60 lines
1.7 KiB
PHP
60 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Dtos;
|
|
|
|
class RecipeIngredientDto
|
|
{
|
|
public ?int $id = null;
|
|
public ?int $ingredientId = null;
|
|
public ?string $ingredientName = null;
|
|
public ?string $ingredientSlug = null;
|
|
public ?string $ingredientCategory = null;
|
|
public ?string $quantity = null;
|
|
public ?string $unit = null;
|
|
public ?string $notes = 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->ingredientId = isset($data['ingredientId']) ? (int)$data['ingredientId'] : null;
|
|
$dto->ingredientName = $data['ingredientName'] ?? null;
|
|
$dto->ingredientSlug = $data['ingredientSlug'] ?? null;
|
|
$dto->ingredientCategory = $data['ingredientCategory'] ?? null;
|
|
$dto->quantity = $data['quantity'] ?? null;
|
|
$dto->unit = $data['unit'] ?? null;
|
|
$dto->notes = $data['notes'] ?? 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,
|
|
'ingredientId' => $this->ingredientId,
|
|
'ingredientName' => $this->ingredientName,
|
|
'ingredientSlug' => $this->ingredientSlug,
|
|
'ingredientCategory' => $this->ingredientCategory,
|
|
'quantity' => $this->quantity,
|
|
'unit' => $this->unit,
|
|
'notes' => $this->notes,
|
|
'sortOrder' => $this->sortOrder,
|
|
];
|
|
}
|
|
}
|