2023-04-23 16:22:15 -04:00
|
|
|
<?php
|
|
|
|
|
2024-10-02 00:18:12 -04:00
|
|
|
namespace TgBotLib\Objects;
|
2023-04-23 16:22:15 -04:00
|
|
|
|
2024-10-03 00:45:23 -04:00
|
|
|
use InvalidArgumentException;
|
|
|
|
use TgBotLib\Enums\Types\InputMessageContentType;
|
2023-04-23 16:22:15 -04:00
|
|
|
use TgBotLib\Interfaces\ObjectTypeInterface;
|
2024-10-02 00:18:12 -04:00
|
|
|
use TgBotLib\Objects\InputMessageContent\InputInvoiceMessageContent;
|
|
|
|
use TgBotLib\Objects\InputMessageContent\InputLocationMessageContent;
|
|
|
|
use TgBotLib\Objects\InputMessageContent\InputTextMessageContent;
|
|
|
|
use TgBotLib\Objects\InputMessageContent\InputVenueMessageContent;
|
2023-04-23 16:22:15 -04:00
|
|
|
|
2024-10-03 00:45:23 -04:00
|
|
|
abstract class InputMessageContent implements ObjectTypeInterface
|
2023-04-23 16:22:15 -04:00
|
|
|
{
|
2024-10-03 00:45:23 -04:00
|
|
|
protected InputMessageContentType $type;
|
|
|
|
|
2023-04-23 16:22:15 -04:00
|
|
|
/**
|
2024-10-03 00:45:23 -04:00
|
|
|
* Returns the type for the Input message content
|
|
|
|
*
|
|
|
|
* @return InputMessageContentType
|
2023-04-23 16:22:15 -04:00
|
|
|
*/
|
2024-10-03 00:45:23 -04:00
|
|
|
public function getType(): InputMessageContentType
|
2023-04-23 16:22:15 -04:00
|
|
|
{
|
2024-10-03 00:45:23 -04:00
|
|
|
return $this->type;
|
2023-04-23 16:22:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
2024-10-03 00:45:23 -04:00
|
|
|
public abstract function toArray(): array;
|
2023-04-23 16:22:15 -04:00
|
|
|
|
2024-10-03 00:45:23 -04:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public static function fromArray(array $data): InputMessageContent
|
|
|
|
{
|
|
|
|
if(isset($data['message_text']))
|
2023-04-23 16:22:15 -04:00
|
|
|
{
|
2024-10-03 00:45:23 -04:00
|
|
|
return InputTextMessageContent::fromArray($data);
|
2023-04-23 16:22:15 -04:00
|
|
|
}
|
|
|
|
|
2024-10-03 00:45:23 -04:00
|
|
|
if(isset($data['latitude']) && isset($data['longitude']) && isset($data['tile']) && isset($data['address']))
|
2023-04-23 16:22:15 -04:00
|
|
|
{
|
|
|
|
return InputVenueMessageContent::fromArray($data);
|
|
|
|
}
|
|
|
|
|
2024-10-03 00:45:23 -04:00
|
|
|
if(isset($data['latitude']) && isset($data['longitude']))
|
2023-04-23 16:22:15 -04:00
|
|
|
{
|
|
|
|
return InputLocationMessageContent::fromArray($data);
|
|
|
|
}
|
|
|
|
|
2024-10-03 00:45:23 -04:00
|
|
|
if(isset($data['title']) && isset($data['description']) && isset($data['payload']))
|
2023-04-23 16:22:15 -04:00
|
|
|
{
|
2024-10-03 00:45:23 -04:00
|
|
|
return InputInvoiceMessageContent::fromArray($data);
|
2023-04-23 16:22:15 -04:00
|
|
|
}
|
|
|
|
|
2024-10-03 00:45:23 -04:00
|
|
|
throw new InvalidArgumentException("Invalid object type, unexpected type");
|
2023-04-23 16:22:15 -04:00
|
|
|
}
|
|
|
|
}
|