Updated CallbackQuery

This commit is contained in:
netkas 2024-10-04 12:14:23 -04:00
parent f6df3bf9da
commit 7d9caf38b3

View file

@ -8,40 +8,13 @@
class CallbackQuery implements ObjectTypeInterface class CallbackQuery implements ObjectTypeInterface
{ {
/** private string $id;
* @var string private User $from;
*/ private ?Message $message;
private $id; private ?string $inline_message_id;
private string $chat_instance;
/** private ?string $data;
* @var User private ?string $game_short_name;
*/
private $from;
/**
* @var Message|null
*/
private $message;
/**
* @var string|null
*/
private $inline_message_id;
/**
* @var string
*/
private $chat_instance;
/**
* @var string|null
*/
private $data;
/**
* @var string|null
*/
private $game_short_name;
/** /**
* Unique identifier for this query * Unique identifier for this query
@ -119,16 +92,14 @@
} }
/** /**
* Returns an array representation of the object * @inheritDoc
*
* @return array
*/ */
public function toArray(): array public function toArray(): array
{ {
return [ return [
'id' => $this->id, 'id' => $this->id,
'from' => ($this->from instanceof ObjectTypeInterface) ? $this->from->toArray() : null, 'from' => $this->from?->toArray(),
'message' => ($this->message instanceof ObjectTypeInterface) ? $this->message->toArray() : null, 'message' => $this->message?->toArray(),
'inline_message_id' => $this->inline_message_id, 'inline_message_id' => $this->inline_message_id,
'chat_instance' => $this->chat_instance, 'chat_instance' => $this->chat_instance,
'data' => $this->data, 'data' => $this->data,
@ -137,15 +108,16 @@
} }
/** /**
* Constructs CallbackQuery object from an array representation * @inheritDoc
*
* @param array $data
* @return CallbackQuery
*/ */
public static function fromArray(array $data): self public static function fromArray(?array $data): ?CallbackQuery
{ {
$object = new self(); if($data === null)
{
return null;
}
$object = new self();
$object->id = $data['id'] ?? null; $object->id = $data['id'] ?? null;
$object->from = isset($data['from']) ? User::fromArray($data['from']) : null; $object->from = isset($data['from']) ? User::fromArray($data['from']) : null;
$object->message = isset($data['message']) ? Message::fromArray($data['message']) : null; $object->message = isset($data['message']) ? Message::fromArray($data['message']) : null;