|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SumoCoders\FrameworkMultiUserBundle\DataTransferObject; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
6
|
|
|
use Doctrine\Common\Collections\Collection; |
|
7
|
|
|
use SumoCoders\FrameworkMultiUserBundle\DataTransferObject\Interfaces\UserDataTransferObject; |
|
8
|
|
|
use SumoCoders\FrameworkMultiUserBundle\User\Interfaces\User; |
|
9
|
|
|
use SumoCoders\FrameworkMultiUserBundle\Entity\BaseUser; |
|
10
|
|
|
|
|
11
|
|
|
class BaseUserDataTransferObject implements UserDataTransferObject |
|
12
|
|
|
{ |
|
13
|
|
|
/** @var int|null */ |
|
14
|
|
|
public $id; |
|
15
|
|
|
|
|
16
|
|
|
/** @var string|null */ |
|
17
|
|
|
public $userName; |
|
18
|
|
|
|
|
19
|
|
|
/** @var string|null */ |
|
20
|
|
|
public $displayName; |
|
21
|
|
|
|
|
22
|
|
|
/** @var string|null */ |
|
23
|
|
|
public $email; |
|
24
|
|
|
|
|
25
|
|
|
/** @var string|null */ |
|
26
|
|
|
public $plainPassword; |
|
27
|
|
|
|
|
28
|
|
|
/** @var User */ |
|
29
|
|
|
protected $user; |
|
30
|
|
|
|
|
31
|
|
|
/** @var Collection|null */ |
|
32
|
|
|
public $roles; |
|
33
|
|
|
|
|
34
|
|
|
public static function fromUser(User $user): UserDataTransferObject |
|
35
|
|
|
{ |
|
36
|
|
|
$baseUserTransferObject = new static(); |
|
37
|
|
|
$baseUserTransferObject->user = $user; |
|
38
|
|
|
$baseUserTransferObject->id = $user->getId(); |
|
39
|
|
|
$baseUserTransferObject->userName = $user->getUsername(); |
|
40
|
|
|
$baseUserTransferObject->displayName = $user->getDisplayName(); |
|
41
|
|
|
$baseUserTransferObject->email = $user->getEmail(); |
|
42
|
|
|
$baseUserTransferObject->roles = $user->getRoles(); |
|
|
|
|
|
|
43
|
|
|
if ($user->hasPlainPassword()) { |
|
44
|
|
|
$baseUserTransferObject->plainPassword = $user->getPlainPassword(); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
return $baseUserTransferObject; |
|
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function getEntity(): User |
|
51
|
|
|
{ |
|
52
|
|
|
if ($this->user) { |
|
53
|
|
|
$this->user->change($this); |
|
54
|
|
|
|
|
55
|
|
|
return $this->user; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
return new BaseUser( |
|
59
|
|
|
$this->userName, |
|
60
|
|
|
$this->plainPassword, |
|
61
|
|
|
$this->displayName, |
|
62
|
|
|
$this->email, |
|
63
|
|
|
$this->roles instanceof Collection ? $this->roles : new ArrayCollection() |
|
64
|
|
|
); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function getId(): ?int |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->id; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function getUserName(): ?string |
|
73
|
|
|
{ |
|
74
|
|
|
return $this->userName; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function getDisplayName(): ?string |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->displayName; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function getEmail(): ?string |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->email; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function getPlainPassword(): ?string |
|
88
|
|
|
{ |
|
89
|
|
|
return $this->plainPassword; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function getRoles(): ?Collection |
|
93
|
|
|
{ |
|
94
|
|
|
return $this->roles; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..