1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Limoncello\Passport\Repositories; |
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 DateTimeImmutable; |
22
|
|
|
use Limoncello\Passport\Contracts\Entities\ScopeInterface; |
23
|
|
|
use Limoncello\Passport\Contracts\Repositories\ScopeRepositoryInterface; |
24
|
|
|
use Limoncello\Passport\Exceptions\RepositoryException; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @package Limoncello\Passport |
28
|
|
|
*/ |
29
|
|
|
abstract class ScopeRepository extends BaseRepository implements ScopeRepositoryInterface |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* @inheritdoc |
33
|
|
|
* |
34
|
|
|
* @throws RepositoryException |
35
|
|
|
*/ |
36
|
2 |
|
public function index(): array |
37
|
|
|
{ |
38
|
|
|
try { |
39
|
2 |
|
return parent::indexResources(); |
|
|
|
|
40
|
1 |
|
} catch (RepositoryException $exception) { |
41
|
1 |
|
$message = 'Reading scopes failed.'; |
42
|
1 |
|
throw new RepositoryException($message, 0, $exception); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @inheritdoc |
48
|
|
|
* |
49
|
|
|
* @throws RepositoryException |
50
|
|
|
*/ |
51
|
20 |
View Code Duplication |
public function create(ScopeInterface $scope): ScopeInterface |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
try { |
54
|
|
|
$now = $this->ignoreException(function (): DateTimeImmutable { |
55
|
20 |
|
return new DateTimeImmutable(); |
56
|
20 |
|
}); |
57
|
20 |
|
$schema = $this->getDatabaseSchema(); |
58
|
20 |
|
$this->createResource([ |
|
|
|
|
59
|
20 |
|
$schema->getScopesIdentityColumn() => $scope->getIdentifier(), |
60
|
20 |
|
$schema->getScopesDescriptionColumn() => $scope->getDescription(), |
61
|
20 |
|
$schema->getScopesCreatedAtColumn() => $now, |
62
|
|
|
]); |
63
|
|
|
|
64
|
19 |
|
$scope->setCreatedAt($now); |
65
|
|
|
|
66
|
19 |
|
return $scope; |
67
|
1 |
|
} catch (RepositoryException $exception) { |
68
|
1 |
|
$message = 'Scope creation failed.'; |
69
|
1 |
|
throw new RepositoryException($message, 0, $exception); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @inheritdoc |
75
|
|
|
* |
76
|
|
|
* @throws RepositoryException |
77
|
|
|
*/ |
78
|
2 |
View Code Duplication |
public function read(string $identifier): ScopeInterface |
|
|
|
|
79
|
|
|
{ |
80
|
|
|
try { |
81
|
2 |
|
return $this->readResource($identifier); |
82
|
1 |
|
} catch (RepositoryException $exception) { |
83
|
1 |
|
$message = 'Scope reading failed.'; |
84
|
1 |
|
throw new RepositoryException($message, 0, $exception); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @inheritdoc |
90
|
|
|
* |
91
|
|
|
* @throws RepositoryException |
92
|
|
|
*/ |
93
|
2 |
View Code Duplication |
public function update(ScopeInterface $scope): void |
|
|
|
|
94
|
|
|
{ |
95
|
|
|
try { |
96
|
|
|
$now = $this->ignoreException(function (): DateTimeImmutable { |
97
|
2 |
|
return new DateTimeImmutable(); |
98
|
2 |
|
}); |
99
|
2 |
|
$schema = $this->getDatabaseSchema(); |
100
|
2 |
|
$this->updateResource($scope->getIdentifier(), [ |
101
|
2 |
|
$schema->getScopesDescriptionColumn() => $scope->getDescription(), |
102
|
2 |
|
$schema->getScopesUpdatedAtColumn() => $now, |
103
|
|
|
]); |
104
|
1 |
|
$scope->setUpdatedAt($now); |
105
|
1 |
|
} catch (RepositoryException $exception) { |
106
|
1 |
|
$message = 'Scope update failed.'; |
107
|
1 |
|
throw new RepositoryException($message, 0, $exception); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @inheritdoc |
113
|
|
|
* |
114
|
|
|
* @throws RepositoryException |
115
|
|
|
*/ |
116
|
2 |
View Code Duplication |
public function delete(string $identifier): void |
|
|
|
|
117
|
|
|
{ |
118
|
|
|
try { |
119
|
2 |
|
$this->deleteResource($identifier); |
120
|
1 |
|
} catch (RepositoryException $exception) { |
121
|
1 |
|
$message = 'Scope deletion failed.'; |
122
|
1 |
|
throw new RepositoryException($message, 0, $exception); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @inheritdoc |
128
|
|
|
*/ |
129
|
26 |
|
protected function getTableNameForWriting(): string |
130
|
|
|
{ |
131
|
26 |
|
return $this->getDatabaseSchema()->getScopesTable(); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @inheritdoc |
136
|
|
|
*/ |
137
|
4 |
|
protected function getPrimaryKeyName(): string |
138
|
|
|
{ |
139
|
4 |
|
return $this->getDatabaseSchema()->getScopesIdentityColumn(); |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.