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

78 lines
2.1 KiB
PHP
Raw Normal View History

2023-02-14 13:44:03 -05:00
<?php
/** @noinspection PhpMissingFieldTypeInspection */
2023-02-14 17:41:38 -05:00
namespace TgBotLib\Objects\Telegram;
2023-02-14 13:44:03 -05:00
use TgBotLib\Interfaces\ObjectTypeInterface;
class PassportData implements ObjectTypeInterface
{
/**
* @var EncryptedPassportElement[]
*/
private $data;
/**
* @var EncryptedCredentials
*/
private $credentials;
/**
* Array with information about documents and other Telegram Passport elements that was shared with the bot
*
* @return EncryptedPassportElement[]
*/
public function getData(): array
{
return $this->data;
}
/**
* Encrypted credentials required to decrypt the data
*
* @return EncryptedCredentials
*/
public function getCredentials(): EncryptedCredentials
{
return $this->credentials;
}
/**
* Returns an array representation of the object
*
* @return array
*/
public function toArray(): array
{
return [
2023-02-14 17:35:16 -05:00
'data' => array_map(function ($element)
2023-02-14 13:44:03 -05:00
{
2023-02-14 17:35:16 -05:00
if($element instanceof ObjectTypeInterface)
{
return $element->toArray();
}
return $element;
2023-02-14 13:44:03 -05:00
}, $this->data),
'credentials' => $this->credentials->toArray(),
];
}
/**
* Constructs object from an array representation
*
* @param array $data
2023-02-16 15:27:57 -05:00
* @return PassportData
2023-02-14 13:44:03 -05:00
*/
2023-02-16 15:27:57 -05:00
public static function fromArray(array $data): self
2023-02-14 13:44:03 -05:00
{
$object = new self();
$object->data = array_map(function (array $element)
{
return EncryptedPassportElement::fromArray($element);
}, $data['data']);
$object->credentials = EncryptedCredentials::fromArray($data['credentials']);
return $object;
}
}