1 | <?php |
||
20 | class User implements UserInterface, \Serializable |
||
21 | { |
||
22 | const ROLE_USER = 'ROLE_USER'; |
||
23 | |||
24 | /** |
||
25 | * @ORM\Id() |
||
26 | * @ORM\GeneratedValue() |
||
27 | * @ORM\Column(type="integer") |
||
28 | */ |
||
29 | private $id; |
||
30 | |||
31 | #private $tokens; |
||
32 | |||
33 | /** |
||
34 | * @var $profile UserProfile |
||
35 | * @ORM\OneToOne(targetEntity="App\Entity\UserProfile", cascade={"persist", "remove"}) |
||
36 | */ |
||
37 | private $profile; |
||
38 | |||
39 | /** |
||
40 | * @ORM\Column(type="string", length=255, unique=true) |
||
41 | */ |
||
42 | public $email; |
||
43 | |||
44 | /** |
||
45 | * @ORM\Column(type="integer", length=1) |
||
46 | */ |
||
47 | private $isEmailConfirmed; |
||
48 | |||
49 | /** |
||
50 | * @ORM\Column(type="string", length=255, unique=true) |
||
51 | */ |
||
52 | public $username; |
||
53 | |||
54 | /** |
||
55 | * @ORM\Column(type="string", length=255, nullable=true) |
||
56 | */ |
||
57 | private $roles; |
||
58 | |||
59 | /** |
||
60 | * @Exclude |
||
61 | */ |
||
62 | private $plainPassword; |
||
63 | |||
64 | /** |
||
65 | * @Exclude |
||
66 | * @ORM\Column(type="string", length=64) |
||
67 | */ |
||
68 | private $password; |
||
69 | |||
70 | 31 | public function __construct() |
|
76 | |||
77 | 8 | public function getProfile(): UserProfile |
|
81 | |||
82 | 4 | public function getId(): ?int |
|
86 | |||
87 | 31 | public function addRole(string $role): self |
|
88 | { |
||
89 | 31 | if (array_search($role, $this->getRoles()) === false) { |
|
90 | 3 | return $this->setRoles( |
|
91 | 3 | array_merge($this->getRoles(), [$role]) |
|
92 | ); |
||
93 | } |
||
94 | |||
95 | 31 | return $this; |
|
96 | } |
||
97 | |||
98 | 1 | public function removeRole(string $role): self |
|
110 | |||
111 | 3 | private function setRoles(array $roles): self |
|
112 | { |
||
113 | 3 | if (!count($roles)) { |
|
114 | 1 | $this->roles = null; |
|
115 | 1 | return $this; |
|
116 | } |
||
117 | |||
118 | 3 | $this->roles = json_encode($roles); |
|
119 | |||
120 | 3 | return $this; |
|
121 | } |
||
122 | |||
123 | 32 | public function getRoles(): array |
|
137 | |||
138 | 32 | private function getDefaultRoles() |
|
142 | |||
143 | 5 | public function setPlainPassword(string $plainPassword): self |
|
153 | |||
154 | 7 | public function getPlainPassword(): string |
|
158 | |||
159 | 9 | public function setPassword($password, UserPasswordEncoderInterface $passwordEncoder): self |
|
165 | |||
166 | 6 | public function isPasswordValid($password, UserPasswordEncoderInterface $passwordEncoder): bool |
|
170 | |||
171 | 4 | public function getPassword(): ?string |
|
175 | |||
176 | 11 | public function getSalt(): ?string |
|
180 | |||
181 | 3 | public function getUsername(): ?string |
|
185 | |||
186 | 7 | public function eraseCredentials(): self |
|
192 | |||
193 | 1 | public function serialize(): string |
|
202 | |||
203 | 1 | public function unserialize($serialized): self |
|
214 | |||
215 | 1 | public function confirmEmail() |
|
221 | |||
222 | public function changeEmail($email) |
||
229 | } |