tgbotlib/src/TgBotLib/Objects/InputMessageContent.php

59 lines
1.8 KiB
PHP
Raw Normal View History

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