46 lines
1.1 KiB
PHP
46 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\DTOs;
|
|
|
|
final readonly class PageData
|
|
{
|
|
public function __construct(
|
|
public string $slug,
|
|
public string $title,
|
|
public ?string $content,
|
|
public ?string $metaTitle,
|
|
public ?string $metaDescription,
|
|
public bool $isActive = true,
|
|
) {}
|
|
|
|
/**
|
|
* @param array<string, mixed> $data
|
|
*/
|
|
public static function fromArray(array $data): self
|
|
{
|
|
return new self(
|
|
slug: $data['slug'],
|
|
title: $data['title'],
|
|
content: $data['content'] ?? null,
|
|
metaTitle: $data['meta_title'] ?? null,
|
|
metaDescription: $data['meta_description'] ?? null,
|
|
isActive: $data['is_active'] ?? true,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(): array
|
|
{
|
|
return [
|
|
'slug' => $this->slug,
|
|
'title' => $this->title,
|
|
'content' => $this->content,
|
|
'meta_title' => $this->metaTitle,
|
|
'meta_description' => $this->metaDescription,
|
|
'is_active' => $this->isActive,
|
|
];
|
|
}
|
|
}
|