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\UserInterface; |
12
|
|
|
use Omatech\Mage\Core\Domains\Users\Features\ExistsAndDeleteUser; |
13
|
|
|
use Omatech\Mage\Core\Domains\Users\Features\FindOrFailUser; |
14
|
|
|
use Omatech\Mage\Core\Domains\Users\Features\UpdateOrCreateUser; |
15
|
|
|
use Omatech\Mage\Core\Domains\Users\Jobs\AllUser; |
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
|
|
|
private $permissions = []; |
33
|
|
|
private $roles = []; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @return int|null |
37
|
|
|
*/ |
38
|
19 |
|
public function getId(): ?int |
39
|
|
|
{ |
40
|
19 |
|
return $this->id; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param int $id |
45
|
|
|
* |
46
|
|
|
* @return User |
47
|
|
|
*/ |
48
|
19 |
|
public function setId(int $id): self |
49
|
|
|
{ |
50
|
19 |
|
$this->id = $id; |
51
|
|
|
|
52
|
19 |
|
return $this; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
19 |
|
public function getName(): string |
59
|
|
|
{ |
60
|
19 |
|
return $this->name; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param string $name |
65
|
|
|
* |
66
|
|
|
* @return User |
67
|
|
|
*/ |
68
|
21 |
|
public function setName(string $name): self |
69
|
|
|
{ |
70
|
21 |
|
$this->name = $name; |
71
|
|
|
|
72
|
21 |
|
return $this; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return string |
77
|
|
|
*/ |
78
|
19 |
|
public function getLanguage(): string |
79
|
|
|
{ |
80
|
19 |
|
return $this->language; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param string $language |
85
|
|
|
* |
86
|
|
|
* @return User |
87
|
|
|
*/ |
88
|
21 |
|
public function setLanguage(string $language): self |
89
|
|
|
{ |
90
|
21 |
|
$this->language = $language; |
91
|
|
|
|
92
|
21 |
|
return $this; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return string |
97
|
|
|
*/ |
98
|
19 |
|
public function getEmail(): string |
99
|
|
|
{ |
100
|
19 |
|
return $this->email; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param string $email |
105
|
|
|
* |
106
|
|
|
* @return User |
107
|
|
|
*/ |
108
|
21 |
|
public function setEmail(string $email): self |
109
|
|
|
{ |
110
|
21 |
|
$this->email = $email; |
111
|
|
|
|
112
|
21 |
|
return $this; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return string|null |
117
|
|
|
*/ |
118
|
19 |
|
public function getEmailVerifiedAt(): ?string |
119
|
|
|
{ |
120
|
19 |
|
return $this->emailVerifiedAt; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @param string|null $emailVerifiedAt |
125
|
|
|
* |
126
|
|
|
* @return User |
127
|
|
|
*/ |
128
|
2 |
|
public function setEmailVerifiedAt(?string $emailVerifiedAt): self |
129
|
|
|
{ |
130
|
2 |
|
$this->emailVerifiedAt = $emailVerifiedAt; |
131
|
|
|
|
132
|
2 |
|
return $this; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @return string |
137
|
|
|
*/ |
138
|
19 |
|
public function getPassword(): string |
139
|
|
|
{ |
140
|
19 |
|
return $this->password; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @param string $password |
145
|
|
|
* |
146
|
|
|
* @return User |
147
|
|
|
*/ |
148
|
21 |
|
public function setPassword(string $password): self |
149
|
|
|
{ |
150
|
21 |
|
$this->password = $password; |
151
|
|
|
|
152
|
21 |
|
return $this; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @return string|null |
157
|
|
|
*/ |
158
|
19 |
|
public function getRememberToken(): ?string |
159
|
|
|
{ |
160
|
19 |
|
return $this->rememberToken; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @param string|null $rememberToken |
165
|
|
|
* |
166
|
|
|
* @return User |
167
|
|
|
*/ |
168
|
2 |
|
public function setRememberToken(?string $rememberToken): self |
169
|
|
|
{ |
170
|
2 |
|
$this->rememberToken = $rememberToken; |
171
|
|
|
|
172
|
2 |
|
return $this; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @return string |
177
|
|
|
*/ |
178
|
6 |
|
public function getCreatedAt(): string |
179
|
|
|
{ |
180
|
6 |
|
return $this->createdAt; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @param string $createdAt |
185
|
|
|
* |
186
|
|
|
* @return User |
187
|
|
|
*/ |
188
|
19 |
|
public function setCreatedAt(string $createdAt): self |
189
|
|
|
{ |
190
|
19 |
|
$this->createdAt = $createdAt; |
191
|
|
|
|
192
|
19 |
|
return $this; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @return string |
197
|
|
|
*/ |
198
|
6 |
|
public function getUpdatedAt(): string |
199
|
|
|
{ |
200
|
6 |
|
return $this->updatedAt; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* @param string $updatedAt |
205
|
|
|
* |
206
|
|
|
* @return User |
207
|
|
|
*/ |
208
|
19 |
|
public function setUpdatedAt(string $updatedAt): self |
209
|
|
|
{ |
210
|
19 |
|
$this->updatedAt = $updatedAt; |
211
|
|
|
|
212
|
19 |
|
return $this; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @return array |
217
|
|
|
*/ |
218
|
20 |
|
public function getPermissions(): array |
219
|
|
|
{ |
220
|
20 |
|
return $this->permissions; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* @return array |
225
|
|
|
*/ |
226
|
20 |
|
public function getRoles(): array |
227
|
|
|
{ |
228
|
20 |
|
return $this->roles; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* @return array |
233
|
|
|
*/ |
234
|
19 |
|
public function getPermissionsIds(): array |
235
|
|
|
{ |
236
|
|
|
return array_map(static function (PermissionInterface $permission) { |
237
|
6 |
|
return $permission->getId(); |
238
|
19 |
|
}, $this->getPermissions()); |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* @return array |
243
|
|
|
*/ |
244
|
19 |
|
public function getRolesIds(): array |
245
|
|
|
{ |
246
|
|
|
return array_map(static function (RoleInterface $role) { |
247
|
6 |
|
return $role->getId(); |
248
|
19 |
|
}, $this->getRoles()); |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* @param AllUserInterface $all |
253
|
|
|
* |
254
|
|
|
* @throws \Illuminate\Contracts\Container\BindingResolutionException |
255
|
|
|
* |
256
|
|
|
* @return mixed |
257
|
|
|
*/ |
258
|
1 |
|
public static function all(AllUserInterface $all) |
259
|
|
|
{ |
260
|
1 |
|
return app()->make(AllUser::class)->make($all); |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* @param int $id |
265
|
|
|
* |
266
|
|
|
* @throws \Illuminate\Contracts\Container\BindingResolutionException |
267
|
|
|
* |
268
|
|
|
* @return User |
269
|
|
|
*/ |
270
|
3 |
|
public static function find(int $id): self |
271
|
|
|
{ |
272
|
3 |
|
return app()->make(FindOrFailUser::class)->make($id); |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* @throws \Illuminate\Contracts\Container\BindingResolutionException |
277
|
|
|
* |
278
|
|
|
* @return bool |
279
|
|
|
*/ |
280
|
19 |
|
public function save(): bool |
281
|
|
|
{ |
282
|
19 |
|
return app()->make(UpdateOrCreateUser::class)->make($this); |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
/** |
286
|
|
|
* @throws \Illuminate\Contracts\Container\BindingResolutionException |
287
|
|
|
* |
288
|
|
|
* @return bool |
289
|
|
|
*/ |
290
|
3 |
|
public function delete(): bool |
291
|
|
|
{ |
292
|
3 |
|
return app()->make(ExistsAndDeleteUser::class)->make($this); |
293
|
|
|
} |
294
|
|
|
} |
295
|
|
|
|