58 lines
1.7 KiB
PHP
58 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\DTOs;
|
|
|
|
class AnnouncementData
|
|
{
|
|
public function __construct(
|
|
public readonly string $slug,
|
|
public readonly string $title,
|
|
public readonly string $category,
|
|
public readonly string $excerpt,
|
|
public readonly string $content,
|
|
public readonly ?string $image = null,
|
|
public readonly bool $isFeatured = false,
|
|
public readonly ?string $metaTitle = null,
|
|
public readonly ?string $metaDescription = null,
|
|
public readonly ?string $publishedAt = null,
|
|
) {}
|
|
|
|
/**
|
|
* @param array<string, mixed> $data
|
|
*/
|
|
public static function fromArray(array $data): self
|
|
{
|
|
return new self(
|
|
slug: $data['slug'],
|
|
title: $data['title'],
|
|
category: $data['category'],
|
|
excerpt: $data['excerpt'],
|
|
content: $data['content'],
|
|
image: $data['image'] ?? null,
|
|
isFeatured: $data['is_featured'] ?? false,
|
|
metaTitle: $data['meta_title'] ?? null,
|
|
metaDescription: $data['meta_description'] ?? null,
|
|
publishedAt: $data['published_at'] ?? null,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(): array
|
|
{
|
|
return [
|
|
'slug' => $this->slug,
|
|
'title' => $this->title,
|
|
'category' => $this->category,
|
|
'excerpt' => $this->excerpt,
|
|
'content' => $this->content,
|
|
'image' => $this->image,
|
|
'is_featured' => $this->isFeatured,
|
|
'meta_title' => $this->metaTitle,
|
|
'meta_description' => $this->metaDescription,
|
|
'published_at' => $this->publishedAt,
|
|
];
|
|
}
|
|
}
|