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 | /** |
||
32 | * @ORM\Column(type="string", length=255, unique=true) |
||
33 | * @Assert\NotBlank() |
||
34 | * @Assert\Email() |
||
35 | */ |
||
36 | public $email; |
||
37 | |||
38 | /** |
||
39 | * @ORM\Column(type="string", length=255, unique=true) |
||
40 | * @Assert\NotBlank() |
||
41 | */ |
||
42 | public $username; |
||
43 | |||
44 | /** |
||
45 | * @ORM\Column(type="string", length=255, nullable=true) |
||
46 | */ |
||
47 | public $roles; |
||
48 | |||
49 | /** |
||
50 | * @Exclude |
||
51 | * @Assert\NotBlank() |
||
52 | * @Assert\Length(max=4096) |
||
53 | */ |
||
54 | public $plainPassword; |
||
55 | |||
56 | /** |
||
57 | * @Exclude |
||
58 | * @ORM\Column(type="string", length=64) |
||
59 | */ |
||
60 | private $password; |
||
61 | |||
62 | 10 | public function __construct() |
|
66 | |||
67 | 1 | public function getId(): ?int |
|
71 | |||
72 | 10 | public function addRole(string $role): self |
|
73 | { |
||
74 | 10 | if (array_search($role, $this->getRoles()) === false) { |
|
75 | 3 | return $this->setRoles( |
|
76 | 3 | array_merge($this->getRoles(), [$role]) |
|
77 | ); |
||
78 | } |
||
79 | |||
80 | 10 | return $this; |
|
81 | } |
||
82 | |||
83 | 1 | public function removeRole(string $role): self |
|
95 | |||
96 | 3 | private function setRoles(array $roles): self |
|
97 | { |
||
98 | 3 | if (!count($roles)) { |
|
99 | 1 | $this->roles = null; |
|
100 | 1 | return $this; |
|
101 | } |
||
102 | |||
103 | 3 | $this->roles = json_encode($roles); |
|
104 | |||
105 | 3 | return $this; |
|
106 | } |
||
107 | |||
108 | 10 | public function getRoles(): array |
|
122 | |||
123 | 10 | private function getDefaultRoles() |
|
127 | |||
128 | 2 | public function setPassword($password, UserPasswordEncoderInterface $passwordEncoder): self |
|
135 | |||
136 | 1 | public function isPasswordValid($password, UserPasswordEncoderInterface $passwordEncoder): bool |
|
140 | |||
141 | 1 | public function getPassword(): ?string |
|
145 | |||
146 | 3 | public function getSalt(): ?string |
|
150 | |||
151 | 3 | public function getUsername(): ?string |
|
155 | |||
156 | 1 | public function eraseCredentials(): self |
|
162 | |||
163 | // todo remove apiKey from 2 methods below |
||
164 | 1 | public function serialize(): string |
|
173 | |||
174 | 1 | public function unserialize($serialized): self |
|
185 | } |