1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* The MIT License (MIT) |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2014-2017 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\Bundle\Server\Annotation; |
15
|
|
|
|
16
|
|
|
use Assert\Assertion; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Annotation class for @OAuth2(). |
20
|
|
|
* |
21
|
|
|
* @Annotation |
22
|
|
|
* @Target({"CLASS", "METHOD"}) |
23
|
|
|
*/ |
24
|
|
|
final class OAuth2 |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var null|string |
28
|
|
|
*/ |
29
|
|
|
private $scope = null; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var null|string |
33
|
|
|
*/ |
34
|
|
|
private $clientId = null; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var null|string |
38
|
|
|
*/ |
39
|
|
|
private $resourceOwnerId = null; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param array $data an array of key/value parameters |
43
|
|
|
* |
44
|
|
|
* @throws \BadMethodCallException |
45
|
|
|
*/ |
46
|
|
|
public function __construct(array $data) |
47
|
|
|
{ |
48
|
|
|
if (isset($data['value'])) { |
49
|
|
|
$data['path'] = $data['value']; |
50
|
|
|
unset($data['value']); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
foreach ($data as $key => $value) { |
54
|
|
|
$method = 'set'.str_replace('_', '', ucwords($key, '_')); |
55
|
|
|
if (!method_exists($this, $method)) { |
56
|
|
|
throw new \BadMethodCallException(sprintf("Unknown property '%s' on annotation '%s'.", $key, get_class($this))); |
57
|
|
|
} |
58
|
|
|
$this->$method($value); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param string $clientId |
64
|
|
|
*/ |
65
|
|
|
protected function setClientId(string $clientId) |
66
|
|
|
{ |
67
|
|
|
Assertion::string($clientId, 'The client public ID should be a string.'); |
68
|
|
|
$this->clientId = $clientId; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return null|string |
73
|
|
|
*/ |
74
|
|
|
public function getClientId(): ?string |
75
|
|
|
{ |
76
|
|
|
return $this->clientId; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param string $resourceOwnerId |
81
|
|
|
*/ |
82
|
|
|
protected function setResourceOwnerId(string $resourceOwnerId) |
83
|
|
|
{ |
84
|
|
|
Assertion::string($resourceOwnerId, 'The resource owner public ID should be a string.'); |
85
|
|
|
$this->resourceOwnerId = $resourceOwnerId; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return null|string |
90
|
|
|
*/ |
91
|
|
|
public function getResourceOwnerId(): ?string |
92
|
|
|
{ |
93
|
|
|
return $this->resourceOwnerId; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param string $scope |
98
|
|
|
*/ |
99
|
|
|
protected function setScope(string $scope) |
100
|
|
|
{ |
101
|
|
|
$this->scope = $scope; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return null|string |
106
|
|
|
*/ |
107
|
|
|
public function getScope(): ?string |
108
|
|
|
{ |
109
|
|
|
return $this->scope; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|