1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Limoncello\Passport\Adaptors\Generic; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Copyright 2015-2019 [email protected] |
7
|
|
|
* |
8
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
9
|
|
|
* you may not use this file except in compliance with the License. |
10
|
|
|
* You may obtain a copy of the License at |
11
|
|
|
* |
12
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
13
|
|
|
* |
14
|
|
|
* Unless required by applicable law or agreed to in writing, software |
15
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
16
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
17
|
|
|
* See the License for the specific language governing permissions and |
18
|
|
|
* limitations under the License. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
use Doctrine\DBAL\Connection; |
22
|
|
|
use Limoncello\Passport\Contracts\Entities\ClientInterface; |
23
|
|
|
use Limoncello\Passport\Contracts\Entities\DatabaseSchemaInterface; |
24
|
|
|
use Limoncello\Passport\Exceptions\RepositoryException; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @package Limoncello\Passport |
28
|
|
|
*/ |
29
|
|
|
class ClientRepository extends \Limoncello\Passport\Repositories\ClientRepository |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
private $modelClass; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param Connection $connection |
38
|
|
|
* @param DatabaseSchemaInterface $databaseSchema |
39
|
|
|
* @param string $modelClass |
40
|
|
|
*/ |
41
|
37 |
|
public function __construct( |
42
|
|
|
Connection $connection, |
43
|
|
|
DatabaseSchemaInterface $databaseSchema, |
44
|
|
|
string $modelClass = Client::class |
45
|
|
|
) { |
46
|
37 |
|
$this->setConnection($connection)->setDatabaseSchema($databaseSchema); |
47
|
37 |
|
$this->modelClass = $modelClass; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @inheritdoc |
52
|
|
|
* |
53
|
|
|
* @throws RepositoryException |
54
|
|
|
*/ |
55
|
2 |
|
public function index(): array |
56
|
|
|
{ |
57
|
|
|
/** @var Client[] $clients */ |
58
|
2 |
|
$clients = parent::index(); |
59
|
1 |
|
foreach ($clients as $client) { |
60
|
1 |
|
$this->addScopeAndRedirectUris($client); |
61
|
|
|
} |
62
|
|
|
|
63
|
1 |
|
return $clients; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @inheritdoc |
68
|
|
|
*/ |
69
|
18 |
|
public function read(string $identifier): ?ClientInterface |
70
|
|
|
{ |
71
|
|
|
/** @var Client|null $client */ |
72
|
18 |
|
$client = parent::read($identifier); |
73
|
|
|
|
74
|
17 |
|
if ($client !== null) { |
75
|
15 |
|
$this->addScopeAndRedirectUris($client); |
76
|
|
|
} |
77
|
|
|
|
78
|
17 |
|
return $client; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @inheritdoc |
83
|
|
|
*/ |
84
|
17 |
|
protected function getClassName(): string |
85
|
|
|
{ |
86
|
17 |
|
return $this->modelClass; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param Client $client |
91
|
|
|
* |
92
|
|
|
* @return void |
93
|
|
|
* |
94
|
|
|
* @throws RepositoryException |
95
|
|
|
*/ |
96
|
15 |
|
private function addScopeAndRedirectUris(Client $client): void |
97
|
|
|
{ |
98
|
15 |
|
$client->setScopeIdentifiers($this->readScopeIdentifiers($client->getIdentifier())); |
99
|
15 |
|
$client->setRedirectUriStrings($this->readRedirectUriStrings($client->getIdentifier())); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @inheritdoc |
104
|
|
|
*/ |
105
|
19 |
|
protected function getTableNameForReading(): string |
106
|
|
|
{ |
107
|
19 |
|
return $this->getTableNameForWriting(); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|