1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* The MIT License (MIT) |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2014-2018 Spomky-Labs |
9
|
|
|
* |
10
|
|
|
* This software may be modified and distributed under the terms |
11
|
|
|
* of the MIT license. See the LICENSE file for details. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace OAuth2Framework\ServerBundle\Tests\TestBundle\Entity; |
15
|
|
|
|
16
|
|
|
use OAuth2Framework\Component\Core\ResourceOwner\ResourceOwnerId; |
17
|
|
|
use OAuth2Framework\Component\Core\UserAccount\UserAccount as UserAccountInterface; |
18
|
|
|
use OAuth2Framework\Component\Core\UserAccount\UserAccountId; |
19
|
|
|
use Symfony\Component\Security\Core\User\EquatableInterface; |
20
|
|
|
use Symfony\Component\Security\Core\User\UserInterface as SymfonyUserInterface; |
21
|
|
|
|
22
|
|
|
final class UserAccount implements UserAccountInterface, SymfonyUserInterface, EquatableInterface |
23
|
|
|
{ |
24
|
|
|
private $username; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string[] |
28
|
|
|
*/ |
29
|
|
|
private $roles; |
30
|
|
|
|
31
|
|
|
private $lastLoginAt; |
32
|
|
|
|
33
|
|
|
private $lastUpdateAt; |
34
|
|
|
|
35
|
|
|
private $userAccountId; |
36
|
|
|
|
37
|
|
|
private $data = []; |
38
|
|
|
|
39
|
|
|
public function __construct(UserAccountId $userAccountId, string $username, array $roles, ?\DateTimeImmutable $lastLoginAt, ?\DateTimeImmutable $lastUpdateAt, array $data) |
40
|
|
|
{ |
41
|
|
|
$this->userAccountId = $userAccountId; |
42
|
|
|
$this->username = $username; |
43
|
|
|
$this->roles = $roles; |
44
|
|
|
$this->lastLoginAt = $lastLoginAt; |
45
|
|
|
$this->lastUpdateAt = $lastUpdateAt; |
46
|
|
|
$this->data = $data; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function getUserAccountId(): UserAccountId |
50
|
|
|
{ |
51
|
|
|
return $this->userAccountId; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function getPublicId(): ResourceOwnerId |
55
|
|
|
{ |
56
|
|
|
return $this->userAccountId; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function has(string $key): bool |
60
|
|
|
{ |
61
|
|
|
return array_key_exists($key, $this->data); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function get(string $key) |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
if (!$this->has($key)) { |
67
|
|
|
throw new \InvalidArgumentException(\Safe\sprintf('The user account parameter "%s" does not exist.', $key)); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return $this->data[$key]; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function getLastLoginAt(): ?int |
|
|
|
|
74
|
|
|
{ |
75
|
|
|
return $this->lastLoginAt ? $this->lastLoginAt->getTimestamp() : null; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function getLastUpdateAt(): ?int |
|
|
|
|
79
|
|
|
{ |
80
|
|
|
return $this->lastUpdateAt ? $this->lastUpdateAt->getTimestamp() : null; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function getRoles(): array |
84
|
|
|
{ |
85
|
|
|
return $this->roles; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function getSalt() |
89
|
|
|
{ |
90
|
|
|
return; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function getUsername(): string |
94
|
|
|
{ |
95
|
|
|
return $this->username; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function getPassword(): string |
99
|
|
|
{ |
100
|
|
|
return ''; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function eraseCredentials() |
104
|
|
|
{ |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function isEqualTo(SymfonyUserInterface $user) |
108
|
|
|
{ |
109
|
|
|
if (!$user instanceof self) { |
110
|
|
|
return false; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
if ($this->username !== $user->getUsername()) { |
|
|
|
|
114
|
|
|
return false; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
return true; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.