|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the Cubiche package. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (c) Cubiche |
|
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
|
|
|
namespace Cubiche\Domain\Repository\Tests\Fixtures; |
|
13
|
|
|
|
|
14
|
|
|
use Cubiche\Core\Collections\ArrayCollection\ArrayHashMap; |
|
15
|
|
|
use Cubiche\Core\Collections\ArrayCollection\ArrayHashMapInterface; |
|
16
|
|
|
use Cubiche\Core\Collections\ArrayCollection\ArrayList; |
|
17
|
|
|
use Cubiche\Core\Collections\ArrayCollection\ArrayListInterface; |
|
18
|
|
|
use Cubiche\Core\Collections\ArrayCollection\ArraySet; |
|
19
|
|
|
use Cubiche\Core\Collections\ArrayCollection\ArraySetInterface; |
|
20
|
|
|
use Cubiche\Domain\Model\AggregateRoot; |
|
21
|
|
|
use Cubiche\Domain\System\StringLiteral; |
|
22
|
|
|
use Cubiche\Domain\Web\EmailAddress; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* User Class. |
|
26
|
|
|
* |
|
27
|
|
|
* @author Karel Osorio Ramírez <[email protected]> |
|
28
|
|
|
* @author Ivannis Suárez Jerez <[email protected]> |
|
29
|
|
|
*/ |
|
30
|
|
|
class User extends AggregateRoot |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $name; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var StringLiteral |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $fullName; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var int |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $age; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var EmailAddress |
|
49
|
|
|
*/ |
|
50
|
|
|
protected $email; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @var ArrayListInterface |
|
54
|
|
|
*/ |
|
55
|
|
|
protected $phonenumbers; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @var Phonenumber |
|
59
|
|
|
*/ |
|
60
|
|
|
protected $fax; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @var Role |
|
64
|
|
|
*/ |
|
65
|
|
|
protected $mainRole; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @var ArraySetInterface |
|
69
|
|
|
*/ |
|
70
|
|
|
protected $roles; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @var ArrayHashMapInterface |
|
74
|
|
|
*/ |
|
75
|
|
|
protected $languagesLevel; |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @var ArraySetInterface |
|
79
|
|
|
*/ |
|
80
|
|
|
protected $addresses; |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @var ArraySetInterface |
|
84
|
|
|
*/ |
|
85
|
|
|
protected $friends; |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @param UserId $id |
|
89
|
|
|
* @param string $name |
|
90
|
|
|
* @param int $age |
|
91
|
|
|
* @param string $email |
|
92
|
|
|
*/ |
|
93
|
|
|
public function __construct(UserId $id, $name, $age, $email) |
|
94
|
|
|
{ |
|
95
|
|
|
parent::__construct($id); |
|
96
|
|
|
|
|
97
|
|
|
$this->name = $name; |
|
98
|
|
|
$this->fullName = StringLiteral::fromNative($name); |
|
99
|
|
|
$this->age = $age; |
|
100
|
|
|
$this->email = EmailAddress::fromNative($email); |
|
101
|
|
|
$this->phonenumbers = new ArrayList(); |
|
102
|
|
|
$this->roles = new ArraySet(); |
|
103
|
|
|
$this->languagesLevel = new ArrayHashMap(); |
|
104
|
|
|
$this->addresses = new ArraySet(); |
|
105
|
|
|
$this->friends = new ArraySet(); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @return int |
|
110
|
|
|
*/ |
|
111
|
|
|
public function age() |
|
112
|
|
|
{ |
|
113
|
|
|
return $this->age; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @param int $age |
|
118
|
|
|
*/ |
|
119
|
|
|
public function setAge($age) |
|
120
|
|
|
{ |
|
121
|
|
|
$this->age = $age; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @return string |
|
126
|
|
|
*/ |
|
127
|
|
|
public function name() |
|
128
|
|
|
{ |
|
129
|
|
|
return $this->name; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* @return StringLiteral |
|
134
|
|
|
*/ |
|
135
|
|
|
public function fullName() |
|
136
|
|
|
{ |
|
137
|
|
|
return $this->fullName; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* @return EmailAddress |
|
142
|
|
|
*/ |
|
143
|
|
|
public function email() |
|
144
|
|
|
{ |
|
145
|
|
|
return $this->email; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @return ArrayListInterface |
|
150
|
|
|
*/ |
|
151
|
|
|
public function phonenumbers() |
|
152
|
|
|
{ |
|
153
|
|
|
return $this->phonenumbers; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* @param Phonenumber $phonenumber |
|
158
|
|
|
*/ |
|
159
|
|
|
public function addPhonenumber(Phonenumber $phonenumber) |
|
160
|
|
|
{ |
|
161
|
|
|
return $this->phonenumbers->add($phonenumber); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* @return Phonenumber |
|
166
|
|
|
*/ |
|
167
|
|
|
public function fax() |
|
168
|
|
|
{ |
|
169
|
|
|
return $this->fax; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* @param Phonenumber $fax |
|
174
|
|
|
*/ |
|
175
|
|
|
public function setFax(Phonenumber $fax) |
|
176
|
|
|
{ |
|
177
|
|
|
$this->fax = $fax; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* @return Role |
|
182
|
|
|
*/ |
|
183
|
|
|
public function mainRole() |
|
184
|
|
|
{ |
|
185
|
|
|
return $this->mainRole; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* @param Role $mainRole |
|
190
|
|
|
*/ |
|
191
|
|
|
public function setMainRole(Role $mainRole) |
|
192
|
|
|
{ |
|
193
|
|
|
$this->mainRole = $mainRole; |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* @return ArraySetInterface |
|
198
|
|
|
*/ |
|
199
|
|
|
public function roles() |
|
200
|
|
|
{ |
|
201
|
|
|
return $this->roles; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* @param Role $role |
|
206
|
|
|
*/ |
|
207
|
|
|
public function addRole(Role $role) |
|
208
|
|
|
{ |
|
209
|
|
|
return $this->roles->add($role); |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* @return ArrayHashMapInterface |
|
214
|
|
|
*/ |
|
215
|
|
|
public function languagesLevel() |
|
216
|
|
|
{ |
|
217
|
|
|
return $this->languagesLevel; |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
/** |
|
221
|
|
|
* @param string $language |
|
222
|
|
|
* @param int $level |
|
223
|
|
|
* |
|
224
|
|
|
* @return ArrayHashMap|ArrayHashMapInterface |
|
225
|
|
|
*/ |
|
226
|
|
|
public function setLanguageLevel($language, $level) |
|
227
|
|
|
{ |
|
228
|
|
|
return $this->languagesLevel->set($language, $level); |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
/** |
|
232
|
|
|
* @return ArraySetInterface |
|
233
|
|
|
*/ |
|
234
|
|
|
public function addresses() |
|
235
|
|
|
{ |
|
236
|
|
|
return $this->addresses; |
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
/** |
|
240
|
|
|
* @param Address $address |
|
241
|
|
|
*/ |
|
242
|
|
|
public function addAddress(Address $address) |
|
243
|
|
|
{ |
|
244
|
|
|
return $this->addresses->add($address); |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
/** |
|
248
|
|
|
* @return ArraySetInterface |
|
249
|
|
|
*/ |
|
250
|
|
|
public function friends() |
|
251
|
|
|
{ |
|
252
|
|
|
return $this->friends; |
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
/** |
|
256
|
|
|
* @param User $friend |
|
257
|
|
|
*/ |
|
258
|
|
|
public function addFriend(User $friend) |
|
259
|
|
|
{ |
|
260
|
|
|
return $this->friends->add($friend); |
|
261
|
|
|
} |
|
262
|
|
|
} |
|
263
|
|
|
|