94 lines
2.5 KiB
PHP
94 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Dto;
|
|
|
|
use App\Models\ProductInco;
|
|
use Domain\Enums\Nutriscore;
|
|
use Domain\Models\ValueObjects\NutritionalValues;
|
|
use Illuminate\Contracts\Routing\UrlRoutable;
|
|
use Illuminate\Contracts\Support\Arrayable;
|
|
|
|
/**
|
|
* @implements Arrayable<string, mixed>
|
|
*/
|
|
final readonly class ProductIncoDto implements Arrayable, UrlRoutable
|
|
{
|
|
public function __construct(
|
|
public int $id,
|
|
public int $no_art,
|
|
public string $product_id,
|
|
public ?string $ingredients,
|
|
public ?string $preparation,
|
|
public ?string $servings,
|
|
public ?string $allergens,
|
|
public ?string $selling_argument,
|
|
public ?Nutriscore $nutriscore,
|
|
public ?string $nutriscore_args,
|
|
public NutritionalValues $nutrition,
|
|
) {
|
|
}
|
|
|
|
public static function fromModel(ProductInco $inco): self
|
|
{
|
|
return new self(
|
|
id: $inco->id,
|
|
no_art: $inco->no_art,
|
|
product_id: (string) $inco->product_id,
|
|
ingredients: $inco->ingredients,
|
|
preparation: $inco->preparation,
|
|
servings: $inco->servings,
|
|
allergens: $inco->allergens,
|
|
selling_argument: $inco->selling_argument,
|
|
nutriscore: $inco->nutriscore,
|
|
nutriscore_args: $inco->nutriscore_args,
|
|
nutrition: $inco->nutrition,
|
|
);
|
|
}
|
|
|
|
#[\Override]
|
|
public function getRouteKey(): mixed
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
#[\Override]
|
|
public function getRouteKeyName(): string
|
|
{
|
|
return 'id';
|
|
}
|
|
|
|
#[\Override]
|
|
public function resolveRouteBinding($value, $field = null): mixed
|
|
{
|
|
return null;
|
|
}
|
|
|
|
#[\Override]
|
|
public function resolveChildRouteBinding($childType, $value, $field): mixed
|
|
{
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
#[\Override]
|
|
public function toArray(): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'no_art' => $this->no_art,
|
|
'product_id' => $this->product_id,
|
|
'ingredients' => $this->ingredients,
|
|
'preparation' => $this->preparation,
|
|
'servings' => $this->servings,
|
|
'allergens' => $this->allergens,
|
|
'selling_argument' => $this->selling_argument,
|
|
'nutriscore' => $this->nutriscore?->value,
|
|
'nutriscore_args' => $this->nutriscore_args,
|
|
'nutrition' => $this->nutrition->toArray(),
|
|
];
|
|
}
|
|
}
|