45 lines
907 B
PHP
45 lines
907 B
PHP
<?php
|
|||
|
|
|
||
|
|
namespace App\Dtos;
|
||
|
|
|
||
|
|
class TagDto
|
||
|
|
{
|
||
|
|
public ?int $id = null;
|
||
|
|
public ?string $name = null;
|
||
|
|
public ?string $slug = null;
|
||
|
|
public ?int $createdAt = null;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Create DTO from array
|
||
|
|
*
|
||
|
|
* @param array $data
|
||
|
|
* @return static
|
||
|
|
*/
|
||
|
|
public static function fromArray(array $data): static
|
||
|
|
{
|
||
|
|
$dto = new static();
|
||
|
|
|
||
|
|
$dto->id = $data['id'] ?? null;
|
||
|
|
$dto->name = $data['name'] ?? null;
|
||
|
|
$dto->slug = $data['slug'] ?? null;
|
||
|
|
$dto->createdAt = isset($data['createdAt']) ? (int)$data['createdAt'] : null;
|
||
|
|
|
||
|
|
return $dto;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Convert DTO to array
|
||
|
|
*
|
||
|
|
* @return array
|
||
|
|
*/
|
||
|
|
public function toArray(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'id' => $this->id,
|
||
|
|
'name' => $this->name,
|
||
|
|
'slug' => $this->slug,
|
||
|
|
'createdAt' => $this->createdAt,
|
||
|
|
];
|
||
|
|
}
|
||
|
|
}
|