1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Limoncello\Auth\Authorization\PolicyAdministration; |
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 Limoncello\Auth\Contracts\Authorization\PolicyAdministration\AdviceInterface; |
22
|
|
|
use Limoncello\Auth\Contracts\Authorization\PolicyAdministration\MethodInterface; |
23
|
|
|
use Limoncello\Auth\Contracts\Authorization\PolicyAdministration\ObligationInterface; |
24
|
|
|
use Limoncello\Auth\Contracts\Authorization\PolicyAdministration\PolicyCombiningAlgorithmInterface; |
25
|
|
|
use Limoncello\Auth\Contracts\Authorization\PolicyAdministration\PolicyInterface; |
26
|
|
|
use Limoncello\Auth\Contracts\Authorization\PolicyAdministration\PolicySetInterface; |
27
|
|
|
use Limoncello\Auth\Contracts\Authorization\PolicyAdministration\TargetInterface; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @package Limoncello\Auth |
31
|
|
|
*/ |
32
|
|
|
class PolicySet implements PolicySetInterface |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* @var string|null |
36
|
|
|
*/ |
37
|
|
|
private $name; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var TargetInterface |
41
|
|
|
*/ |
42
|
|
|
private $target; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var PolicyInterface[]|PolicySetInterface[] |
46
|
|
|
*/ |
47
|
|
|
private $policiesAndSets; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var PolicyCombiningAlgorithmInterface |
51
|
|
|
*/ |
52
|
|
|
private $combiningAlgorithm; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var MethodInterface[] |
56
|
|
|
*/ |
57
|
|
|
private $obligations; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var MethodInterface[] |
61
|
|
|
*/ |
62
|
|
|
private $advice; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param PolicyInterface[]|PolicySetInterface[] $policiesAndSets |
66
|
|
|
* @param PolicyCombiningAlgorithmInterface $combiningAlgorithm |
67
|
|
|
* @param null|string $name |
68
|
|
|
* @param TargetInterface $target |
|
|
|
|
69
|
|
|
* @param MethodInterface[] $obligations |
70
|
13 |
|
* @param MethodInterface[] $advice |
71
|
|
|
*/ |
72
|
|
|
public function __construct( |
73
|
|
|
array $policiesAndSets, |
74
|
|
|
PolicyCombiningAlgorithmInterface $combiningAlgorithm, |
75
|
|
|
string $name = null, |
76
|
|
|
TargetInterface $target = null, |
77
|
|
|
array $obligations = [], |
78
|
13 |
|
array $advice = [] |
79
|
13 |
|
) { |
80
|
13 |
|
$this->setName($name)->setTarget($target) |
81
|
|
|
->setPoliciesAndSets($policiesAndSets)->setCombiningAlgorithm($combiningAlgorithm) |
82
|
|
|
->setObligations($obligations)->setAdvice($advice); |
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
13 |
|
* @inheritdoc |
87
|
|
|
*/ |
88
|
13 |
|
public function getName(): ?string |
89
|
|
|
{ |
90
|
|
|
return $this->name; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param null|string $name |
95
|
|
|
* |
96
|
13 |
|
* @return self |
97
|
|
|
*/ |
98
|
13 |
|
public function setName(?string $name): self |
99
|
|
|
{ |
100
|
13 |
|
$this->name = $name; |
101
|
|
|
|
102
|
|
|
return $this; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
13 |
|
* @inheritdoc |
107
|
|
|
*/ |
108
|
13 |
|
public function getTarget(): ?TargetInterface |
109
|
|
|
{ |
110
|
|
|
return $this->target; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param TargetInterface|null $target |
115
|
|
|
* |
116
|
13 |
|
* @return self |
117
|
|
|
*/ |
118
|
13 |
|
public function setTarget(?TargetInterface $target): self |
119
|
|
|
{ |
120
|
13 |
|
$this->target = $target; |
121
|
|
|
|
122
|
|
|
return $this; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
13 |
|
* @inheritdoc |
127
|
|
|
*/ |
128
|
13 |
|
public function getPoliciesAndSets(): array |
129
|
|
|
{ |
130
|
|
|
return $this->policiesAndSets; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @param PolicyInterface[]|PolicySetInterface[] $policiesAndSets |
135
|
|
|
* |
136
|
13 |
|
* @return self |
137
|
|
|
*/ |
138
|
13 |
|
public function setPoliciesAndSets(array $policiesAndSets): self |
139
|
|
|
{ |
140
|
13 |
|
$this->policiesAndSets = $policiesAndSets; |
141
|
|
|
|
142
|
|
|
return $this; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
13 |
|
* @inheritdoc |
147
|
|
|
*/ |
148
|
13 |
|
public function getCombiningAlgorithm(): PolicyCombiningAlgorithmInterface |
149
|
|
|
{ |
150
|
|
|
return $this->combiningAlgorithm; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @param PolicyCombiningAlgorithmInterface $combiningAlgorithm |
155
|
|
|
* |
156
|
13 |
|
* @return self |
157
|
|
|
*/ |
158
|
13 |
|
public function setCombiningAlgorithm(PolicyCombiningAlgorithmInterface $combiningAlgorithm): self |
159
|
|
|
{ |
160
|
13 |
|
$this->combiningAlgorithm = $combiningAlgorithm; |
161
|
|
|
|
162
|
|
|
return $this; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
13 |
|
* @inheritdoc |
167
|
|
|
*/ |
168
|
13 |
|
public function getObligations(): array |
169
|
|
|
{ |
170
|
|
|
return $this->obligations; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @param ObligationInterface[] $obligations |
175
|
|
|
* |
176
|
13 |
|
* @return self |
177
|
|
|
*/ |
178
|
13 |
|
public function setObligations(array $obligations): self |
179
|
|
|
{ |
180
|
13 |
|
$this->obligations = $obligations; |
181
|
|
|
|
182
|
|
|
return $this; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
13 |
|
* @inheritdoc |
187
|
|
|
*/ |
188
|
13 |
|
public function getAdvice(): array |
189
|
|
|
{ |
190
|
|
|
return $this->advice; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @param AdviceInterface[] $advice |
195
|
|
|
* |
196
|
13 |
|
* @return self |
197
|
|
|
*/ |
198
|
13 |
|
public function setAdvice(array $advice): self |
199
|
|
|
{ |
200
|
13 |
|
$this->advice = $advice; |
201
|
|
|
|
202
|
|
|
return $this; |
203
|
|
|
} |
204
|
|
|
} |
205
|
|
|
|
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.