46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\DTOs;
|
|
|
|
class CategoryData
|
|
{
|
|
public function __construct(
|
|
public readonly string $slug,
|
|
public readonly string $label,
|
|
public readonly ?string $desc = null,
|
|
public readonly ?string $image = null,
|
|
public readonly ?string $metaTitle = null,
|
|
public readonly ?string $metaDescription = null,
|
|
) {}
|
|
|
|
/**
|
|
* @param array<string, mixed> $data
|
|
*/
|
|
public static function fromArray(array $data): self
|
|
{
|
|
return new self(
|
|
slug: $data['slug'],
|
|
label: $data['label'],
|
|
desc: $data['desc'] ?? null,
|
|
image: $data['image'] ?? null,
|
|
metaTitle: $data['meta_title'] ?? null,
|
|
metaDescription: $data['meta_description'] ?? null,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(): array
|
|
{
|
|
return [
|
|
'slug' => $this->slug,
|
|
'label' => $this->label,
|
|
'desc' => $this->desc,
|
|
'image' => $this->image,
|
|
'meta_title' => $this->metaTitle,
|
|
'meta_description' => $this->metaDescription,
|
|
];
|
|
}
|
|
}
|