54 lines
1.4 KiB
PHP
54 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Dtos;
|
|
|
|
class RecipeImageDto
|
|
{
|
|
public ?int $id = null;
|
|
public ?string $imagePath = null;
|
|
public ?string $title = null;
|
|
public ?string $description = null;
|
|
public ?int $isFeatured = null;
|
|
public ?int $sortOrder = 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->imagePath = $data['imagePath'] ?? null;
|
|
$dto->title = $data['title'] ?? null;
|
|
$dto->description = $data['description'] ?? null;
|
|
$dto->isFeatured = isset($data['isFeatured']) ? (int)$data['isFeatured'] : null;
|
|
$dto->sortOrder = isset($data['sortOrder']) ? (int)$data['sortOrder'] : 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,
|
|
'imagePath' => $this->imagePath,
|
|
'title' => $this->title,
|
|
'description' => $this->description,
|
|
'isFeatured' => $this->isFeatured,
|
|
'sortOrder' => $this->sortOrder,
|
|
'createdAt' => $this->createdAt,
|
|
];
|
|
}
|
|
}
|