tgbotlib/src/TgBotLib/Objects/Telegram/ChatLocation.php

69 lines
1.7 KiB
PHP
Raw Normal View History

2023-02-13 20:07:44 -05:00
<?php
/** @noinspection PhpMissingFieldTypeInspection */
2023-02-14 17:41:38 -05:00
namespace TgBotLib\Objects\Telegram;
2023-02-13 20:07:44 -05:00
use TgBotLib\Interfaces\ObjectTypeInterface;
class ChatLocation implements ObjectTypeInterface
{
/**
* @var Location
*/
private $location;
/**
* @var string
*/
private $address;
/**
* The location to which the supergroup is connected. Can't be a live location.
*
* @return Location
*/
public function getLocation(): Location
{
return $this->location;
}
/**
* Location address; 1-64 characters, as defined by the chat owner
*
* @return string
*/
public function getAddress(): string
{
return $this->address;
}
/**
* Returns an array representation of the object
*
* @return array
*/
public function toArray(): array
{
return [
2023-02-14 17:35:16 -05:00
'location' => ($this->location instanceof ObjectTypeInterface) ? $this->location->toArray() : $this->location,
2023-02-13 20:07:44 -05:00
'address' => $this->address,
];
}
/**
* Constructs object from an array representation
*
* @param array $data
* @return ObjectTypeInterface
*/
public static function fromArray(array $data): ObjectTypeInterface
{
$object = new self();
$object->location = isset($data['location']) ? Location::fromArray($data['location']) : null;
2023-02-14 17:35:16 -05:00
$object->address = $data['address'] ?? null;
2023-02-13 20:07:44 -05:00
return $object;
}
}