1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Lookyman\NetteOAuth2Server\Storage\Doctrine\Scope; |
5
|
|
|
|
6
|
|
|
use Kdyby\Doctrine\InvalidStateException; |
7
|
|
|
use Kdyby\Doctrine\QueryException; |
8
|
|
|
use Kdyby\Doctrine\Registry; |
9
|
|
|
use League\OAuth2\Server\Entities\ClientEntityInterface; |
10
|
|
|
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface; |
11
|
|
|
|
12
|
|
|
class ScopeRepository implements ScopeRepositoryInterface |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var Registry |
16
|
|
|
*/ |
17
|
|
|
private $registry; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var callable |
21
|
|
|
*/ |
22
|
|
|
private $scopeFinalizer; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param Registry $registry |
26
|
|
|
* @param callable|null $scopeFinalizer |
27
|
|
|
*/ |
28
|
|
|
public function __construct(Registry $registry, callable $scopeFinalizer = null) |
29
|
|
|
{ |
30
|
|
|
$this->registry = $registry; |
31
|
|
|
$this->scopeFinalizer = $scopeFinalizer ?: function (array $scopes) { return $scopes; }; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param string $identifier |
36
|
|
|
* @return ScopeEntity|null |
37
|
|
|
* @throws InvalidStateException |
38
|
|
|
* @throws QueryException |
39
|
|
|
*/ |
40
|
|
|
public function getScopeEntityByIdentifier($identifier) |
41
|
|
|
{ |
42
|
|
|
return $this->registry->getManager()->getRepository(ScopeEntity::class)->fetchOne($this->createQuery()->byIdentifier($identifier)); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param ScopeEntity[] $scopes |
47
|
|
|
* @param string $grantType |
48
|
|
|
* @param ClientEntityInterface $clientEntity |
49
|
|
|
* @param string|null $userIdentifier |
50
|
|
|
* @return ScopeEntity[] |
51
|
|
|
*/ |
52
|
|
|
public function finalizeScopes( |
53
|
|
|
array $scopes, |
54
|
|
|
$grantType, |
55
|
|
|
ClientEntityInterface $clientEntity, |
56
|
|
|
$userIdentifier = null |
57
|
|
|
) |
58
|
|
|
{ |
59
|
|
|
return call_user_func($this->scopeFinalizer, $scopes, $grantType, $clientEntity, $userIdentifier); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return ScopeQuery |
64
|
|
|
*/ |
65
|
|
|
protected function createQuery(): ScopeQuery |
66
|
|
|
{ |
67
|
|
|
return new ScopeQuery(); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|