1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the EOffice project. |
5
|
|
|
* |
6
|
|
|
* (c) Anthonius Munthi <https://itstoni.com> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace EOffice\User\Model; |
15
|
|
|
|
16
|
|
|
use EOffice\Contracts\User\Model\UserInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @psalm-suppress MixedReturnTypeCoercion |
20
|
|
|
* @psalm-suppress PropertyNotSetInConstructor |
21
|
|
|
*/ |
22
|
|
|
class User implements UserInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
* @psalm-suppress PropertyNotSetInConstructor |
27
|
|
|
*/ |
28
|
|
|
protected string $id; |
29
|
|
|
protected string $username; |
30
|
|
|
protected string $email; |
31
|
|
|
protected string $password; |
32
|
|
|
protected ?string $salt = null; |
33
|
|
|
protected array $roles; |
34
|
|
|
protected bool $enabled = true; |
35
|
|
|
protected ?string $plainPassword = null; |
36
|
|
|
protected ?\DateTimeInterface $createdAt = null; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param string $username |
40
|
|
|
* @param string $email |
41
|
|
|
* @param string|null $plainPassword |
42
|
|
|
* @param array $roles |
43
|
|
|
* @param bool $enabled |
44
|
|
|
*/ |
45
|
|
|
public function __construct( |
46
|
|
|
string $username, |
47
|
|
|
string $email, |
48
|
|
|
?string $plainPassword = null, |
49
|
|
|
array $roles = [], |
50
|
|
|
bool $enabled = true |
51
|
|
|
) { |
52
|
|
|
$this->username = $username; |
53
|
|
|
$this->email = $email; |
54
|
|
|
$this->plainPassword = $plainPassword; |
55
|
|
|
$this->roles = $roles; |
56
|
|
|
$this->enabled = $enabled; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return \DateTimeInterface|null |
61
|
|
|
*/ |
62
|
|
|
public function getCreatedAt(): ?\DateTimeInterface |
63
|
|
|
{ |
64
|
|
|
return $this->createdAt; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param \DateTimeInterface|null $createdAt |
69
|
|
|
*/ |
70
|
|
|
public function setCreatedAt(?\DateTimeInterface $createdAt): void |
71
|
|
|
{ |
72
|
|
|
$this->createdAt = $createdAt; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param string $username |
77
|
|
|
*/ |
78
|
|
|
public function setUsername(string $username): void |
79
|
|
|
{ |
80
|
|
|
$this->username = $username; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param string $email |
85
|
|
|
*/ |
86
|
|
|
public function setEmail(string $email): void |
87
|
|
|
{ |
88
|
|
|
$this->email = $email; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param string|null $salt |
93
|
|
|
*/ |
94
|
|
|
public function setSalt(?string $salt): void |
95
|
|
|
{ |
96
|
|
|
$this->salt = $salt; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param array $roles |
101
|
|
|
*/ |
102
|
|
|
public function setRoles(array $roles): void |
103
|
|
|
{ |
104
|
|
|
$this->roles = $roles; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @param bool $enabled |
109
|
|
|
*/ |
110
|
|
|
public function setEnabled(bool $enabled): void |
111
|
|
|
{ |
112
|
|
|
$this->enabled = $enabled; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param string|null $plainPassword |
117
|
|
|
*/ |
118
|
|
|
public function setPlainPassword(?string $plainPassword): void |
119
|
|
|
{ |
120
|
|
|
$this->plainPassword = $plainPassword; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @return string[] |
125
|
|
|
*/ |
126
|
|
|
public function getRoles() |
127
|
|
|
{ |
128
|
|
|
$roles = $this->roles; |
129
|
|
|
$roles[] = 'ROLE_USER'; |
130
|
|
|
|
131
|
|
|
return array_unique($roles); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function getPassword(): string |
135
|
|
|
{ |
136
|
|
|
return $this->password; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function getSalt(): ?string |
140
|
|
|
{ |
141
|
|
|
return $this->salt; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function eraseCredentials(): void |
145
|
|
|
{ |
146
|
|
|
// TODO: Implement eraseCredentials() method. |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public function getPlainPassword(): ?string |
150
|
|
|
{ |
151
|
|
|
return $this->plainPassword; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function setPassword(string $password): void |
155
|
|
|
{ |
156
|
|
|
$this->password = $password; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @return string |
161
|
|
|
*/ |
162
|
|
|
public function getId(): string |
163
|
|
|
{ |
164
|
|
|
return $this->id; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @return string |
169
|
|
|
*/ |
170
|
|
|
public function getUsername(): string |
171
|
|
|
{ |
172
|
|
|
return $this->username; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @return string |
177
|
|
|
*/ |
178
|
|
|
public function getEmail(): string |
179
|
|
|
{ |
180
|
|
|
return $this->email; |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|