2023-04-24 19:22:06 -04:00
< ? php
namespace TgBotLib\Objects\Telegram ;
use InvalidArgumentException ;
2023-08-09 15:32:45 -04:00
use TgBotLib\Enums\InlineQueryResultType ;
2023-04-24 19:22:06 -04:00
use TgBotLib\Exceptions\NotImplementedException ;
use TgBotLib\Interfaces\ObjectTypeInterface ;
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultArticle ;
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultAudio ;
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultContact ;
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultDocument ;
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultGame ;
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultGif ;
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultLocation ;
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultMpeg4Gif ;
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultPhoto ;
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultVenue ;
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultVideo ;
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultVoice ;
class InlineQueryResult implements ObjectTypeInterface
{
/**
* Returns an array representation of the object
*
* @ return array
* @ throws NotImplementedException
* @ deprecated Don ' t use , use fromArray () instead directly to construct the appropriate child class
*/
public function toArray () : array
{
throw new NotImplementedException ( sprintf ( 'This object is abstract, you can\'t use it directly, try constructing one of the child classes with fromArray()' ));
}
/**
* Returns an object constructed from the given array
*
* @ param array $data
* @ return ObjectTypeInterface
*/
public static function fromArray ( array $data ) : ObjectTypeInterface
{
if ( ! isset ( $data [ 'type' ]))
{
throw new InvalidArgumentException ( 'The type of the InlineQueryResult is not set, this is required!' );
}
switch ( strtolower ( $data [ 'type' ]))
{
2023-08-09 15:32:45 -04:00
case InlineQueryResultType :: ARTICLE :
2023-04-24 19:22:06 -04:00
return InlineQueryResultArticle :: fromArray ( $data );
2023-08-09 15:32:45 -04:00
case InlineQueryResultType :: PHOTO :
2023-04-24 19:22:06 -04:00
return InlineQueryResultPhoto :: fromArray ( $data );
2023-08-09 15:32:45 -04:00
case InlineQueryResultType :: GIF :
2023-04-24 19:22:06 -04:00
return InlineQueryResultGif :: fromArray ( $data );
2023-08-09 15:32:45 -04:00
case InlineQueryResultType :: MPEG_4_GIF :
2023-04-24 19:22:06 -04:00
return InlineQueryResultMpeg4Gif :: fromArray ( $data );
2023-08-09 15:32:45 -04:00
case InlineQueryResultType :: VIDEO :
2023-04-24 19:22:06 -04:00
return InlineQueryResultVideo :: fromArray ( $data );
2023-08-09 15:32:45 -04:00
case InlineQueryResultType :: AUDIO :
2023-04-24 19:22:06 -04:00
return InlineQueryResultAudio :: fromArray ( $data );
2023-08-09 15:32:45 -04:00
case InlineQueryResultType :: VOICE :
2023-04-24 19:22:06 -04:00
return InlineQueryResultVoice :: fromArray ( $data );
2023-08-09 15:32:45 -04:00
case InlineQueryResultType :: DOCUMENT :
2023-04-24 19:22:06 -04:00
return InlineQueryResultDocument :: fromArray ( $data );
2023-08-09 15:32:45 -04:00
case InlineQueryResultType :: LOCATION :
2023-04-24 19:22:06 -04:00
return InlineQueryResultLocation :: fromArray ( $data );
2023-08-09 15:32:45 -04:00
case InlineQueryResultType :: VENUE :
2023-04-24 19:22:06 -04:00
return InlineQueryResultVenue :: fromArray ( $data );
2023-08-09 15:32:45 -04:00
case InlineQueryResultType :: CONTACT :
2023-04-24 19:22:06 -04:00
return InlineQueryResultContact :: fromArray ( $data );
2023-08-09 15:32:45 -04:00
case InlineQueryResultType :: GAME :
2023-04-24 19:22:06 -04:00
return InlineQueryResultGame :: fromArray ( $data );
default :
2023-08-09 15:32:45 -04:00
throw new InvalidArgumentException ( sprintf ( 'The type of the InlineQueryResult is invalid, got "%s", expected one of "%s"' , $data [ 'type' ], implode ( '", "' , InlineQueryResultType :: ALL )));
2023-04-24 19:22:06 -04:00
}
}
}