1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the SexyField package. |
5
|
|
|
* |
6
|
|
|
* (c) Dion Snoeijen <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare (strict_types = 1); |
13
|
|
|
|
14
|
|
|
namespace Tardigrades\Entity; |
15
|
|
|
|
16
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
17
|
|
|
use Doctrine\Common\Collections\Collection; |
18
|
|
|
use Tardigrades\SectionField\ValueObject\Id; |
19
|
|
|
use Tardigrades\SectionField\ValueObject\Handle; |
20
|
|
|
use Tardigrades\SectionField\ValueObject\Name; |
21
|
|
|
use Tardigrades\SectionField\ValueObject\Created; |
22
|
|
|
use Tardigrades\SectionField\ValueObject\Updated; |
23
|
|
|
|
24
|
|
|
class Application implements ApplicationInterface |
25
|
|
|
{ |
26
|
|
|
/** @var int */ |
27
|
|
|
protected $id; |
28
|
|
|
|
29
|
|
|
/** @var string */ |
30
|
|
|
protected $name; |
31
|
|
|
|
32
|
|
|
/** @var string */ |
33
|
|
|
protected $handle; |
34
|
|
|
|
35
|
|
|
/** @var ArrayCollection */ |
36
|
|
|
protected $languages; |
37
|
|
|
|
38
|
|
|
/** @var ArrayCollection */ |
39
|
|
|
protected $sections; |
40
|
|
|
|
41
|
|
|
/** @var \DateTime */ |
42
|
|
|
protected $created; |
43
|
|
|
|
44
|
|
|
/** @var \DateTime */ |
45
|
|
|
protected $updated; |
46
|
|
|
|
47
|
|
|
public function __construct( |
48
|
|
|
Collection $languages = null, |
49
|
|
|
Collection $sections = null |
50
|
|
|
) { |
51
|
|
|
$this->languages = is_null($languages) ? new ArrayCollection() : $languages; |
52
|
|
|
$this->sections = is_null($sections) ? new ArrayCollection() : $sections; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function setId(int $id): ApplicationInterface |
56
|
|
|
{ |
57
|
|
|
$this->id = $id; |
58
|
|
|
|
59
|
|
|
return $this; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function getId(): ?int |
63
|
|
|
{ |
64
|
|
|
return $this->id; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function getIdValueObject(): ?Id |
68
|
|
|
{ |
69
|
|
|
return $this->id ? Id::fromInt($this->id) : null; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function setName(string $name): ApplicationInterface |
73
|
|
|
{ |
74
|
|
|
$this->name = $name; |
75
|
|
|
|
76
|
|
|
return $this; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function getName(): Name |
80
|
|
|
{ |
81
|
|
|
return Name::fromString($this->name); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function setHandle(string $handle): ApplicationInterface |
85
|
|
|
{ |
86
|
|
|
$this->handle = $handle; |
87
|
|
|
|
88
|
|
|
return $this; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function getHandle(): Handle |
92
|
|
|
{ |
93
|
|
|
return Handle::fromString($this->handle); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function getLanguages(): Collection |
97
|
|
|
{ |
98
|
|
|
return $this->languages; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function addLanguage(LanguageInterface $language): ApplicationInterface |
102
|
|
|
{ |
103
|
|
|
if ($this->languages->contains($language)) { |
104
|
|
|
return $this; |
105
|
|
|
} |
106
|
|
|
$this->languages->add($language); |
107
|
|
|
|
108
|
|
|
return $this; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function removeLanguage(LanguageInterface $language): ApplicationInterface |
112
|
|
|
{ |
113
|
|
|
if (!$this->languages->contains($language)) { |
114
|
|
|
return $this; |
115
|
|
|
} |
116
|
|
|
$this->languages->removeElement($language); |
117
|
|
|
|
118
|
|
|
return $this; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function getSections(): Collection |
122
|
|
|
{ |
123
|
|
|
return $this->sections; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function addSection(SectionInterface $section): ApplicationInterface |
127
|
|
|
{ |
128
|
|
|
if ($this->sections->contains($section)) { |
129
|
|
|
return $this; |
130
|
|
|
} |
131
|
|
|
$this->sections->add($section); |
132
|
|
|
|
133
|
|
|
return $this; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function removeSection(SectionInterface $section): ApplicationInterface |
137
|
|
|
{ |
138
|
|
|
if (!$this->sections->contains($section)) { |
139
|
|
|
return $this; |
140
|
|
|
} |
141
|
|
|
$this->sections->removeElement($section); |
142
|
|
|
|
143
|
|
|
return $this; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
public function setCreated(\DateTime $created): ApplicationInterface |
147
|
|
|
{ |
148
|
|
|
$this->created = $created; |
149
|
|
|
|
150
|
|
|
return $this; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
public function getCreated(): ?\DateTime |
154
|
|
|
{ |
155
|
|
|
return $this->created ?: null; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
public function getCreatedValueObject(): ?Created |
159
|
|
|
{ |
160
|
|
|
return $this->created ? Created::fromDateTime($this->created) : null; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
public function setUpdated(\DateTime $updated): ApplicationInterface |
164
|
|
|
{ |
165
|
|
|
$this->updated = $updated; |
166
|
|
|
|
167
|
|
|
return $this; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
public function getUpdated(): ?\DateTime |
171
|
|
|
{ |
172
|
|
|
return $this->updated ?: null; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
public function getUpdatedValueObject(): ?Updated |
176
|
|
|
{ |
177
|
|
|
return $this->updated ? Updated::fromDateTime($this->updated) : null; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
public function onPrePersist(): void |
181
|
|
|
{ |
182
|
|
|
$this->created = new \DateTime("now"); |
183
|
|
|
$this->updated = new \DateTime("now"); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
public function onPreUpdate(): void |
187
|
|
|
{ |
188
|
|
|
$this->updated = new \DateTime("now"); |
189
|
|
|
} |
190
|
|
|
} |
191
|
|
|
|