|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Starkerxp\UserBundle\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
6
|
|
|
use Lexik\Bundle\JWTAuthenticationBundle\Security\User\JWTUserInterface; |
|
7
|
|
|
use Ramsey\Uuid\Uuid; |
|
8
|
|
|
use Starkerxp\StructureBundle\Entity\Entity; |
|
9
|
|
|
use Starkerxp\StructureBundle\Entity\UserInterface; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* User |
|
13
|
|
|
* |
|
14
|
|
|
* @ORM\Table(name="user", indexes={ |
|
15
|
|
|
* @ORM\Index(columns={"created_at"}), |
|
16
|
|
|
* @ORM\Index(columns={"updated_at"}) |
|
17
|
|
|
* }) |
|
18
|
|
|
* @ORM\Entity(repositoryClass="Starkerxp\UserBundle\Repository\UserRepository") |
|
19
|
|
|
*/ |
|
20
|
|
|
class User extends Entity implements JWTUserInterface, UserInterface |
|
21
|
|
|
{ |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var RoleUser |
|
25
|
|
|
* |
|
26
|
|
|
* @ORM\OneToOne(targetEntity="RoleUser", cascade={"persist"}) |
|
27
|
|
|
* @ORM\JoinColumn(name="roles", referencedColumnName="id", nullable=true) |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $roles; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var string |
|
33
|
|
|
* |
|
34
|
|
|
* @ORM\Column(name="salt", type="string", length=255, nullable=true) |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $salt; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var string |
|
40
|
|
|
* |
|
41
|
|
|
* @ORM\Column(name="password", type="string", length=255) |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $password; |
|
44
|
|
|
protected $plainPassword; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @var string |
|
48
|
|
|
* |
|
49
|
|
|
* @ORM\Column(name="email", type="string", length=255, nullable=false, unique=true) |
|
50
|
|
|
*/ |
|
51
|
|
|
protected $email; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* User constructor. |
|
55
|
|
|
* @param array $roles |
|
56
|
|
|
* @param string $email |
|
57
|
|
|
*/ |
|
58
|
|
|
public function __construct($email, $roles) |
|
59
|
|
|
{ |
|
60
|
|
|
$this->email = $email; |
|
61
|
|
|
$this->setRoles($roles); |
|
62
|
|
|
$uuid = Uuid::uuid4(); |
|
63
|
|
|
$this->salt = $uuid->toString(); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public static function createFromPayload($username, array $payload) |
|
67
|
|
|
{ |
|
68
|
|
|
return new self( |
|
69
|
|
|
$username, |
|
70
|
|
|
$payload['roles'] |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function getRoles() |
|
75
|
|
|
{ |
|
76
|
|
|
/** @var \Starkerxp\UserBundle\Entity\RoleUser $roles */ |
|
77
|
|
|
if (empty($this->roles)) { |
|
78
|
|
|
return null; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
return $this->roles->getRole(); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @param array $roles |
|
86
|
|
|
* |
|
87
|
|
|
* @return bool |
|
88
|
|
|
*/ |
|
89
|
|
|
public function setRoles($roles) |
|
90
|
|
|
{ |
|
91
|
|
|
if($roles instanceof RoleUser || empty($this->roles) ){ |
|
|
|
|
|
|
92
|
|
|
$this->roles = new RoleUser($roles); |
|
93
|
|
|
return true; |
|
94
|
|
|
} |
|
95
|
|
|
$this->roles->setRoles($roles); |
|
96
|
|
|
|
|
97
|
|
|
return true; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function getPassword() |
|
101
|
|
|
{ |
|
102
|
|
|
return $this->password; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @param string $password |
|
107
|
|
|
*/ |
|
108
|
|
|
public function setPassword($password) |
|
109
|
|
|
{ |
|
110
|
|
|
$this->password = $password; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
public function getSalt() |
|
114
|
|
|
{ |
|
115
|
|
|
return $this->salt; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
public function getUsername() |
|
119
|
|
|
{ |
|
120
|
|
|
return $this->email; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
public function eraseCredentials() |
|
124
|
|
|
{ |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @param string $email |
|
130
|
|
|
*/ |
|
131
|
|
|
public function setEmail($email) |
|
132
|
|
|
{ |
|
133
|
|
|
$this->email = $email; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* @return mixed |
|
138
|
|
|
*/ |
|
139
|
|
|
public function getPlainPassword() |
|
140
|
|
|
{ |
|
141
|
|
|
return $this->plainPassword; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* @param mixed $plainPassword |
|
146
|
|
|
*/ |
|
147
|
|
|
public function setPlainPassword($plainPassword) |
|
148
|
|
|
{ |
|
149
|
|
|
$this->plainPassword = $plainPassword; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
|
|
153
|
|
|
} |
|
|
|
|
|
|
154
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.