init commit
This commit is contained in:
51
app/DTOs/UserDTO.php
Normal file
51
app/DTOs/UserDTO.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?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'
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user