| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- namespace App\Data\Didit\Session\Parts\Request;
- use App\Data\Didit\DiditData;
- final readonly class ExpectedDetailsData extends DiditData
- {
- public function __construct(
- public ?string $firstName = null,
- public ?string $lastName = null,
- public ?string $dateOfBirth = null,
- public ?string $identificationNumber = null,
- public string $idCountry = 'BRA',
- ) {}
- public static function fromName(
- ?string $fullName,
- ?string $dateOfBirth = null,
- ?string $document = null,
- ): self {
- $parts = preg_split('/\s+/', trim((string) $fullName), 2) ?: [];
- return new self(
- firstName: $parts[0] ?? null,
- lastName: $parts[1] ?? null,
- dateOfBirth: $dateOfBirth,
- identificationNumber: $document ? self::digits($document) : null,
- );
- }
- public function toArray(): array
- {
- return $this->filterFilledRecursive([
- 'first_name' => $this->firstName,
- 'last_name' => $this->lastName,
- 'date_of_birth' => $this->dateOfBirth,
- 'identification_number' => $this->identificationNumber,
- 'id_country' => $this->idCountry,
- ]);
- }
- }
|