2023-02-13 20:07:44 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
2024-10-02 00:18:12 -04:00
|
|
|
namespace TgBotLib\Objects;
|
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
|
2023-02-16 15:27:57 -05:00
|
|
|
* @return ChatLocation
|
2023-02-13 20:07:44 -05:00
|
|
|
*/
|
2023-02-16 15:27:57 -05:00
|
|
|
public static function fromArray(array $data): self
|
2023-02-13 20:07:44 -05:00
|
|
|
{
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
}
|