Files
myep/src/Form/Model/RegistrationDto.php
T

59 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Form\Model;
use App\BusProNet\Model\Address;
use App\BusProNet\Model\Communication;
use Symfony\Component\Validator\Constraints as Assert;
class RegistrationDto
{
#[Assert\NotBlank(message: 'Bitte angeben')]
public ?string $firstName = null;
#[Assert\NotBlank(message: 'Bitte angeben')]
public ?string $name = null;
#[Assert\NotBlank(message: 'Bitte angeben')]
#[Assert\Choice(choices: ['M', 'W', 'D'], message: 'Bitte gib einen gültigen Wert an')]
public ?string $gender = null;
#[Assert\NotBlank(message: 'Bitte angeben')]
public ?\DateTimeImmutable $dateOfBirth = null;
#[Assert\NotBlank(message: 'Bitte angeben')]
public ?string $nationality = null;
#[Assert\Valid]
public Address $address;
#[Assert\Valid]
public Communication $communication;
public function __construct()
{
$this->address = new Address();
$this->communication = new Communication();
}
/**
* Converts the registration data to API payload format.
*
* @return array<string, mixed>
*/
public function toPayload(): array
{
return [
'geschlecht' => $this->gender,
'vorname' => $this->firstName,
'name' => $this->name,
'nationalitaet' => $this->nationality,
'geburtsdatum' => $this->dateOfBirth?->format('d.m.Y'),
'anschrift' => $this->address->toPayload(),
'kommunikation' => $this->communication->toPayload(),
];
}
}