78 lines
1.8 KiB
PHP
78 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Dto;
|
|
|
|
use App\Models\Page;
|
|
use Domain\Enums\StaticPageSlug;
|
|
use Illuminate\Contracts\Routing\UrlRoutable;
|
|
use Illuminate\Contracts\Support\Arrayable;
|
|
|
|
/**
|
|
* @implements Arrayable<string, mixed>
|
|
*/
|
|
final readonly class PageDto implements Arrayable, UrlRoutable
|
|
{
|
|
public function __construct(
|
|
public int $id,
|
|
public StaticPageSlug $slug,
|
|
public string $seo_title,
|
|
public string $seo_description,
|
|
public ?string $title,
|
|
public string $content,
|
|
) {
|
|
}
|
|
|
|
public static function fromModel(Page $page): self
|
|
{
|
|
return new self(
|
|
id: $page->id,
|
|
slug: $page->slug,
|
|
seo_title: $page->seo_title,
|
|
seo_description: $page->seo_description,
|
|
title: $page->title,
|
|
content: $page->content,
|
|
);
|
|
}
|
|
|
|
#[\Override]
|
|
public function getRouteKey(): mixed
|
|
{
|
|
return $this->slug->value;
|
|
}
|
|
|
|
#[\Override]
|
|
public function getRouteKeyName(): string
|
|
{
|
|
return 'slug';
|
|
}
|
|
|
|
#[\Override]
|
|
public function resolveRouteBinding($value, $field = null): mixed
|
|
{
|
|
return null;
|
|
}
|
|
|
|
#[\Override]
|
|
public function resolveChildRouteBinding($childType, $value, $field): mixed
|
|
{
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* @return array{id: int, slug: StaticPageSlug, seo_title: string, seo_description: string, title: string|null, content: string}
|
|
*/
|
|
#[\Override]
|
|
public function toArray(): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'slug' => $this->slug,
|
|
'seo_title' => $this->seo_title,
|
|
'seo_description' => $this->seo_description,
|
|
'title' => $this->title,
|
|
'content' => $this->content,
|
|
];
|
|
}
|
|
}
|