|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* The MIT License (MIT) |
|
7
|
|
|
* |
|
8
|
|
|
* Copyright (c) 2014-2019 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\Repository; |
|
15
|
|
|
|
|
16
|
|
|
use OAuth2Framework\Component\Core\UserAccount\UserAccount as BaseUserAccount; |
|
17
|
|
|
use OAuth2Framework\Component\Core\UserAccount\UserAccountId; |
|
18
|
|
|
use OAuth2Framework\Component\Core\UserAccount\UserAccountRepository as UserAccountRepositoryInterface; |
|
19
|
|
|
use OAuth2Framework\ServerBundle\Tests\TestBundle\Entity\UserAccount; |
|
20
|
|
|
|
|
21
|
|
|
final class UserAccountRepository implements UserAccountRepositoryInterface |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @var UserAccount[] |
|
25
|
|
|
*/ |
|
26
|
|
|
private $userAccounts = []; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var UserAccount[] |
|
30
|
|
|
*/ |
|
31
|
|
|
private $usernames = []; |
|
32
|
|
|
|
|
33
|
|
|
public function __construct() |
|
34
|
|
|
{ |
|
35
|
|
|
foreach ($this->getUsers() as $data) { |
|
36
|
|
|
$userAccount = new UserAccount( |
|
37
|
|
|
new UserAccountId($data['id']), |
|
38
|
|
|
$data['username'], |
|
39
|
|
|
$data['roles'], |
|
40
|
|
|
$data['last_login_at'], |
|
41
|
|
|
$data['last_update_at'], |
|
42
|
|
|
$data['parameters'] |
|
43
|
|
|
); |
|
44
|
|
|
$this->userAccounts[$data['id']] = $userAccount; |
|
45
|
|
|
$this->usernames[$data['username']] = $userAccount; |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function find(UserAccountId $publicId): ?BaseUserAccount |
|
50
|
|
|
{ |
|
51
|
|
|
return \array_key_exists($publicId->getValue(), $this->userAccounts) ? $this->userAccounts[$publicId->getValue()] : null; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function findOneByUsername(string $username): ?BaseUserAccount |
|
55
|
|
|
{ |
|
56
|
|
|
return \array_key_exists($username, $this->usernames) ? $this->usernames[$username] : null; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
private function getUsers(): array |
|
60
|
|
|
{ |
|
61
|
|
|
return [ |
|
62
|
|
|
[ |
|
63
|
|
|
'username' => 'admin', |
|
64
|
|
|
'roles' => ['ROLE_ADMIN', 'ROLE_USER'], |
|
65
|
|
|
'last_login_at' => new \DateTimeImmutable('now -25 hours'), |
|
66
|
|
|
'last_update_at' => new \DateTimeImmutable('now -15 days'), |
|
67
|
|
|
'id' => 'john.1', |
|
68
|
|
|
'parameters' => [ |
|
69
|
|
|
'address', [ |
|
70
|
|
|
'street_address' => '5 rue Sainte Anne', |
|
71
|
|
|
'region' => 'Île de France', |
|
72
|
|
|
'postal_code' => '75001', |
|
73
|
|
|
'locality' => 'Paris', |
|
74
|
|
|
'country' => 'France', |
|
75
|
|
|
], |
|
76
|
|
|
'name' => 'John Doe', |
|
77
|
|
|
'given_name' => 'John', |
|
78
|
|
|
'family_name' => 'Doe', |
|
79
|
|
|
'middle_name' => 'Jack', |
|
80
|
|
|
'nickname' => 'Little John', |
|
81
|
|
|
'profile' => 'https://profile.doe.fr/john/', |
|
82
|
|
|
'preferred_username' => 'j-d', |
|
83
|
|
|
'gender' => 'M', |
|
84
|
|
|
'phone_number' => '+0123456789', |
|
85
|
|
|
'phone_number_verified' => true, |
|
86
|
|
|
'zoneinfo' => 'Europe/Paris', |
|
87
|
|
|
'locale' => 'en', |
|
88
|
|
|
'picture' => 'https://www.google.com', |
|
89
|
|
|
'birthdate' => '1950-01-01', |
|
90
|
|
|
'email' => '[email protected]', |
|
91
|
|
|
'email_verified' => false, |
|
92
|
|
|
'website' => 'https://john.doe.com', |
|
93
|
|
|
'website#fr_fr' => 'https://john.doe.fr', |
|
94
|
|
|
'website#fr' => 'https://john.doe.fr', |
|
95
|
|
|
'picture#de' => 'https://john.doe.de/picture', |
|
96
|
|
|
], |
|
97
|
|
|
], |
|
98
|
|
|
]; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|