1 | <?php |
||
15 | class ComparisonManager { |
||
16 | /** @var \PhpAbac\Manager\AttributeManager **/ |
||
17 | protected $attributeManager; |
||
18 | /** @var array **/ |
||
19 | protected $comparisons = [ |
||
20 | 'array' => ArrayComparison::class, |
||
21 | 'boolean' => BooleanComparison::class, |
||
22 | 'datetime' => DatetimeComparison::class, |
||
23 | 'numeric' => NumericComparison::class, |
||
24 | 'object' => ObjectComparison::class, |
||
25 | 'user' => UserComparison::class, |
||
26 | 'string' => StringComparison::class, |
||
27 | ]; |
||
28 | /** @var array **/ |
||
29 | protected $rejectedAttributes = []; |
||
30 | |||
31 | /** |
||
32 | * @param \PhpAbac\Manager\AttributeManager $manager |
||
33 | */ |
||
34 | 29 | public function __construct(AttributeManager $manager) { |
|
37 | |||
38 | /** |
||
39 | * This method retrieve the comparison class, instanciate it, |
||
40 | * and then perform the configured comparison |
||
41 | * It does return a control value for special operations, |
||
42 | * but the real check is at the end of the enforce() method, |
||
43 | * when the rejected attributes are counted. |
||
44 | * |
||
45 | * If the second parameter is set to true, compare will not report errors. |
||
46 | * This is used to test a bunch of comparisons expecting not all of them true to return a granted access. |
||
47 | * In fact, this parameter is used in comparisons which need to perform comparisons on their own. |
||
48 | * |
||
49 | * @param PolicyRuleAttribute $pra |
||
50 | * @param boolean $subComparing |
||
51 | * @return bool |
||
52 | */ |
||
53 | 9 | public function compare(PolicyRuleAttribute $pra, $subComparing = false) { |
|
85 | |||
86 | /** |
||
87 | * @param array $dynamicAttributes |
||
88 | */ |
||
89 | 2 | public function setDynamicAttributes($dynamicAttributes) { |
|
92 | |||
93 | /** |
||
94 | * A dynamic attribute is a value given by the user code as an option |
||
95 | * If a policy rule attribute is dynamic, |
||
96 | * we check that the developer has given a dynamic value in the options |
||
97 | * |
||
98 | * Dynamic attributes are given with slugs as key |
||
99 | * |
||
100 | * @param string $attributeSlug |
||
101 | * @return mixed |
||
102 | * @throws \InvalidArgumentException |
||
103 | */ |
||
104 | 3 | public function getDynamicAttribute($attributeSlug) { |
|
110 | |||
111 | /** |
||
112 | * @param string $type |
||
113 | * @param string $class |
||
114 | */ |
||
115 | public function addComparison($type, $class) { |
||
118 | |||
119 | /** |
||
120 | * @return \PhpAbac\Manager\AttributeManager |
||
121 | */ |
||
122 | 6 | public function getAttributeManager() { |
|
125 | |||
126 | /** |
||
127 | * This method is called when all the policy rule attributes are checked |
||
128 | * All along the comparisons, the failing attributes slugs are stored |
||
129 | * If the rejected attributes array is not empty, it means that the rule is not enforced |
||
130 | * |
||
131 | * @return array|bool |
||
132 | */ |
||
133 | 6 | public function getResult() { |
|
142 | } |
||
143 |