1 | <?php |
||
17 | class User implements UserInterface |
||
18 | { |
||
19 | use FromArray; |
||
20 | use PermissionsManager; |
||
21 | use RolesManager; |
||
22 | |||
23 | private $id; |
||
24 | private $name; |
||
25 | private $language; |
||
26 | private $email; |
||
27 | private $emailVerifiedAt; |
||
28 | private $password; |
||
29 | private $rememberToken; |
||
30 | private $createdAt; |
||
31 | private $updatedAt; |
||
32 | |||
33 | /** |
||
34 | * @return int|null |
||
35 | */ |
||
36 | 19 | public function getId(): ?int |
|
40 | |||
41 | /** |
||
42 | * @param int $id |
||
43 | * @return $this|mixed |
||
44 | */ |
||
45 | 19 | public function setId(int $id) |
|
51 | |||
52 | /** |
||
53 | * @return string |
||
54 | */ |
||
55 | 19 | public function getName(): string |
|
59 | |||
60 | /** |
||
61 | * @param string $name |
||
62 | * @return $this|mixed |
||
63 | */ |
||
64 | 21 | public function setName(string $name) |
|
70 | |||
71 | /** |
||
72 | * @return string |
||
73 | */ |
||
74 | 19 | public function getLanguage(): string |
|
78 | |||
79 | /** |
||
80 | * @param string $language |
||
81 | * @return $this|mixed |
||
82 | */ |
||
83 | 21 | public function setLanguage(string $language) |
|
89 | |||
90 | /** |
||
91 | * @return string |
||
92 | */ |
||
93 | 19 | public function getEmail(): string |
|
97 | |||
98 | /** |
||
99 | * @param string $email |
||
100 | * @return $this|mixed |
||
101 | */ |
||
102 | 21 | public function setEmail(string $email) |
|
108 | |||
109 | /** |
||
110 | * @return string|null |
||
111 | */ |
||
112 | 19 | public function getEmailVerifiedAt(): ?string |
|
116 | |||
117 | /** |
||
118 | * @param string|null $emailVerifiedAt |
||
119 | * @return $this|mixed |
||
120 | */ |
||
121 | 2 | public function setEmailVerifiedAt(?string $emailVerifiedAt) |
|
127 | |||
128 | /** |
||
129 | * @return string |
||
130 | */ |
||
131 | 19 | public function getPassword(): string |
|
135 | |||
136 | /** |
||
137 | * @param string $password |
||
138 | * @return $this|mixed |
||
139 | */ |
||
140 | 21 | public function setPassword(string $password) |
|
146 | |||
147 | /** |
||
148 | * @return string|null |
||
149 | */ |
||
150 | 19 | public function getRememberToken(): ?string |
|
151 | { |
||
152 | 19 | return $this->rememberToken; |
|
153 | } |
||
154 | |||
155 | /** |
||
156 | * @param string|null $rememberToken |
||
157 | * @return $this|mixed |
||
158 | */ |
||
159 | 2 | public function setRememberToken(?string $rememberToken) |
|
160 | { |
||
161 | 2 | $this->rememberToken = $rememberToken; |
|
162 | |||
163 | 2 | return $this; |
|
164 | } |
||
165 | |||
166 | /** |
||
167 | * @return string |
||
168 | */ |
||
169 | 6 | public function getCreatedAt(): string |
|
170 | { |
||
171 | 6 | return $this->createdAt; |
|
172 | } |
||
173 | |||
174 | /** |
||
175 | * @param string $createdAt |
||
176 | * @return $this|mixed |
||
177 | */ |
||
178 | 19 | public function setCreatedAt(string $createdAt) |
|
179 | { |
||
180 | 19 | $this->createdAt = $createdAt; |
|
181 | |||
182 | 19 | return $this; |
|
183 | } |
||
184 | |||
185 | /** |
||
186 | * @return string |
||
187 | */ |
||
188 | 6 | public function getUpdatedAt(): string |
|
189 | { |
||
190 | 6 | return $this->updatedAt; |
|
191 | } |
||
192 | |||
193 | /** |
||
194 | * @param string $updatedAt |
||
195 | * @return $this|mixed |
||
196 | */ |
||
197 | 19 | public function setUpdatedAt(string $updatedAt) |
|
198 | { |
||
199 | 19 | $this->updatedAt = $updatedAt; |
|
200 | |||
201 | 19 | return $this; |
|
202 | } |
||
203 | |||
204 | /** |
||
205 | * @return array |
||
206 | */ |
||
207 | 20 | public function getPermissions(): array |
|
208 | { |
||
209 | 20 | return $this->permissions; |
|
210 | } |
||
211 | |||
212 | /** |
||
213 | * @return array |
||
214 | */ |
||
215 | 20 | public function getRoles(): array |
|
216 | { |
||
217 | 20 | return $this->roles; |
|
218 | } |
||
219 | |||
220 | /** |
||
221 | * @return array |
||
222 | */ |
||
223 | 19 | public function getPermissionsIds(): array |
|
224 | { |
||
225 | return array_map(static function (PermissionInterface $permission) { |
||
226 | 6 | return $permission->getId(); |
|
227 | 19 | }, $this->getPermissions()); |
|
228 | } |
||
229 | |||
230 | /** |
||
231 | * @return array |
||
232 | */ |
||
233 | 19 | public function getRolesIds(): array |
|
234 | { |
||
235 | return array_map(static function (RoleInterface $role) { |
||
236 | 6 | return $role->getId(); |
|
237 | 19 | }, $this->getRoles()); |
|
238 | } |
||
239 | |||
240 | /** |
||
241 | * @param AllUserInterface $all |
||
242 | * @return mixed |
||
243 | */ |
||
244 | 1 | public static function all(AllUserInterface $all) |
|
245 | { |
||
246 | 1 | return $all->get(); |
|
247 | } |
||
248 | |||
249 | /** |
||
250 | * @param FindUserInterface $find |
||
251 | * @param array $params |
||
252 | * @return mixed|User|null |
||
253 | * @throws Exceptions\UserDoesNotExistsException |
||
254 | */ |
||
255 | 3 | public static function find(FindUserInterface $find, array $params) |
|
256 | { |
||
257 | 3 | return (new FindOrFailUser())->make($find, $params); |
|
258 | } |
||
259 | |||
260 | /** |
||
261 | * @return bool |
||
262 | * @throws Exceptions\UserAlreadyExistsException |
||
263 | * @throws Exceptions\UserDoesNotExistsException |
||
264 | * @throws Exceptions\UserNameExistsMustBeUniqueException |
||
265 | */ |
||
266 | 19 | public function save(): bool |
|
270 | |||
271 | /** |
||
272 | * @return bool |
||
273 | * @throws Exceptions\UserDoesNotExistsException |
||
274 | */ |
||
275 | 3 | public function delete(): bool |
|
279 | } |
||
280 |