1 | <?php |
||
13 | class ComparisonManager { |
||
14 | /** @var \PhpAbac\Manager\AttributeManager **/ |
||
15 | protected $attributeManager; |
||
16 | /** @var array **/ |
||
17 | protected $comparisons = [ |
||
18 | 'array' => ArrayComparison::class, |
||
19 | 'boolean' => BooleanComparison::class, |
||
20 | 'datetime' => DatetimeComparison::class, |
||
21 | 'numeric' => NumericComparison::class, |
||
22 | 'string' => StringComparison::class, |
||
23 | ]; |
||
24 | /** @var array **/ |
||
25 | protected $rejectedAttributes = []; |
||
26 | |||
27 | /** |
||
28 | * @param \PhpAbac\Manager\AttributeManager $manager |
||
29 | */ |
||
30 | 24 | public function __construct(AttributeManager $manager) { |
|
33 | |||
34 | /** |
||
35 | * This method retrieve the comparison class, instanciate it, |
||
36 | * and then perform the configured comparison |
||
37 | * It does return a control value for special operations, |
||
38 | * but the real check is at the end of the enforce() method, |
||
39 | * when the rejected attributes are counted |
||
40 | * |
||
41 | * @param PolicyRuleAttribute $pra |
||
42 | * @return bool |
||
43 | */ |
||
44 | 6 | public function compare(PolicyRuleAttribute $pra) { |
|
75 | |||
76 | /** |
||
77 | * @param array $dynamicAttributes |
||
78 | */ |
||
79 | 2 | public function setDynamicAttributes($dynamicAttributes) { |
|
82 | |||
83 | /** |
||
84 | * A dynamic attribute is a value given by the user code as an option |
||
85 | * If a policy rule attribute is dynamic, |
||
86 | * we check that the developer has given a dynamic value in the options |
||
87 | * |
||
88 | * Dynamic attributes are given with slugs as key |
||
89 | * |
||
90 | * @param string $attributeSlug |
||
91 | * @return mixed |
||
92 | * @throws \InvalidArgumentException |
||
93 | */ |
||
94 | 3 | public function getDynamicAttribute($attributeSlug) { |
|
100 | |||
101 | /** |
||
102 | * @param string $type |
||
103 | * @param string $class |
||
104 | */ |
||
105 | public function addComparison($type, $class) { |
||
108 | |||
109 | /** |
||
110 | * @return \PhpAbac\Manager\AttributeManager |
||
111 | */ |
||
112 | 2 | public function getAttributeManager() { |
|
115 | |||
116 | /** |
||
117 | * This method is called when all the policy rule attributes are checked |
||
118 | * All along the comparisons, the failing attributes slugs are stored |
||
119 | * If the rejected attributes array is not empty, it means that the rule is not enforced |
||
120 | * |
||
121 | * @return array|bool |
||
122 | */ |
||
123 | 3 | public function getResult() { |
|
132 | } |