1 | <?php |
||
14 | class ApplicationUser extends EventSourcedAggregateRoot implements OriginalAppUser |
||
15 | { |
||
16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
||
17 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
||
18 | ///////////////////////////////////////////// PROPERTIES /////////////////////////////////////////////////// |
||
19 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
||
20 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
||
21 | |||
22 | /** |
||
23 | * @var ApplicationUserId |
||
24 | */ |
||
25 | private $id; |
||
26 | |||
27 | /** |
||
28 | * @var string |
||
29 | */ |
||
30 | private $name; |
||
31 | |||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | private $preferredLanguage; |
||
36 | |||
37 | /** |
||
38 | * @var ThirdPartyAccount[] |
||
39 | */ |
||
40 | private $thirdPartyAccounts; |
||
41 | |||
42 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
||
43 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
||
44 | ///////////////////////////////////////// PRIVATE CONSTRUCTOR ////////////////////////////////////////////// |
||
45 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
||
46 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
||
47 | |||
48 | /** |
||
49 | * Constructor |
||
50 | */ |
||
51 | 6 | private function __construct() |
|
55 | |||
56 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
||
57 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
||
58 | //////////////////////////////////////////// DOMAIN METHODS //////////////////////////////////////////////// |
||
59 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
||
60 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
||
61 | |||
62 | /** |
||
63 | * @param ThirdPartyAccount $thirdPartyUser |
||
64 | */ |
||
65 | public function linkToThirdPartyAccount(ThirdPartyAccount $thirdPartyUser) |
||
73 | |||
74 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
||
75 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
||
76 | ////////////////////////////////////////////// ACCESSORS /////////////////////////////////////////////////// |
||
77 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
||
78 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
||
79 | |||
80 | /** |
||
81 | * Returns the user id |
||
82 | * |
||
83 | * @return ApplicationUserId |
||
84 | */ |
||
85 | 3 | public function getId() |
|
89 | |||
90 | /** |
||
91 | * @return string |
||
92 | */ |
||
93 | 3 | public function getAggregateRootId() |
|
97 | |||
98 | /** |
||
99 | * Returns the user name |
||
100 | * |
||
101 | * @return string |
||
102 | */ |
||
103 | 3 | public function getName() |
|
107 | |||
108 | /** |
||
109 | * Returns the preferred language |
||
110 | * |
||
111 | * @return string |
||
112 | */ |
||
113 | 3 | public function getPreferredLanguage() |
|
117 | |||
118 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
||
119 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
||
120 | ////////////////////////////////////////// PRIVATE METHODS ///////////////////////////////////////////////// |
||
121 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
||
122 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
||
123 | |||
124 | /** |
||
125 | * Initialize the game |
||
126 | * |
||
127 | * @param ApplicationUserId $id |
||
128 | * @param string $name |
||
129 | * @param string $language |
||
130 | */ |
||
131 | 3 | private function initialize(ApplicationUserId $id, $name, $language) |
|
135 | |||
136 | /** |
||
137 | * @param Source $source |
||
138 | * |
||
139 | * @return bool |
||
140 | */ |
||
141 | private function isThirdPartyAccountAlreadyLinked(Source $source) |
||
145 | |||
146 | /** |
||
147 | * @param ThirdPartyAccount $account |
||
148 | */ |
||
149 | private function setThirdPartyUser(ThirdPartyAccount $account) |
||
153 | |||
154 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
||
155 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
||
156 | //////////////////////////////////////////// APPLY EVENTS ////////////////////////////////////////////////// |
||
157 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
||
158 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
||
159 | |||
160 | /** |
||
161 | * Apply the user created event |
||
162 | * |
||
163 | * @param \MessageApp\Event\UserCreatedEvent $event |
||
164 | */ |
||
165 | 3 | protected function applyUserCreatedEvent(UserCreatedEvent $event) |
|
172 | |||
173 | /** |
||
174 | * Apply the third party account linked event |
||
175 | * |
||
176 | * @param ThirdPartyAccountLinkedEvent $event |
||
177 | */ |
||
178 | protected function applyThirdPartyAccountLinkedEvent(ThirdPartyAccountLinkedEvent $event) |
||
182 | |||
183 | /** |
||
184 | * Apply the third party account replaced event |
||
185 | * |
||
186 | * @param ThirdPartyAccountReplacedEvent $event |
||
187 | */ |
||
188 | protected function applyThirdPartyAccountReplacedEvent(ThirdPartyAccountReplacedEvent $event) |
||
192 | |||
193 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
||
194 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
||
195 | ///////////////////////////////////////// STATIC CONSTRUCTOR /////////////////////////////////////////////// |
||
196 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
||
197 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
||
198 | |||
199 | /** |
||
200 | * Create a new instance |
||
201 | * |
||
202 | * @param ApplicationUserId $id |
||
203 | * @param string $name |
||
204 | * @param string $language |
||
205 | * |
||
206 | * @return ApplicationUser |
||
207 | */ |
||
208 | 3 | public static function createUser(ApplicationUserId $id, $name, $language) |
|
219 | |||
220 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
||
221 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
||
222 | /////////////////////////////////////////// RECONSTITUTION ///////////////////////////////////////////////// |
||
223 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
||
224 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
||
225 | |||
226 | /** |
||
227 | * Static construction method for reconstitution |
||
228 | * |
||
229 | * @return ApplicationUser |
||
230 | */ |
||
231 | 3 | public static function instantiateForReconstitution() |
|
235 | } |
||
236 |