|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Bundle\Example\Entity; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Import classes |
|
7
|
|
|
*/ |
|
8
|
|
|
use Arus\Doctrine\Bridge\Validator\Constraint\UniqueEntity; |
|
9
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
10
|
|
|
use Ramsey\Uuid\Uuid; |
|
11
|
|
|
use Ramsey\Uuid\UuidInterface; |
|
12
|
|
|
use Sunrise\Http\Router\OpenApi\Annotation\OpenApi; |
|
13
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
|
14
|
|
|
use DateTime; |
|
15
|
|
|
use DateTimeInterface; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @ORM\Table( |
|
19
|
|
|
* indexes={ |
|
20
|
|
|
* @ORM\Index(columns={"createdAt"}), |
|
21
|
|
|
* }, |
|
22
|
|
|
* uniqueConstraints={ |
|
23
|
|
|
* @ORM\UniqueConstraint(columns={"slug"}), |
|
24
|
|
|
* }, |
|
25
|
|
|
* options={ |
|
26
|
|
|
* "charset": "utf8mb4", |
|
27
|
|
|
* "collate": "utf8mb4_unicode_ci", |
|
28
|
|
|
* }, |
|
29
|
|
|
* ) |
|
30
|
|
|
* |
|
31
|
|
|
* @ORM\Entity( |
|
32
|
|
|
* repositoryClass="App\Bundle\Example\Repository\EntryRepository", |
|
33
|
|
|
* ) |
|
34
|
|
|
* |
|
35
|
|
|
* @ORM\HasLifecycleCallbacks() |
|
36
|
|
|
* |
|
37
|
|
|
* @UniqueEntity({"slug"}) |
|
38
|
|
|
*/ |
|
39
|
|
|
class Entry |
|
40
|
|
|
{ |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @ORM\Id() |
|
44
|
|
|
* |
|
45
|
|
|
* @ORM\Column( |
|
46
|
|
|
* type="uuid", |
|
47
|
|
|
* nullable=false, |
|
48
|
|
|
* ) |
|
49
|
|
|
* |
|
50
|
|
|
* @var string|UuidInterface |
|
51
|
|
|
*/ |
|
52
|
|
|
private $id; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @ORM\Column( |
|
56
|
|
|
* type="string", |
|
57
|
|
|
* length=128, |
|
58
|
|
|
* nullable=false, |
|
59
|
|
|
* ) |
|
60
|
|
|
* |
|
61
|
|
|
* @Assert\Length(min=1, max=128) |
|
62
|
|
|
* |
|
63
|
|
|
* @OpenApi\Schema( |
|
64
|
|
|
* refName="EntryName", |
|
65
|
|
|
* type="string", |
|
66
|
|
|
* minLength=1, |
|
67
|
|
|
* maxLength=128, |
|
68
|
|
|
* nullable=false, |
|
69
|
|
|
* ) |
|
70
|
|
|
* |
|
71
|
|
|
* @var string |
|
72
|
|
|
*/ |
|
73
|
|
|
private $name = ''; |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @ORM\Column( |
|
77
|
|
|
* type="string", |
|
78
|
|
|
* length=128, |
|
79
|
|
|
* nullable=false, |
|
80
|
|
|
* ) |
|
81
|
|
|
* |
|
82
|
|
|
* @Assert\Length(min=1, max=128) |
|
83
|
|
|
* |
|
84
|
|
|
* @OpenApi\Schema( |
|
85
|
|
|
* refName="EntrySlug", |
|
86
|
|
|
* type="string", |
|
87
|
|
|
* minLength=1, |
|
88
|
|
|
* maxLength=128, |
|
89
|
|
|
* nullable=false, |
|
90
|
|
|
* ) |
|
91
|
|
|
* |
|
92
|
|
|
* @var string |
|
93
|
|
|
*/ |
|
94
|
|
|
private $slug = ''; |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @ORM\Column( |
|
98
|
|
|
* type="datetime", |
|
99
|
|
|
* nullable=false, |
|
100
|
|
|
* ) |
|
101
|
|
|
* |
|
102
|
|
|
* @var null|DateTimeInterface |
|
103
|
|
|
*/ |
|
104
|
|
|
private $createdAt = null; |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @ORM\Column( |
|
108
|
|
|
* type="datetime", |
|
109
|
|
|
* nullable=true, |
|
110
|
|
|
* ) |
|
111
|
|
|
* |
|
112
|
|
|
* @var null|DateTimeInterface |
|
113
|
|
|
*/ |
|
114
|
|
|
private $updatedAt = null; |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Inits the entity |
|
118
|
|
|
*/ |
|
119
|
16 |
|
public function __construct() |
|
120
|
|
|
{ |
|
121
|
16 |
|
$this->id = Uuid::uuid4(); |
|
122
|
16 |
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Gets the entity ID |
|
126
|
|
|
* |
|
127
|
|
|
* @return string|UuidInterface |
|
128
|
|
|
*/ |
|
129
|
12 |
|
public function getId() |
|
130
|
|
|
{ |
|
131
|
12 |
|
return $this->id; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Gets the entry name |
|
136
|
|
|
* |
|
137
|
|
|
* @return string |
|
138
|
|
|
*/ |
|
139
|
6 |
|
public function getName() : string |
|
140
|
|
|
{ |
|
141
|
6 |
|
return $this->name; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Gets the entry slug |
|
146
|
|
|
* |
|
147
|
|
|
* @return string |
|
148
|
|
|
*/ |
|
149
|
6 |
|
public function getSlug() : string |
|
150
|
|
|
{ |
|
151
|
6 |
|
return $this->slug; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* Gets the entity created date |
|
156
|
|
|
* |
|
157
|
|
|
* @return null|DateTimeInterface |
|
158
|
|
|
*/ |
|
159
|
4 |
|
public function getCreatedAt() : ?DateTimeInterface |
|
160
|
|
|
{ |
|
161
|
4 |
|
return $this->createdAt; |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* Gets the entity last updated date |
|
166
|
|
|
* |
|
167
|
|
|
* @return null|DateTimeInterface |
|
168
|
|
|
*/ |
|
169
|
4 |
|
public function getUpdatedAt() : ?DateTimeInterface |
|
170
|
|
|
{ |
|
171
|
4 |
|
return $this->updatedAt; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* Sets the entry name |
|
176
|
|
|
* |
|
177
|
|
|
* @param string $name |
|
178
|
|
|
* |
|
179
|
|
|
* @return void |
|
180
|
|
|
*/ |
|
181
|
15 |
|
public function setName(string $name) : void |
|
182
|
|
|
{ |
|
183
|
15 |
|
$this->name = $name; |
|
184
|
15 |
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* Sets the entry slug |
|
188
|
|
|
* |
|
189
|
|
|
* @param string $slug |
|
190
|
|
|
* |
|
191
|
|
|
* @return void |
|
192
|
|
|
*/ |
|
193
|
15 |
|
public function setSlug(string $slug) : void |
|
194
|
|
|
{ |
|
195
|
15 |
|
$this->slug = $slug; |
|
196
|
15 |
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* @ORM\PrePersist() |
|
200
|
|
|
* |
|
201
|
|
|
* @return void |
|
202
|
|
|
*/ |
|
203
|
12 |
|
public function prePersist() : void |
|
204
|
|
|
{ |
|
205
|
12 |
|
$this->createdAt = new DateTime('now'); |
|
206
|
12 |
|
} |
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* @ORM\PreUpdate() |
|
210
|
|
|
* |
|
211
|
|
|
* @return void |
|
212
|
|
|
*/ |
|
213
|
2 |
|
public function preUpdate() : void |
|
214
|
|
|
{ |
|
215
|
2 |
|
$this->updatedAt = new DateTime('now'); |
|
216
|
2 |
|
} |
|
217
|
|
|
} |
|
218
|
|
|
|