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