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 User\Domain\Model; |
15
|
|
|
|
16
|
|
|
use Core\Domain\Common\Model\VO\EmailField; |
17
|
|
|
use Core\Domain\Common\Model\VO\NameField; |
18
|
|
|
use Core\Domain\Common\Model\VO\ResourceUuid; |
19
|
|
|
use User\Domain\Model\VO\Password; |
20
|
|
|
|
21
|
|
|
class User |
22
|
|
|
{ |
23
|
|
|
private ResourceUuid $uuid; |
24
|
|
|
private NameField $username; |
25
|
|
|
private EmailField $email; |
26
|
|
|
private Password $password; |
27
|
|
|
private array $roles; |
28
|
|
|
|
29
|
|
|
public function __construct( |
30
|
|
|
ResourceUuid $uuid, |
31
|
|
|
NameField $username, |
32
|
|
|
EmailField $email, |
33
|
|
|
Password $password, |
34
|
|
|
array $roles = [] |
35
|
|
|
) { |
36
|
|
|
$this->uuid = $uuid; |
37
|
|
|
$this->username = $username; |
38
|
|
|
$this->email = $email; |
39
|
|
|
$this->password = $password; |
40
|
|
|
$this->roles = $roles; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public static function create( |
44
|
|
|
ResourceUuid $uuid, |
45
|
|
|
NameField $username, |
46
|
|
|
EmailField $email, |
47
|
|
|
Password $password, |
48
|
|
|
array $roles = [] |
49
|
|
|
): self { |
50
|
|
|
return new self($uuid, $username, $email, $password, $roles); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
final public function uuid(): ResourceUuid |
54
|
|
|
{ |
55
|
|
|
return $this->uuid; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
final public function username(): NameField |
59
|
|
|
{ |
60
|
|
|
return $this->username; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
final public function renameUser(NameField $username): self |
64
|
|
|
{ |
65
|
|
|
$this->username = $username; |
66
|
|
|
|
67
|
|
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
final public function email(): EmailField |
71
|
|
|
{ |
72
|
|
|
return $this->email; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
final public function changeEmail(EmailField $email): self |
76
|
|
|
{ |
77
|
|
|
$this->email = $email; |
78
|
|
|
|
79
|
|
|
return $this; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
final public function password(): Password |
83
|
|
|
{ |
84
|
|
|
return $this->password; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
final public function changePassword(Password $password): self |
88
|
|
|
{ |
89
|
|
|
$this->password = $password; |
90
|
|
|
|
91
|
|
|
return $this; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
final public function roles(): array |
95
|
|
|
{ |
96
|
|
|
if ([] === $this->roles) { |
97
|
|
|
$this->roles = ['ROLE_USER']; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
return $this->roles; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
final public function assignRoles(array $roles): self |
104
|
|
|
{ |
105
|
|
|
$this->roles = $roles; |
106
|
|
|
|
107
|
|
|
return $this; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|