Updated classes fromArray signatures (in-progress)
This commit is contained in:
parent
59f6875edf
commit
dfb812237b
43 changed files with 288 additions and 75 deletions
|
@ -108,13 +108,17 @@
|
|||
/**
|
||||
* Constructs object from an array representation
|
||||
*
|
||||
* @param array $data
|
||||
* @return ChosenInlineResult
|
||||
* @param array|null $data
|
||||
* @return ChosenInlineResult|null
|
||||
*/
|
||||
public static function fromArray(array $data): self
|
||||
public static function fromArray(?array $data): ?ChosenInlineResult
|
||||
{
|
||||
$object = new self();
|
||||
if($data === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$object = new self();
|
||||
$object->result_id = $data['result_id'] ?? null;
|
||||
$object->from = $data['from'] ?? null;
|
||||
$object->location = $data['location'] ?? null;
|
||||
|
|
|
@ -334,13 +334,17 @@
|
|||
/**
|
||||
* Constructs a new InlineKeyboardButton object from an array
|
||||
*
|
||||
* @param array $data
|
||||
* @return InlineKeyboardButton
|
||||
* @param array|null $data
|
||||
* @return InlineKeyboardButton|null
|
||||
*/
|
||||
public static function fromArray(array $data): self
|
||||
public static function fromArray(?array $data): ?InlineKeyboardButton
|
||||
{
|
||||
$object = new self();
|
||||
if($data === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$object = new self();
|
||||
$object->text = $data['text'] ?? null;
|
||||
$object->url = $data['url'] ?? null;
|
||||
$object->callback_data = $data['callback_data'] ?? null;
|
||||
|
|
|
@ -72,13 +72,17 @@
|
|||
/**
|
||||
* Constructs the object from an array representation
|
||||
*
|
||||
* @param array $data
|
||||
* @return InlineKeyboardMarkup
|
||||
* @param array|null $data
|
||||
* @return InlineKeyboardMarkup|null
|
||||
*/
|
||||
public static function fromArray(array $data): self
|
||||
public static function fromArray(?array $data): ?InlineKeyboardMarkup
|
||||
{
|
||||
$object = new self();
|
||||
if($data === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$object = new self();
|
||||
$object->inline_keyboard = [];
|
||||
|
||||
foreach($data as $item)
|
||||
|
|
|
@ -123,13 +123,17 @@
|
|||
/**
|
||||
* Constructs object from an array representation
|
||||
*
|
||||
* @param array $data
|
||||
* @return InlineQuery
|
||||
* @param array|null $data
|
||||
* @return InlineQuery|null
|
||||
*/
|
||||
public static function fromArray(array $data): self
|
||||
public static function fromArray(?array $data): ?InlineQuery
|
||||
{
|
||||
$object = new self();
|
||||
if($data === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$object = new self();
|
||||
$object->id = $data['id'];
|
||||
$object->from = isset($data['from']) && is_array($data['from']) ? User::fromArray($data['from']) : $data['from'];
|
||||
$object->query = $data['query'];
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
use InvalidArgumentException;
|
||||
use TgBotLib\Classes\Validate;
|
||||
use TgBotLib\Enums\Types\InlineQueryResultType;
|
||||
use TgBotLib\Exceptions\NotImplementedException;
|
||||
use TgBotLib\Interfaces\ObjectTypeInterface;
|
||||
use TgBotLib\Objects\Inline\InlineQueryResult\InlineQueryResultArticle;
|
||||
use TgBotLib\Objects\Inline\InlineQueryResult\InlineQueryResultAudio;
|
||||
|
@ -71,8 +70,33 @@
|
|||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function fromArray(array $data): ObjectTypeInterface
|
||||
public static function fromArray(?array $data): ?InlineQueryResult
|
||||
{
|
||||
// TODO: Implement this
|
||||
if($data === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if(!isset($data['type']))
|
||||
{
|
||||
throw new InvalidArgumentException('InlineQueryResult expected type');
|
||||
}
|
||||
|
||||
return match(InlineQueryResultType::tryFrom($data['type']))
|
||||
{
|
||||
InlineQueryResultType::ARTICLE => InlineQueryResultArticle::fromArray($data),
|
||||
InlineQueryResultType::AUDIO => InlineQueryResultAudio::fromArray($data),
|
||||
InlineQueryResultType::CONTACT => InlineQueryResultContact::fromArray($data),
|
||||
InlineQueryResultType::DOCUMENT => InlineQueryResultDocument::fromArray($data),
|
||||
InlineQueryResultType::GAME => InlineQueryResultGame::fromArray($data),
|
||||
InlineQueryResultType::GIF => InlineQueryResultGif::fromArray($data),
|
||||
InlineQueryResultType::LOCATION => InlineQueryResultLocation::fromArray($data),
|
||||
InlineQueryResultType::MPEG_4_GIF => InlineQueryResultMpeg4Gif::fromArray($data),
|
||||
InlineQueryResultType::PHOTO => InlineQueryResultPhoto::fromArray($data),
|
||||
InlineQueryResultType::VENUE => InlineQueryResultVenue::fromArray($data),
|
||||
InlineQueryResultType::VIDEO => InlineQueryResultVideo::fromArray($data),
|
||||
InlineQueryResultType::VOICE => InlineQueryResultVoice::fromArray($data),
|
||||
default => throw new InvalidArgumentException('Unexpected type for InlineQueryResult')
|
||||
};
|
||||
}
|
||||
}
|
|
@ -262,8 +262,13 @@
|
|||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function fromArray(array $data): InlineQueryResultArticle
|
||||
public static function fromArray(?array $data): ?InlineQueryResultArticle
|
||||
{
|
||||
if($data === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$object = new self();
|
||||
$object->type = InlineQueryResultType::ARTICLE;
|
||||
$object->id = $data['id'] ?? null;
|
||||
|
|
|
@ -312,8 +312,13 @@
|
|||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function fromArray(array $data): InlineQueryResultAudio
|
||||
public static function fromArray(?array $data): ?InlineQueryResultAudio
|
||||
{
|
||||
if($data === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$object = new self();
|
||||
$object->type = InlineQueryResultType::AUDIO;
|
||||
$object->id = $data['id'] ?? null;
|
||||
|
|
|
@ -260,8 +260,13 @@
|
|||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function fromArray(array $data): InlineQueryResultContact
|
||||
public static function fromArray(?array $data): ?InlineQueryResultContact
|
||||
{
|
||||
if($data === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$object = new self();
|
||||
$object->type = InlineQueryResultType::CONTACT;
|
||||
$object->id = $data['id'] ?? null;
|
||||
|
|
|
@ -381,8 +381,13 @@
|
|||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function fromArray(array $data): InlineQueryResultDocument
|
||||
public static function fromArray(?array $data): ?InlineQueryResultDocument
|
||||
{
|
||||
if($data === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$object = new self();
|
||||
$object->type = InlineQueryResultType::DOCUMENT;
|
||||
$object->id = $data['id'] ?? null;
|
||||
|
|
|
@ -89,8 +89,13 @@
|
|||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function fromArray(array $data): InlineQueryResultGame
|
||||
public static function fromArray(?array $data): ?InlineQueryResultGame
|
||||
{
|
||||
if($data === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$object = new self();
|
||||
$object->type = InlineQueryResultType::GAME;
|
||||
$object->id = $data['id'] ?? null;
|
||||
|
|
|
@ -390,8 +390,13 @@
|
|||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function fromArray(array $data): InlineQueryResultGif
|
||||
public static function fromArray(?array $data): ?InlineQueryResultGif
|
||||
{
|
||||
if($data === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$object = new self();
|
||||
$object->type = InlineQueryResultType::GIF;
|
||||
$object->id = $data['id'] ?? null;
|
||||
|
|
|
@ -339,8 +339,13 @@
|
|||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function fromArray(array $data): InlineQueryResultLocation
|
||||
public static function fromArray(?array $data): ?InlineQueryResultLocation
|
||||
{
|
||||
if($data === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$object = new self();
|
||||
$object->type = InlineQueryResultType::LOCATION;
|
||||
$object->id = $data['id'] ?? null;
|
||||
|
|
|
@ -322,8 +322,13 @@
|
|||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function fromArray(array $data): InlineQueryResultMpeg4Gif
|
||||
public static function fromArray(?array $data): ?InlineQueryResultMpeg4Gif
|
||||
{
|
||||
if($data === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$object = new self();
|
||||
$object->type = InlineQueryResultType::MPEG_4_GIF;
|
||||
$object->id = $data['id'] ?? null;
|
||||
|
|
|
@ -303,8 +303,13 @@
|
|||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function fromArray(array $data): InlineQueryResultPhoto
|
||||
public static function fromArray(?array $data): ?InlineQueryResultPhoto
|
||||
{
|
||||
if($data === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$object = new self();
|
||||
$object->type = InlineQueryResultType::PHOTO;
|
||||
$object->id = $data['id'] ?? null;
|
||||
|
|
|
@ -342,8 +342,13 @@
|
|||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function fromArray(array $data): InlineQueryResultVenue
|
||||
public static function fromArray(?array $data): ?InlineQueryResultVenue
|
||||
{
|
||||
if($data === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$object = new self();
|
||||
$object->type = InlineQueryResultType::VENUE;
|
||||
$object->id = $data['id'] ?? null;
|
||||
|
|
|
@ -356,8 +356,13 @@
|
|||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function fromArray(array $data): ObjectTypeInterface
|
||||
public static function fromArray(?array $data): ?InlineQueryResultVideo
|
||||
{
|
||||
if($data === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$object = new self();
|
||||
$object->type = InlineQueryResultType::VIDEO;
|
||||
$object->id = $data['id'] ?? null;
|
||||
|
|
|
@ -232,8 +232,13 @@
|
|||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function fromArray(array $data): InlineQueryResultVoice
|
||||
public static function fromArray(?array $data): ?InlineQueryResultVoice
|
||||
{
|
||||
if($data === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$object = new self();
|
||||
$object->type = InlineQueryResultType::VOICE;
|
||||
$object->id = $data['id'] ?? null;
|
||||
|
|
|
@ -37,13 +37,17 @@
|
|||
/**
|
||||
* Constructs object from an array representation
|
||||
*
|
||||
* @param array $data
|
||||
* @return SentWebAppMessage
|
||||
* @param array|null $data
|
||||
* @return SentWebAppMessage|null
|
||||
*/
|
||||
public static function fromArray(array $data): SentWebAppMessage
|
||||
public static function fromArray(?array $data): ?SentWebAppMessage
|
||||
{
|
||||
$object = new self();
|
||||
if($data === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$object = new self();
|
||||
$object->inline_message_id = $data['inline_message_id'] ?? null;
|
||||
|
||||
return $object;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue