1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the G.L.S.R. Apps package. |
7
|
|
|
* |
8
|
|
|
* (c) Dev-Int Création <[email protected]>. |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Administration\Domain\User\Model; |
15
|
|
|
|
16
|
|
|
use Administration\Domain\User\Model\VO\UserUuid; |
17
|
|
|
use Core\Domain\Common\Model\VO\EmailField; |
18
|
|
|
use Core\Domain\Common\Model\VO\NameField; |
19
|
|
|
|
20
|
|
|
final class User |
21
|
|
|
{ |
22
|
|
|
private string $uuid; |
23
|
|
|
private string $username; |
24
|
|
|
private string $email; |
25
|
|
|
private string $password; |
26
|
|
|
private array $roles; |
27
|
|
|
|
28
|
|
|
public function __construct( |
29
|
|
|
UserUuid $uuid, |
30
|
|
|
NameField $username, |
31
|
|
|
EmailField $email, |
32
|
|
|
string $password, |
33
|
|
|
array $roles = [] |
34
|
|
|
) { |
35
|
|
|
$this->uuid = $uuid->toString(); |
36
|
|
|
$this->username = $username->getValue(); |
37
|
|
|
$this->email = $email->getValue(); |
38
|
|
|
$this->password = $password; |
39
|
|
|
$this->roles = $roles; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public static function create( |
43
|
|
|
UserUuid $uuid, |
44
|
|
|
NameField $username, |
45
|
|
|
EmailField $email, |
46
|
|
|
string $password, |
47
|
|
|
array $roles = [] |
48
|
|
|
): self { |
49
|
|
|
return new self($uuid, $username, $email, $password, $roles); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function uuid(): string |
53
|
|
|
{ |
54
|
|
|
return $this->uuid; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function username(): string |
58
|
|
|
{ |
59
|
|
|
return $this->username; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function renameUser(NameField $username): self |
63
|
|
|
{ |
64
|
|
|
$this->username = $username->getValue(); |
65
|
|
|
|
66
|
|
|
return $this; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function email(): string |
70
|
|
|
{ |
71
|
|
|
return $this->email; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function changeEmail(EmailField $email): self |
75
|
|
|
{ |
76
|
|
|
$this->email = $email->getValue(); |
77
|
|
|
|
78
|
|
|
return $this; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function password(): string |
82
|
|
|
{ |
83
|
|
|
return $this->password; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function changePassword(string $password): self |
87
|
|
|
{ |
88
|
|
|
$this->password = $password; |
89
|
|
|
|
90
|
|
|
return $this; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function roles(): array |
94
|
|
|
{ |
95
|
|
|
return $this->roles; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function assignRoles(array $roles): self |
99
|
|
|
{ |
100
|
|
|
$this->roles = $roles; |
101
|
|
|
|
102
|
|
|
return $this; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|