Files
dailydish/app/Dtos/RecipeStepDto.php
T
2026-08-09 20:15:40 +03:00

54 lines
1.4 KiB
PHP

<?php
namespace App\Dtos;
class RecipeStepDto
{
public ?int $id = null;
public ?int $stepNumber = null;
public ?string $title = null;
public ?string $instruction = null;
public ?string $image = null;
public ?int $timeEstimate = null;
public ?int $sortOrder = 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->stepNumber = isset($data['stepNumber']) ? (int)$data['stepNumber'] : null;
$dto->title = $data['title'] ?? null;
$dto->instruction = $data['instruction'] ?? null;
$dto->image = $data['image'] ?? null;
$dto->timeEstimate = isset($data['timeEstimate']) ? (int)$data['timeEstimate'] : null;
$dto->sortOrder = isset($data['sortOrder']) ? (int)$data['sortOrder'] : null;
return $dto;
}
/**
* Convert DTO to array
*
* @return array
*/
public function toArray(): array
{
return [
'id' => $this->id,
'stepNumber' => $this->stepNumber,
'title' => $this->title,
'instruction' => $this->instruction,
'image' => $this->image,
'timeEstimate' => $this->timeEstimate,
'sortOrder' => $this->sortOrder,
];
}
}