Updated MessageOrigin objects
This commit is contained in:
parent
5426dd9e1c
commit
2405873510
5 changed files with 40 additions and 25 deletions
|
@ -35,21 +35,20 @@ abstract class MessageOrigin implements ObjectTypeInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Converts the object to an array representation.
|
||||
*
|
||||
* @return array The array representation of the object.
|
||||
* @inheritDoc
|
||||
*/
|
||||
public abstract function toArray(): array;
|
||||
|
||||
/**
|
||||
* Converts an associative array to a MessageOrigin object.
|
||||
*
|
||||
* @param array $data The data representing the message origin.
|
||||
* @return MessageOrigin The constructed MessageOrigin object.
|
||||
* @throws InvalidArgumentException If the 'type' key is missing or an unknown type is provided.
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function fromArray(array $data): MessageOrigin
|
||||
public static function fromArray(?array $data): ?MessageOrigin
|
||||
{
|
||||
if($data === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if(!isset($data['type']))
|
||||
{
|
||||
throw new InvalidArgumentException('Message origin type is required');
|
||||
|
|
|
@ -49,8 +49,8 @@ class MessageOriginChannel extends MessageOrigin implements ObjectTypeInterface
|
|||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'type' => $this->getType()->value,
|
||||
'date' => $this->getDate(),
|
||||
'type' => $this->type->value,
|
||||
'date' => $this->date,
|
||||
'chat' => $this->chat->toArray(),
|
||||
'message_id' => $this->message_id,
|
||||
'author_signature' => $this->author_signature,
|
||||
|
@ -60,10 +60,14 @@ class MessageOriginChannel extends MessageOrigin implements ObjectTypeInterface
|
|||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function fromArray(array $data): MessageOrigin
|
||||
public static function fromArray(?array $data): ?MessageOrigin
|
||||
{
|
||||
$object = new self();
|
||||
if($data === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$object = new self();
|
||||
$object->type = MessageOriginType::CHANNEL;
|
||||
$object->date = $data['date'];
|
||||
$object->chat = Chat::fromArray($data['chat']);
|
||||
|
|
|
@ -38,8 +38,8 @@ class MessageOriginChat extends MessageOrigin implements ObjectTypeInterface
|
|||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'type' => $this->getType()->value,
|
||||
'date' => $this->getDate(),
|
||||
'type' => $this->type->value,
|
||||
'date' => $this->date,
|
||||
'sender_chat' => $this->sender_chat->toArray(),
|
||||
'author_signature' => $this->author_signature,
|
||||
];
|
||||
|
@ -48,10 +48,14 @@ class MessageOriginChat extends MessageOrigin implements ObjectTypeInterface
|
|||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function fromArray(array $data): MessageOrigin
|
||||
public static function fromArray(?array $data): ?MessageOrigin
|
||||
{
|
||||
$object = new self();
|
||||
if($data === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$object = new self();
|
||||
$object->type = MessageOriginType::CHAT;
|
||||
$object->date = $data['date'];
|
||||
$object->sender_chat = Chat::fromArray($data['sender_chat']);
|
||||
|
|
|
@ -26,8 +26,8 @@ class MessageOriginHiddenUser extends MessageOrigin implements ObjectTypeInterfa
|
|||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'type' => $this->getType()->value,
|
||||
'date' => $this->getDate(),
|
||||
'type' => $this->type->value,
|
||||
'date' => $this->date,
|
||||
'sender_user_name' => $this->sender_user_name
|
||||
];
|
||||
}
|
||||
|
@ -35,10 +35,14 @@ class MessageOriginHiddenUser extends MessageOrigin implements ObjectTypeInterfa
|
|||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function fromArray(array $data): MessageOrigin
|
||||
public static function fromArray(?array $data): ?MessageOrigin
|
||||
{
|
||||
$object = new self();
|
||||
if($data === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$object = new self();
|
||||
$object->type = MessageOriginType::HIDDEN_USER;
|
||||
$object->date = $data['date'];
|
||||
$object->sender_user_name = $data['sender_user_name'];
|
||||
|
|
|
@ -27,8 +27,8 @@ class MessageOriginUser extends MessageOrigin implements ObjectTypeInterface
|
|||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'type' => $this->getType()->value,
|
||||
'date' => $this->getDate(),
|
||||
'type' => $this->type->value,
|
||||
'date' => $this->date,
|
||||
'sender_user' => $this->sender_user->toArray()
|
||||
];
|
||||
}
|
||||
|
@ -36,10 +36,14 @@ class MessageOriginUser extends MessageOrigin implements ObjectTypeInterface
|
|||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function fromArray(array $data): MessageOrigin
|
||||
public static function fromArray(?array $data): ?MessageOrigin
|
||||
{
|
||||
$object = new self();
|
||||
if($data === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$object = new self();
|
||||
$object->type = MessageOriginType::USER;
|
||||
$object->date = $data['date'];
|
||||
$object->sender_user = User::fromArray($data['sender_user']);
|
||||
|
|
Loading…
Add table
Reference in a new issue