|
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\Core\Metadata\Tests\Fixtures; |
|
13
|
|
|
|
|
14
|
|
|
use Cubiche\Core\Collections\ArrayCollection\ArraySet; |
|
15
|
|
|
use Cubiche\Core\Collections\ArrayCollection\ArraySetInterface; |
|
16
|
|
|
use Cubiche\Core\Metadata\Tests\Fixtures\Annotations as Cubiche; |
|
17
|
|
|
use Cubiche\Domain\Model\AggregateRoot; |
|
18
|
|
|
use Cubiche\Domain\System\Integer; |
|
19
|
|
|
use Cubiche\Domain\System\StringLiteral; |
|
20
|
|
|
use Cubiche\Domain\Web\EmailAddress; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* User Class. |
|
24
|
|
|
* |
|
25
|
|
|
* @author Ivannis Suárez Jerez <[email protected]> |
|
26
|
|
|
* @Cubiche\AggregateRoot |
|
27
|
|
|
*/ |
|
28
|
|
|
class User extends AggregateRoot |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* @var IdInterface |
|
32
|
|
|
* @Cubiche\Id |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $id; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var StringLiteral |
|
38
|
|
|
* @Cubiche\Field(type="StringLiteral", name="fullName") |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $name; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var StringLiteral |
|
44
|
|
|
* @Cubiche\Field(type="StringLiteral") |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $username; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var int |
|
50
|
|
|
* @Cubiche\Field(type="Integer") |
|
51
|
|
|
*/ |
|
52
|
|
|
protected $age; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @var EmailAddress |
|
56
|
|
|
* @Cubiche\Field(type="EmailAddress") |
|
57
|
|
|
*/ |
|
58
|
|
|
protected $email; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @var ArraySetInterface |
|
62
|
|
|
* @Cubiche\Field(type="ArraySet", of="Cubiche\Core\Metadata\Tests\Fixtures\Address") |
|
63
|
|
|
*/ |
|
64
|
|
|
protected $addresses; |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @var ArraySetInterface |
|
68
|
|
|
* @Cubiche\Field(type="ArraySet", of="Cubiche\Core\Metadata\Tests\Fixtures\User") |
|
69
|
|
|
*/ |
|
70
|
|
|
protected $friends; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param UserId $id |
|
74
|
|
|
* @param string $name |
|
75
|
|
|
* @param string $username |
|
76
|
|
|
* @param int $age |
|
77
|
|
|
* @param string $email |
|
78
|
|
|
*/ |
|
79
|
|
|
public function __construct(UserId $id, $name, $username, $age, $email) |
|
80
|
|
|
{ |
|
81
|
|
|
parent::__construct($id); |
|
82
|
|
|
|
|
83
|
|
|
$this->name = StringLiteral::fromNative($name); |
|
84
|
|
|
$this->username = StringLiteral::fromNative($username); |
|
85
|
|
|
$this->age = Integer::fromNative($age); |
|
86
|
|
|
$this->email = EmailAddress::fromNative($email); |
|
87
|
|
|
$this->addresses = new ArraySet(); |
|
|
|
|
|
|
88
|
|
|
$this->friends = new ArraySet(); |
|
|
|
|
|
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @return StringLiteral |
|
93
|
|
|
*/ |
|
94
|
|
|
public function name() |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->name; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @return StringLiteral |
|
101
|
|
|
*/ |
|
102
|
|
|
public function username() |
|
103
|
|
|
{ |
|
104
|
|
|
return $this->username; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @return int |
|
109
|
|
|
*/ |
|
110
|
|
|
public function age() |
|
111
|
|
|
{ |
|
112
|
|
|
return $this->age; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @return EmailAddress |
|
117
|
|
|
*/ |
|
118
|
|
|
public function email() |
|
119
|
|
|
{ |
|
120
|
|
|
return $this->email; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* @return ArraySetInterface |
|
125
|
|
|
*/ |
|
126
|
|
|
public function addresses() |
|
127
|
|
|
{ |
|
128
|
|
|
return $this->addresses; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @param Address $address |
|
133
|
|
|
*/ |
|
134
|
|
|
public function addAddress(Address $address) |
|
135
|
|
|
{ |
|
136
|
|
|
return $this->addresses->add($address); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* @return ArraySetInterface |
|
141
|
|
|
*/ |
|
142
|
|
|
public function friends() |
|
143
|
|
|
{ |
|
144
|
|
|
return $this->friends; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* @param User $friend |
|
149
|
|
|
*/ |
|
150
|
|
|
public function addFriend(User $friend) |
|
151
|
|
|
{ |
|
152
|
|
|
return $this->friends->add($friend); |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..