Moved Passport objects
This commit is contained in:
parent
02dedd3e03
commit
0b8603ec75
5 changed files with 5 additions and 4 deletions
77
src/TgBotLib/Objects/Passport/PassportData.php
Normal file
77
src/TgBotLib/Objects/Passport/PassportData.php
Normal file
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace TgBotLib\Objects\Passport;
|
||||
|
||||
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 ($element)
|
||||
{
|
||||
if($element instanceof ObjectTypeInterface)
|
||||
{
|
||||
return $element->toArray();
|
||||
}
|
||||
return $element;
|
||||
}, $this->data),
|
||||
'credentials' => $this->credentials->toArray(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs object from an array representation
|
||||
*
|
||||
* @param array $data
|
||||
* @return PassportData
|
||||
*/
|
||||
public static function fromArray(array $data): self
|
||||
{
|
||||
$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
Add a link
Reference in a new issue