Added \TgBotLib\Objects\ChatMember > ChatMemberLeft

This commit is contained in:
Netkas 2023-02-13 17:50:13 -05:00
parent dc415dc49c
commit b74c0c2975

View file

@ -0,0 +1,81 @@
<?php
namespace TgBotLib\Objects\ChatMember;
use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\ChatMember;
use TgBotLib\Objects\User;
class ChatMemberLeft implements ObjectTypeInterface
{
/**
* @var string
*/
private $status;
/**
* @var User
*/
private $user;
/**
* The member's status in the chat, always “left”
*
* @return string
*/
public function getStatus(): string
{
return $this->status;
}
/**
* Information about the user
*
* @return User
*/
public function getUser(): User
{
return $this->user;
}
/**
* Returns an array representation of the object
*
* @return array
*/
public function toArray(): array
{
return [
'status' => $this->status,
'user' => ($this->user instanceof ObjectTypeInterface) ? $this->user->toArray() : $this->user,
];
}
/**
* Constructs the object from an array representation
*
* @param array $data
* @return ObjectTypeInterface
*/
public static function fromArray(array $data): ObjectTypeInterface
{
$object = new self();
$object->status = $data['status'];
$object->user = User::fromArray($data['user']);
return $object;
}
/**
* Constructs the object from ChatMember object
*
* @param ChatMember $chatMember
* @return static
*/
public static function fromChatMember(ChatMember $chatMember): self
{
$object = new self();
$object->status = $chatMember->getStatus();
$object->user = $chatMember->getUser();
return $object;
}
}