Updated Passport objects

This commit is contained in:
netkas 2024-10-04 19:54:04 -04:00
parent eef9ab5624
commit 6f75038bf5
4 changed files with 65 additions and 182 deletions

View file

@ -7,20 +7,9 @@
class EncryptedCredentials implements ObjectTypeInterface class EncryptedCredentials implements ObjectTypeInterface
{ {
/** private string $data;
* @var string private string $hash;
*/ private string $secret;
private $data;
/**
* @var string
*/
private $hash;
/**
* @var string
*/
private $secret;
/** /**
* Base64-encoded encrypted JSON-serialized data with unique user's payload, data hashes and secrets required * Base64-encoded encrypted JSON-serialized data with unique user's payload, data hashes and secrets required
@ -55,9 +44,7 @@
} }
/** /**
* Returns an array representation of the object * @inheritDoc
*
* @return array
*/ */
public function toArray(): array public function toArray(): array
{ {
@ -69,15 +56,16 @@
} }
/** /**
* Constructs object from an array representation * @inheritDoc
*
* @param array $data
* @return EncryptedCredentials
*/ */
public static function fromArray(array $data): self public static function fromArray(?array $data): ?EncryptedCredentials
{ {
$object = new self(); if($data === null)
{
return null;
}
$object = new self();
$object->data = $data['data'] ?? null; $object->data = $data['data'] ?? null;
$object->hash = $data['hash'] ?? null; $object->hash = $data['hash'] ?? null;
$object->secret = $data['secret'] ?? null; $object->secret = $data['secret'] ?? null;

View file

@ -7,55 +7,31 @@
class EncryptedPassportElement implements ObjectTypeInterface class EncryptedPassportElement implements ObjectTypeInterface
{ {
/** private string $type;
* @var string private ?string $data;
*/ private ?string $phone_number;
private $type; private ?string $email;
/**
* @var string|null
*/
private $data;
/**
* @var string|null
*/
private $phone_number;
/**
* @var string|null
*/
private $email;
/** /**
* @var PassportFile[]|null * @var PassportFile[]|null
*/ */
private $files; private ?array $files;
/** /**
* @var PassportFile[]|null * @var PassportFile[]|null
*/ */
private $front_side; private ?array $front_side;
/** /**
* @var PassportFile[]|null * @var PassportFile[]|null
*/ */
private $reverse_side; private ?array $reverse_side;
/** /**
* @var PassportFile[]|null * @var PassportFile[]|null
*/ */
private $selfie; private ?array $selfie;
/** /**
* @var PassportFile[]|null * @var PassportFile[]|null
*/ */
private $translation; private ?array $translation;
private string $hash;
/**
* @var string
*/
private $hash;
/** /**
* Element type. One of “personal_details”, “passport”, “driver_license”, “identity_card”, “internal_passport”, * Element type. One of “personal_details”, “passport”, “driver_license”, “identity_card”, “internal_passport”,
@ -180,9 +156,7 @@
} }
/** /**
* Returns an array representation of the object. * @inheritDoc
*
* @return array
*/ */
public function toArray(): array public function toArray(): array
{ {
@ -191,84 +165,35 @@
'data' => $this->data, 'data' => $this->data,
'phone_number' => $this->phone_number, 'phone_number' => $this->phone_number,
'email' => $this->email, 'email' => $this->email,
'files' => is_array($this->files) ? array_map(function ($file) 'files' => is_null($this->files) ? null : array_map(fn(PassportFile $item) => $item->toArray(), $this->files),
{ 'front_side' => is_null($this->front_side) ? null : array_map(fn(PassportFile $item) => $item->toArray(), $this->front_side),
if($file instanceof PassportFile) 'reverse_side' => is_null($this->reverse_side) ? null : array_map(fn(PassportFile $item) => $item->toArray(), $this->reverse_side),
{ 'selfie' => is_null($this->selfie) ? null : array_map(fn(PassportFile $item) => $item->toArray(), $this->selfie),
return $file->toArray(); 'translation' => is_null($this->translation) ? null : array_map(fn(PassportFile $item) => $item->toArray(), $this->translation),
}
return $file;
}, $this->files) : null,
'front_side' => is_array($this->front_side) ? array_map(function ($file)
{
if($file instanceof PassportFile)
{
return $file->toArray();
}
return $file;
}, $this->front_side) : null,
'reverse_side' => is_array($this->reverse_side) ? array_map(function ($file)
{
if($file instanceof PassportFile)
{
return $file->toArray();
}
return $file;
}, $this->reverse_side) : null,
'selfie' => is_array($this->selfie) ? array_map(function ($file)
{
if($file instanceof PassportFile)
{
return $file->toArray();
}
return $file;
}, $this->selfie) : null,
'translation' => is_array($this->translation) ? array_map(function ($file)
{
if($file instanceof PassportFile)
{
return $file->toArray();
}
return $file;
}, $this->translation) : null,
'hash' => $this->hash 'hash' => $this->hash
]; ];
} }
/** /**
* Constructs object from an array representation. * @inheritDoc
*
* @param array $data
* @return EncryptedPassportElement
*/ */
public static function fromArray(array $data): self public static function fromArray(?array $data): ?EncryptedPassportElement
{ {
$object = new static(); if($data === null)
{
return null;
}
$object = new static();
$object->type = $data['type']; $object->type = $data['type'];
$object->data = $data['data'] ?? null; $object->data = $data['data'] ?? null;
$object->phone_number = $data['phone_number'] ?? null; $object->phone_number = $data['phone_number'] ?? null;
$object->email = $data['email'] ?? null; $object->email = $data['email'] ?? null;
$object->files = isset($data['files']) ? array_map(function (array $file) $object->files = isset($data['files']) ? array_map(fn(array $items) => PassportFile::fromArray($items), $data['files'] ?? []) : null;
{ $object->front_side = isset($data['front_side']) ? array_map(fn(array $items) => PassportFile::fromArray($items), $data['front_side'] ?? []) : null;
return PassportFile::fromArray($file); $object->reverse_side = isset($data['reverse_side']) ? array_map(fn(array $items) => PassportFile::fromArray($items), $data['reverse_side'] ?? []) : null;
}, $data['files'] ?? []) : null; $object->selfie = isset($data['selfie']) ? array_map(fn(array $items) => PassportFile::fromArray($items), $data['selfie'] ?? []) : null;
$object->front_side = isset($data['front_side']) ? array_map(function (array $file) $object->translation = isset($data['translation']) ? array_map(fn(array $items) => PassportFile::fromArray($items), $data['translation'] ?? []) : null;
{
return PassportFile::fromArray($file);
}, $data['front_side'] ?? []) : null;
$object->reverse_side = isset($data['reverse_side']) ? array_map(function (array $file)
{
return PassportFile::fromArray($file);
}, $data['reverse_side'] ?? []) : null;
$object->selfie = isset($data['selfie']) ? array_map(function (array $file)
{
return PassportFile::fromArray($file);
}, $data['selfie'] ?? []) : null;
$object->translation = isset($data['translation']) ? array_map(function (array $file)
{
return PassportFile::fromArray($file);
}, $data['translation'] ?? []) : null;
$object->hash = $data['hash']; $object->hash = $data['hash'];
return $object; return $object;

View file

@ -10,12 +10,8 @@
/** /**
* @var EncryptedPassportElement[] * @var EncryptedPassportElement[]
*/ */
private $data; private array $data;
private EncryptedCredentials $credentials;
/**
* @var EncryptedCredentials
*/
private $credentials;
/** /**
* Array with information about documents and other Telegram Passport elements that was shared with the bot * Array with information about documents and other Telegram Passport elements that was shared with the bot
@ -38,39 +34,29 @@
} }
/** /**
* Returns an array representation of the object * @inheritDoc
*
* @return array
*/ */
public function toArray(): array public function toArray(): array
{ {
return [ return [
'data' => array_map(function ($element) 'data' => is_null($this->data) ? null : array_map(fn(EncryptedPassportElement $item) => $item->toArray(), $this->data),
{ 'credentials' => $this->credentials?->toArray(),
if($element instanceof ObjectTypeInterface)
{
return $element->toArray();
}
return $element;
}, $this->data),
'credentials' => $this->credentials->toArray(),
]; ];
} }
/** /**
* Constructs object from an array representation * @inheritDoc
*
* @param array $data
* @return PassportData
*/ */
public static function fromArray(array $data): self public static function fromArray(?array $data): ?PassportData
{ {
$object = new self(); if($data === null)
$object->data = array_map(function (array $element)
{ {
return EncryptedPassportElement::fromArray($element); return null;
}, $data['data']); }
$object->credentials = EncryptedCredentials::fromArray($data['credentials']);
$object = new self();
$object->data = isset($data['data']) ? array_map(fn(array $items) => EncryptedPassportElement::fromArray($items), $data['data'] ?? []) : null;
$object->credentials = isset($data['credentials']) ? EncryptedCredentials::fromArray($data['credentials']) : null;
return $object; return $object;
} }

View file

@ -7,25 +7,10 @@
class PassportFile implements ObjectTypeInterface class PassportFile implements ObjectTypeInterface
{ {
/** private string $file_id;
* @var string private string $file_unique_id;
*/ private int $file_size;
private $file_id; private int $file_date;
/**
* @var string
*/
private $file_unique_id;
/**
* @var int
*/
private $file_size;
/**
* @var int
*/
private $file_date;
/** /**
* Identifier for this file, which can be used to download or reuse the file * Identifier for this file, which can be used to download or reuse the file
@ -69,9 +54,7 @@
} }
/** /**
* Returns an array representation of the object * @inheritDoc
*
* @return array
*/ */
public function toArray(): array public function toArray(): array
{ {
@ -84,15 +67,16 @@
} }
/** /**
* Constructs object from an array representation * @inheritDoc
*
* @param array $data
* @return PassportFile
*/ */
public static function fromArray(array $data): self public static function fromArray(?array $data): ?PassportFile
{ {
$object = new self(); if($data === null)
{
return null;
}
$object = new self();
$object->file_id = $data['file_id'] ?? null; $object->file_id = $data['file_id'] ?? null;
$object->file_unique_id = $data['file_unique_id'] ?? null; $object->file_unique_id = $data['file_unique_id'] ?? null;
$object->file_size = $data['file_size'] ?? null; $object->file_size = $data['file_size'] ?? null;