1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace VSV\GVQ_API\User\Repositories\Entities; |
4
|
|
|
|
5
|
|
|
use Ramsey\Uuid\Uuid; |
6
|
|
|
use VSV\GVQ_API\Common\Repositories\Entities\Entity; |
7
|
|
|
use Doctrine\ORM\Mapping as ORM; |
8
|
|
|
use VSV\GVQ_API\Common\ValueObjects\NotEmptyString; |
9
|
|
|
use VSV\GVQ_API\User\Models\User; |
10
|
|
|
use VSV\GVQ_API\User\ValueObjects\Email; |
11
|
|
|
use VSV\GVQ_API\User\ValueObjects\Password; |
12
|
|
|
use VSV\GVQ_API\User\ValueObjects\Role; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @ORM\Entity() |
16
|
|
|
* @ORM\Table(name="user") |
17
|
|
|
*/ |
18
|
|
|
class UserEntity extends Entity |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var string |
22
|
|
|
* |
23
|
|
|
* @ORM\Column(type="string", length=255, nullable=false) |
24
|
|
|
*/ |
25
|
|
|
private $email; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var string |
29
|
|
|
* |
30
|
|
|
* @ORM\Column(type="string", length=255, nullable=false) |
31
|
|
|
*/ |
32
|
|
|
private $password; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string |
36
|
|
|
* |
37
|
|
|
* @ORM\Column(type="string", length=255, nullable=false) |
38
|
|
|
*/ |
39
|
|
|
private $lastName; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var string |
43
|
|
|
* |
44
|
|
|
* @ORM\Column(type="string", length=255, nullable=false) |
45
|
|
|
*/ |
46
|
|
|
private $firstName; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var string |
50
|
|
|
* |
51
|
|
|
* @ORM\Column(type="string", length=20, nullable=false) |
52
|
|
|
*/ |
53
|
|
|
private $role; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param string $id |
57
|
|
|
* @param string $email |
58
|
|
|
* @param string $password |
59
|
|
|
* @param string $lastName |
60
|
|
|
* @param string $firstName |
61
|
|
|
* @param string $role |
62
|
|
|
*/ |
63
|
|
|
public function __construct( |
64
|
|
|
string $id, |
65
|
|
|
string $email, |
66
|
|
|
string $password, |
67
|
|
|
string $lastName, |
68
|
|
|
string $firstName, |
69
|
|
|
string $role |
70
|
|
|
) { |
71
|
|
|
parent::__construct($id); |
72
|
|
|
|
73
|
|
|
$this->email = $email; |
74
|
|
|
$this->password = $password; |
75
|
|
|
$this->lastName = $lastName; |
76
|
|
|
$this->firstName = $firstName; |
77
|
|
|
$this->role = $role; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param User $user |
82
|
|
|
* @return UserEntity |
83
|
|
|
*/ |
84
|
|
|
public static function fromUser(User $user): UserEntity |
85
|
|
|
{ |
86
|
|
|
return new UserEntity( |
87
|
|
|
$user->getId()->toString(), |
88
|
|
|
$user->getEmail()->toNative(), |
89
|
|
|
$user->getPassword()->toNative(), |
90
|
|
|
$user->getLastName()->toNative(), |
91
|
|
|
$user->getFirstName()->toNative(), |
92
|
|
|
$user->getRole()->toNative() |
93
|
|
|
); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return User |
98
|
|
|
*/ |
99
|
|
|
public function toUser(): User |
100
|
|
|
{ |
101
|
|
|
return new User( |
102
|
|
|
Uuid::fromString($this->getId()), |
103
|
|
|
new Email($this->getEmail()), |
104
|
|
|
Password::fromHash($this->getPassword()), |
105
|
|
|
new NotEmptyString($this->getLastName()), |
106
|
|
|
new NotEmptyString($this->getFirstName()), |
107
|
|
|
new Role($this->getRole()) |
108
|
|
|
); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return string |
113
|
|
|
*/ |
114
|
|
|
public function getEmail(): string |
115
|
|
|
{ |
116
|
|
|
return $this->email; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @return string |
121
|
|
|
*/ |
122
|
|
|
public function getPassword(): string |
123
|
|
|
{ |
124
|
|
|
return $this->password; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @return string |
129
|
|
|
*/ |
130
|
|
|
public function getLastName(): string |
131
|
|
|
{ |
132
|
|
|
return $this->lastName; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @return string |
137
|
|
|
*/ |
138
|
|
|
public function getFirstName(): string |
139
|
|
|
{ |
140
|
|
|
return $this->firstName; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @return string |
145
|
|
|
*/ |
146
|
|
|
public function getRole(): string |
147
|
|
|
{ |
148
|
|
|
return $this->role; |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|