Files
Laravel/app/DTOs/UserDTO.php
David Melendez e25d53d054 init commit
2026-01-14 22:38:44 +01:00

52 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace App\DTOs;
/**
* User Data Transfer Object
*
* @author David Valera Melendez <david@valera-melendez.de>
* @created 2025-08-08
* @location Made in Germany 🇩🇪
*/
class UserDTO
{
public function __construct(
public readonly string $first_name,
public readonly string $last_name,
public readonly string $email,
public readonly ?string $phone = null,
public readonly ?string $profession = null,
public readonly ?string $location = null,
public readonly ?string $status = 'active'
) {}
public function toArray(): array
{
return [
'first_name' => $this->first_name,
'last_name' => $this->last_name,
'email' => $this->email,
'phone' => $this->phone,
'profession' => $this->profession,
'location' => $this->location,
'status' => $this->status,
];
}
public static function fromArray(array $data): self
{
return new self(
first_name: $data['first_name'],
last_name: $data['last_name'],
email: $data['email'],
phone: $data['phone'] ?? null,
profession: $data['profession'] ?? null,
location: $data['location'] ?? null,
status: $data['status'] ?? 'active'
);
}
}