Added \TgBotLib\Objects > PassportData
This commit is contained in:
parent
231779ed1b
commit
7b536a6f67
1 changed files with 74 additions and 0 deletions
74
src/TgBotLib/Objects/PassportData.php
Normal file
74
src/TgBotLib/Objects/PassportData.php
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/** @noinspection PhpMissingFieldTypeInspection */
|
||||||
|
|
||||||
|
namespace TgBotLib\Objects;
|
||||||
|
|
||||||
|
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 [
|
||||||
|
'data' => array_map(function (EncryptedPassportElement $element)
|
||||||
|
{
|
||||||
|
return $element->toArray();
|
||||||
|
}, $this->data),
|
||||||
|
'credentials' => $this->credentials->toArray(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs object from an array representation
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
* @return ObjectTypeInterface
|
||||||
|
*/
|
||||||
|
public static function fromArray(array $data): ObjectTypeInterface
|
||||||
|
{
|
||||||
|
$object = new self();
|
||||||
|
$object->data = array_map(function (array $element)
|
||||||
|
{
|
||||||
|
return EncryptedPassportElement::fromArray($element);
|
||||||
|
}, $data['data']);
|
||||||
|
$object->credentials = EncryptedCredentials::fromArray($data['credentials']);
|
||||||
|
|
||||||
|
return $object;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue