-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPost.php
More file actions
207 lines (169 loc) · 5.11 KB
/
Copy pathPost.php
File metadata and controls
207 lines (169 loc) · 5.11 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<?php
declare(strict_types=1);
namespace Light\Blog\Entity;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Light\App\Entity\AbstractEntity;
use Light\Blog\Enum\PostStatusEnum;
use Light\Blog\Repository\PostRepository;
#[ORM\Entity(repositoryClass: PostRepository::class)]
#[ORM\Table(name: 'post')]
#[ORM\HasLifecycleCallbacks]
class Post extends AbstractEntity
{
#[ORM\Column(name: 'title', type: 'text')]
private string $title;
#[ORM\Column(name: 'slug', type: 'text', unique: true)]
private string $slug;
#[ORM\Column(name: 'post_date', type: 'datetime_immutable')]
private DateTimeImmutable $postDate;
#[ORM\Column(name: 'excerpt', type: 'text')]
private string $excerpt;
#[ORM\Column(name: 'tl_dr', type: 'text', nullable: true)]
private ?string $tlDr = null;
#[ORM\Column(
name: 'status',
type: 'post_status_enum',
enumType: PostStatusEnum::class,
options: ['default' => PostStatusEnum::Draft]
)]
private PostStatusEnum $status = PostStatusEnum::Draft;
#[ORM\ManyToOne(targetEntity: Category::class)]
#[ORM\JoinColumn(name: 'category_id', referencedColumnName: 'id', nullable: false)]
private Category $category;
#[ORM\ManyToOne(targetEntity: Author::class)]
#[ORM\JoinColumn(name: 'author_id', referencedColumnName: 'id', nullable: false)]
private Author $author;
#[ORM\Column(name: 'isObsolete', type: 'boolean')]
private bool $isObsolete = false;
#[ORM\Column(name: 'opengraph_img', type: 'string', length: 255, nullable: true)]
private ?string $openGraphImage = null;
/** @var Collection<int, PostTag> */
#[ORM\OneToMany(mappedBy: 'post', targetEntity: PostTag::class)]
private Collection $postTags;
public function __construct()
{
parent::__construct();
$this->postTags = new ArrayCollection();
}
public function getTitle(): string
{
return $this->title;
}
public function setTitle(string $title): void
{
$this->title = $title;
}
public function getSlug(): string
{
return $this->slug;
}
public function setSlug(string $slug): void
{
$this->slug = $slug;
}
public function getPostDate(): DateTimeImmutable
{
return $this->postDate;
}
public function setPostDate(DateTimeImmutable $postDate): void
{
$this->postDate = $postDate;
}
public function getStatus(): PostStatusEnum
{
return $this->status;
}
public function setStatus(PostStatusEnum $status): void
{
$this->status = $status;
}
public function getCategory(): Category
{
return $this->category;
}
public function setCategory(Category $category): void
{
$this->category = $category;
}
public function getAuthor(): Author
{
return $this->author;
}
public function setAuthor(Author $author): void
{
$this->author = $author;
}
public function getExcerpt(): string
{
return $this->excerpt;
}
public function setExcerpt(string $excerpt): void
{
$this->excerpt = $excerpt;
}
public function getTlDr(): ?string
{
return $this->tlDr;
}
public function setTlDr(?string $tlDr): void
{
$this->tlDr = $tlDr;
}
public function isObsolete(): bool
{
return $this->isObsolete;
}
public function setObsolete(bool $isObsolete): void
{
$this->isObsolete = $isObsolete;
}
public function getOpenGraphImage(): ?string
{
return $this->openGraphImage;
}
public function setOpenGraphImage(?string $openGraphImage): void
{
$this->openGraphImage = $openGraphImage;
}
/**
* @return Collection<int, PostTag>
*/
public function getPostTags(): Collection
{
return $this->postTags;
}
/**
* @return array{
* id: non-empty-string,
* title: string,
* slug: string,
* status: string,
* excerpt: string,
* tlDr: string|null,
* postDate: string,
* isObsolete: bool,
* openGraphImage: string|null,
* category: array{id: non-empty-string, name: string, slug: string},
* author: array{id: non-empty-string, name: string, slug: string, github: string|null}
* }
*/
public function getArrayCopy(): array
{
return [
'id' => $this->id->toString(),
'title' => $this->title,
'slug' => $this->slug,
'status' => $this->status->value,
'excerpt' => $this->excerpt,
'tlDr' => $this->tlDr,
'isObsolete' => $this->isObsolete,
'openGraphImage' => $this->openGraphImage,
'postDate' => $this->postDate->format('Y-m-d H:i:s'),
'category' => $this->category->getArrayCopy(),
'author' => $this->author->getArrayCopy(),
];
}
}