1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Omatech\Mage\Core\Domains\Users; |
4
|
|
|
|
5
|
|
|
use Omatech\Mage\Core\Domains\Permissions\Contracts\PermissionInterface; |
6
|
|
|
use Omatech\Mage\Core\Domains\Roles\Contracts\RoleInterface; |
7
|
|
|
use Omatech\Mage\Core\Domains\Shared\Traits\FromArray; |
8
|
|
|
use Omatech\Mage\Core\Domains\Shared\Traits\PermissionsManager; |
9
|
|
|
use Omatech\Mage\Core\Domains\Shared\Traits\RolesManager; |
10
|
|
|
use Omatech\Mage\Core\Domains\Users\Contracts\AllUserInterface; |
11
|
|
|
use Omatech\Mage\Core\Domains\Users\Contracts\FindUserInterface; |
12
|
|
|
use Omatech\Mage\Core\Domains\Users\Contracts\UserInterface; |
13
|
|
|
use Omatech\Mage\Core\Domains\Users\Features\ExistsAndDeleteUser; |
14
|
|
|
use Omatech\Mage\Core\Domains\Users\Features\FindOrFailUser; |
15
|
|
|
use Omatech\Mage\Core\Domains\Users\Features\UpdateOrCreateUser; |
16
|
|
|
|
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 |
37
|
|
|
{ |
38
|
19 |
|
return $this->id; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param int $id |
43
|
|
|
* @return $this|mixed |
44
|
|
|
*/ |
45
|
19 |
|
public function setId(int $id) |
46
|
|
|
{ |
47
|
19 |
|
$this->id = $id; |
48
|
|
|
|
49
|
19 |
|
return $this; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return string |
54
|
|
|
*/ |
55
|
19 |
|
public function getName(): string |
56
|
|
|
{ |
57
|
19 |
|
return $this->name; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param string $name |
62
|
|
|
* @return $this|mixed |
63
|
|
|
*/ |
64
|
21 |
|
public function setName(string $name) |
65
|
|
|
{ |
66
|
21 |
|
$this->name = $name; |
67
|
|
|
|
68
|
21 |
|
return $this; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return string |
73
|
|
|
*/ |
74
|
19 |
|
public function getLanguage(): string |
75
|
|
|
{ |
76
|
19 |
|
return $this->language; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param string $language |
81
|
|
|
* @return $this|mixed |
82
|
|
|
*/ |
83
|
21 |
|
public function setLanguage(string $language) |
84
|
|
|
{ |
85
|
21 |
|
$this->language = $language; |
86
|
|
|
|
87
|
21 |
|
return $this; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return string |
92
|
|
|
*/ |
93
|
19 |
|
public function getEmail(): string |
94
|
|
|
{ |
95
|
19 |
|
return $this->email; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param string $email |
100
|
|
|
* @return $this|mixed |
101
|
|
|
*/ |
102
|
21 |
|
public function setEmail(string $email) |
103
|
|
|
{ |
104
|
21 |
|
$this->email = $email; |
105
|
|
|
|
106
|
21 |
|
return $this; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @return string|null |
111
|
|
|
*/ |
112
|
19 |
|
public function getEmailVerifiedAt(): ?string |
113
|
|
|
{ |
114
|
19 |
|
return $this->emailVerifiedAt; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @param string|null $emailVerifiedAt |
119
|
|
|
* @return $this|mixed |
120
|
|
|
*/ |
121
|
2 |
|
public function setEmailVerifiedAt(?string $emailVerifiedAt) |
122
|
|
|
{ |
123
|
2 |
|
$this->emailVerifiedAt = $emailVerifiedAt; |
124
|
|
|
|
125
|
2 |
|
return $this; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @return string |
130
|
|
|
*/ |
131
|
19 |
|
public function getPassword(): string |
132
|
|
|
{ |
133
|
19 |
|
return $this->password; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @param string $password |
138
|
|
|
* @return $this|mixed |
139
|
|
|
*/ |
140
|
21 |
|
public function setPassword(string $password) |
141
|
|
|
{ |
142
|
21 |
|
$this->password = $password; |
143
|
|
|
|
144
|
21 |
|
return $this; |
145
|
|
|
} |
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 |
267
|
|
|
{ |
268
|
19 |
|
return (new UpdateOrCreateUser())->make($this); |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* @return bool |
273
|
|
|
* @throws Exceptions\UserDoesNotExistsException |
274
|
|
|
*/ |
275
|
3 |
|
public function delete(): bool |
276
|
|
|
{ |
277
|
3 |
|
return (new ExistsAndDeleteUser())->make($this); |
278
|
|
|
} |
279
|
|
|
} |
280
|
|
|
|