@@ -70,18 +70,18 @@ discard block |
||
70 | 70 | public function enforce($ruleName, $user, $resource = null, $options = []) { |
71 | 71 | // If there is dynamic attributes, we pass them to the comparison manager |
72 | 72 | // When a comparison will be performed, the passed values will be retrieved and used |
73 | - if(isset($options['dynamic_attributes'])) { |
|
73 | + if (isset($options['dynamic_attributes'])) { |
|
74 | 74 | $this->comparisonManager->setDynamicAttributes($options['dynamic_attributes']); |
75 | 75 | } |
76 | 76 | // Retrieve cache value for the current rule and values if cache item is valid |
77 | - if(($cacheResult = isset($options['cache_result']) && $options['cache_result'] === true) === true) { |
|
77 | + if (($cacheResult = isset($options['cache_result']) && $options['cache_result'] === true) === true) { |
|
78 | 78 | $cacheItem = $this->cacheManager->getItem( |
79 | - "$ruleName-{$user->getId()}-" . (($resource !== null) ? $resource->getId() : ''), |
|
79 | + "$ruleName-{$user->getId()}-".(($resource !== null) ? $resource->getId() : ''), |
|
80 | 80 | (isset($options['cache_driver'])) ? $options['cache_driver'] : null, |
81 | 81 | (isset($options['cache_ttl'])) ? $options['cache_ttl'] : null |
82 | 82 | ); |
83 | 83 | // We check if the cache value s valid before returning it |
84 | - if(($cacheValue = $cacheItem->get()) !== null) { |
|
84 | + if (($cacheValue = $cacheItem->get()) !== null) { |
|
85 | 85 | return $cacheValue; |
86 | 86 | } |
87 | 87 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | foreach ($policyRule->getPolicyRuleAttributes() as $pra) { |
91 | 91 | $attribute = $pra->getAttribute(); |
92 | 92 | $attribute->setValue($this->attributeManager->retrieveAttribute($attribute, $user, $resource)); |
93 | - if(count($pra->getExtraData()) > 0) { |
|
93 | + if (count($pra->getExtraData()) > 0) { |
|
94 | 94 | $this->processExtraData($pra, $user, $resource); |
95 | 95 | } |
96 | 96 | $this->comparisonManager->compare($pra); |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | // The given result could be an array of rejected attributes or true |
99 | 99 | // True means that the rule is correctly enforced for the given user and resource |
100 | 100 | $result = $this->comparisonManager->getResult(); |
101 | - if($cacheResult) { |
|
101 | + if ($cacheResult) { |
|
102 | 102 | $cacheItem->set($result); |
103 | 103 | $this->cacheManager->save($cacheItem); |
104 | 104 | } |
@@ -111,8 +111,8 @@ discard block |
||
111 | 111 | * @param object $resource |
112 | 112 | */ |
113 | 113 | public function processExtraData(PolicyRuleAttribute $pra, $user, $resource) { |
114 | - foreach($pra->getExtraData() as $key => $data) { |
|
115 | - switch($key) { |
|
114 | + foreach ($pra->getExtraData() as $key => $data) { |
|
115 | + switch ($key) { |
|
116 | 116 | case 'with': |
117 | 117 | // This data has to be removed for it will be stored elsewhere |
118 | 118 | // in the policy rule attribute |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | // The "with" extra data is an array of attributes, which are objects |
121 | 121 | // Once we process it as policy rule attributes, we set it as the main policy rule attribute value |
122 | 122 | $subPolicyRuleAttributes = []; |
123 | - foreach($this->policyRuleManager->processRuleAttributes($data) as $subPolicyRuleAttribute) { |
|
123 | + foreach ($this->policyRuleManager->processRuleAttributes($data) as $subPolicyRuleAttribute) { |
|
124 | 124 | $subPolicyRuleAttributes[] = $subPolicyRuleAttribute; |
125 | 125 | } |
126 | 126 | $pra->setValue($subPolicyRuleAttributes); |
@@ -51,21 +51,21 @@ discard block |
||
51 | 51 | : $pra->getValue() |
52 | 52 | ; |
53 | 53 | // Checking that the configured comparison type is available |
54 | - if(!isset($this->comparisons[$pra->getComparisonType()])) { |
|
54 | + if (!isset($this->comparisons[$pra->getComparisonType()])) { |
|
55 | 55 | throw new \InvalidArgumentException('The requested comparison class does not exist'); |
56 | 56 | } |
57 | 57 | // The comparison class will perform the attribute check with the configured method |
58 | 58 | // For more complex comparisons, the comparison manager is injected |
59 | 59 | $comparison = new $this->comparisons[$pra->getComparisonType()]($this); |
60 | - if(!method_exists($comparison, $pra->getComparison())) { |
|
60 | + if (!method_exists($comparison, $pra->getComparison())) { |
|
61 | 61 | throw new \InvalidArgumentException('The requested comparison method does not exist'); |
62 | 62 | } |
63 | 63 | // Then the comparison is performed with needed |
64 | 64 | $result = $comparison->{$pra->getComparison()}($praValue, $attribute->getValue(), $pra->getExtraData()); |
65 | 65 | // If the checked attribute is not valid, the attribute slug is marked as rejected |
66 | 66 | // The rejected attributes will be returned instead of the expected true boolean |
67 | - if($result !== true) { |
|
68 | - if(!in_array($attribute->getSlug(), $this->rejectedAttributes)) { |
|
67 | + if ($result !== true) { |
|
68 | + if (!in_array($attribute->getSlug(), $this->rejectedAttributes)) { |
|
69 | 69 | $this->rejectedAttributes[] = $attribute->getSlug(); |
70 | 70 | } |
71 | 71 | return false; |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | * @throws \InvalidArgumentException |
93 | 93 | */ |
94 | 94 | public function getDynamicAttribute($attributeSlug) { |
95 | - if(!isset($this->dynamicAttributes[$attributeSlug])) { |
|
95 | + if (!isset($this->dynamicAttributes[$attributeSlug])) { |
|
96 | 96 | throw new \InvalidArgumentException("The dynamic value for attribute $attributeSlug was not given"); |
97 | 97 | } |
98 | 98 | return $this->dynamicAttributes[$attributeSlug]; |
@@ -54,19 +54,19 @@ |
||
54 | 54 | * @return boolean |
55 | 55 | */ |
56 | 56 | public function contains($policyRuleAttributes, $attributes, $extraData = []) { |
57 | - foreach($extraData['attribute']->getValue() as $attribute) { |
|
57 | + foreach ($extraData['attribute']->getValue() as $attribute) { |
|
58 | 58 | $result = true; |
59 | - foreach($policyRuleAttributes as $pra) { |
|
59 | + foreach ($policyRuleAttributes as $pra) { |
|
60 | 60 | $attributeData = $pra->getAttribute(); |
61 | 61 | $attributeData->setValue( |
62 | 62 | $this->comparisonManager->getAttributeManager()->retrieveAttribute($attributeData, $extraData['user'], $attribute) |
63 | 63 | ); |
64 | - if(!$this->comparisonManager->compare($pra)) { |
|
64 | + if (!$this->comparisonManager->compare($pra)) { |
|
65 | 65 | $result = false; |
66 | 66 | break; |
67 | 67 | } |
68 | 68 | } |
69 | - if($result === true) { |
|
69 | + if ($result === true) { |
|
70 | 70 | return true; |
71 | 71 | } |
72 | 72 | } |