-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPost.php
55 lines (49 loc) · 1.24 KB
/
Post.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
declare(strict_types=1);
namespace App\Blog;
use Symfony\Component\Uid\Uuid;
final readonly class Post
{
public function __construct(
public Uuid $id,
public string $title,
public string $link,
public string $description,
public string $content,
public string $author,
public \DateTimeImmutable $date,
) {
}
public function toString(): string
{
return <<<TEXT
Title: {$this->title}
From: {$this->author} on {$this->date->format('Y-m-d')}
Description: {$this->description}
{$this->content}
TEXT;
}
/**
* @return array{
* id: string,
* title: string,
* link: string,
* description: string,
* content: string,
* author: string,
* date: string,
* }
*/
public function toArray(): array
{
return [
'id' => $this->id->toRfc4122(),
'title' => $this->title,
'link' => $this->link,
'description' => $this->description,
'content' => $this->content,
'author' => $this->author,
'date' => $this->date->format('Y-m-d'),
];
}
}