@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | $user1Vehicle = $abac->enforce('vehicle-homologation', $users[0], $vehicles[0], [ |
35 | 35 | 'dynamic_attributes' => ['proprietaire' => 1] |
36 | 36 | ]); |
37 | - if($user1Vehicle === true) { |
|
37 | + if ($user1Vehicle === true) { |
|
38 | 38 | echo("GRANTED : The vehicle 1 is able to be approved for the user 1\n"); |
39 | 39 | } else { |
40 | 40 | echo("FAIL : The system didn't grant access\n"); |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | $user3Vehicle = $abac->enforce('vehicle-homologation', $users[2], $vehicles[1], [ |
43 | 43 | 'dynamic_attributes' => ['proprietaire' => 3] |
44 | 44 | ]); |
45 | - if(!$user3Vehicle !== true) { |
|
45 | + if (!$user3Vehicle !== true) { |
|
46 | 46 | echo("DENIED : The vehicle 2 is not approved for the user 3 because its last technical review is too old\n"); |
47 | 47 | } else { |
48 | 48 | echo("FAIL : The system didn't deny access\n"); |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | $user4Vehicle = $abac->enforce('vehicle-homologation', $users[3], $vehicles[3], [ |
51 | 51 | 'dynamic_attributes' => ['proprietaire' => 4] |
52 | 52 | ]); |
53 | - if($user4Vehicle !== true) { |
|
53 | + if ($user4Vehicle !== true) { |
|
54 | 54 | echo("DENIED : The vehicle 4 is not able to be approved for the user 4 because he has no driving license\n"); |
55 | 55 | } else { |
56 | 56 | echo("FAIL : The system didn't deny access\n"); |
@@ -58,19 +58,19 @@ discard block |
||
58 | 58 | $user5Vehicle = $abac->enforce('vehicle-homologation', $users[3], $vehicles[3], [ |
59 | 59 | 'dynamic_attributes' => ['proprietaire' => 1] |
60 | 60 | ]); |
61 | - if($user5Vehicle !== true) { |
|
61 | + if ($user5Vehicle !== true) { |
|
62 | 62 | echo("DENIED : The vehicle 4 is not able to be approved for the user 2 because he doesn't own the vehicle\n"); |
63 | 63 | } else { |
64 | 64 | echo("FAIL : The system didn't deny access\n"); |
65 | 65 | } |
66 | 66 | $userTravel1 = $abac->enforce('travel-to-usa', $users[0]); |
67 | - if($userTravel1 !== true) { |
|
67 | + if ($userTravel1 !== true) { |
|
68 | 68 | echo("DENIED: The user 1 is not allowed to travel to the USA because he doesn't have an US visa\n"); |
69 | 69 | } else { |
70 | 70 | echo('FAIL: The system didn\'t deny access'); |
71 | 71 | } |
72 | 72 | $userTravel2 = $abac->enforce('travel-to-usa', $users[1]); |
73 | - if($userTravel2 === true) { |
|
73 | + if ($userTravel2 === true) { |
|
74 | 74 | echo("GRANTED: The user 2 is allowed to travel to the USA\n"); |
75 | 75 | } else { |
76 | 76 | echo('FAIL: The system didn\'t deny access'); |
@@ -69,14 +69,14 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function enforce($ruleName, $user, $resource = null, $options = []) { |
71 | 71 | // Retrieve cache value for the current rule and values if cache item is valid |
72 | - if(($cacheResult = isset($options['cache_result']) && $options['cache_result'] === true) === true) { |
|
72 | + if (($cacheResult = isset($options['cache_result']) && $options['cache_result'] === true) === true) { |
|
73 | 73 | $cacheItem = $this->cacheManager->getItem( |
74 | - "$ruleName-{$user->getId()}-" . (($resource !== null) ? $resource->getId() : ''), |
|
74 | + "$ruleName-{$user->getId()}-".(($resource !== null) ? $resource->getId() : ''), |
|
75 | 75 | (isset($options['cache_driver'])) ? $options['cache_driver'] : null, |
76 | 76 | (isset($options['cache_ttl'])) ? $options['cache_ttl'] : null |
77 | 77 | ); |
78 | 78 | // We check if the cache value s valid before returning it |
79 | - if(($cacheValue = $cacheItem->get()) !== null) { |
|
79 | + if (($cacheValue = $cacheItem->get()) !== null) { |
|
80 | 80 | return $cacheValue; |
81 | 81 | } |
82 | 82 | } |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | $attribute = $pra->getAttribute(); |
88 | 88 | $attribute->setValue($this->attributeManager->retrieveAttribute($attribute, $user, $resource)); |
89 | 89 | $dynamicAttributes = (isset($options['dynamic_attributes'])) ? $options['dynamic_attributes'] : []; |
90 | - if(count($pra->getExtraData()) > 0) { |
|
90 | + if (count($pra->getExtraData()) > 0) { |
|
91 | 91 | $this->processExtraData($pra, $user, $resource); |
92 | 92 | } |
93 | 93 | $value = |
@@ -105,8 +105,8 @@ discard block |
||
105 | 105 | $rejectedAttributes[] = $attribute->getSlug(); |
106 | 106 | } |
107 | 107 | } |
108 | - $result = (count($rejectedAttributes) === 0) ? : $rejectedAttributes; |
|
109 | - if($cacheResult) { |
|
108 | + $result = (count($rejectedAttributes) === 0) ?: $rejectedAttributes; |
|
109 | + if ($cacheResult) { |
|
110 | 110 | $cacheItem->set($result); |
111 | 111 | $this->cacheManager->save($cacheItem); |
112 | 112 | } |
@@ -114,12 +114,12 @@ discard block |
||
114 | 114 | } |
115 | 115 | |
116 | 116 | public function processExtraData(PolicyRuleAttribute $pra, $user, $resource) { |
117 | - foreach($pra->getExtraData() as $key => $data) { |
|
118 | - switch($key) { |
|
117 | + foreach ($pra->getExtraData() as $key => $data) { |
|
118 | + switch ($key) { |
|
119 | 119 | case 'with': |
120 | 120 | $pra->removeExtraData('with'); |
121 | 121 | $subPolicyRuleAttributes = []; |
122 | - foreach($this->policyRuleManager->processRuleAttributes($data) as $subPolicyRuleAttribute) { |
|
122 | + foreach ($this->policyRuleManager->processRuleAttributes($data) as $subPolicyRuleAttribute) { |
|
123 | 123 | $subPolicyRuleAttributes[] = $subPolicyRuleAttribute; |
124 | 124 | } |
125 | 125 | $pra->setValue($subPolicyRuleAttributes); |
@@ -121,7 +121,7 @@ |
||
121 | 121 | * @return \PhpAbac\Model\PolicyRuleAttribute |
122 | 122 | */ |
123 | 123 | public function removeExtraData($key) { |
124 | - if(isset($this->extraData[$key])) { |
|
124 | + if (isset($this->extraData[$key])) { |
|
125 | 125 | unset($this->extraData[$key]); |
126 | 126 | } |
127 | 127 | return $this; |
@@ -36,11 +36,11 @@ |
||
36 | 36 | * @return bool |
37 | 37 | */ |
38 | 38 | public function compare($type, $method, $expectedValue, $value, $extraData = []) { |
39 | - if(!isset($this->comparisons[$type])) { |
|
39 | + if (!isset($this->comparisons[$type])) { |
|
40 | 40 | throw new \InvalidArgumentException('The requested comparison class does not exist'); |
41 | 41 | } |
42 | 42 | $comparison = new $this->comparisons[$type]($this); |
43 | - if(!method_exists($comparison, $method)) { |
|
43 | + if (!method_exists($comparison, $method)) { |
|
44 | 44 | throw new \InvalidArgumentException('The requested comparison method does not exist'); |
45 | 45 | } |
46 | 46 | return $comparison->{$method}($expectedValue, $value, $extraData); |
@@ -32,14 +32,14 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function getRule($ruleName) |
34 | 34 | { |
35 | - if(!isset($this->rules[$ruleName])) { |
|
36 | - throw new \InvalidArgumentException('The given rule "' . $ruleName . '" is not configured'); |
|
35 | + if (!isset($this->rules[$ruleName])) { |
|
36 | + throw new \InvalidArgumentException('The given rule "'.$ruleName.'" is not configured'); |
|
37 | 37 | } |
38 | 38 | $rule = |
39 | 39 | (new PolicyRule()) |
40 | 40 | ->setName($ruleName) |
41 | 41 | ; |
42 | - foreach($this->processRuleAttributes($this->rules[$ruleName]['attributes']) as $pra) { |
|
42 | + foreach ($this->processRuleAttributes($this->rules[$ruleName]['attributes']) as $pra) { |
|
43 | 43 | $rule->addPolicyRuleAttribute($pra); |
44 | 44 | } |
45 | 45 | return $rule; |
@@ -49,15 +49,15 @@ discard block |
||
49 | 49 | * @param array $attributes |
50 | 50 | */ |
51 | 51 | public function processRuleAttributes($attributes) { |
52 | - foreach($attributes as $attributeName => $attribute) { |
|
52 | + foreach ($attributes as $attributeName => $attribute) { |
|
53 | 53 | $pra = (new PolicyRuleAttribute()) |
54 | 54 | ->setAttribute($this->attributeManager->getAttribute($attributeName)) |
55 | 55 | ->setComparison($attribute['comparison']) |
56 | 56 | ->setComparisonType($attribute['comparison_type']) |
57 | 57 | ->setValue((isset($attribute['value'])) ? $attribute['value'] : null) |
58 | 58 | ; |
59 | - foreach($attribute as $key => $value) { |
|
60 | - if(!in_array($key, ['comparison', 'comparison_type', 'value'])) { |
|
59 | + foreach ($attribute as $key => $value) { |
|
60 | + if (!in_array($key, ['comparison', 'comparison_type', 'value'])) { |
|
61 | 61 | $pra->addExtraData($key, $value); |
62 | 62 | } |
63 | 63 | } |
@@ -54,11 +54,11 @@ discard block |
||
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 | - if(!$this->comparisonManager->compare( |
|
61 | + if (!$this->comparisonManager->compare( |
|
62 | 62 | $pra->getComparisonType(), |
63 | 63 | $pra->getComparison(), |
64 | 64 | $pra->getValue(), |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | break; |
69 | 69 | } |
70 | 70 | } |
71 | - if($result === true) { |
|
71 | + if ($result === true) { |
|
72 | 72 | return true; |
73 | 73 | } |
74 | 74 | } |
@@ -101,7 +101,7 @@ |
||
101 | 101 | * @return \PhpAbac\Example\User |
102 | 102 | */ |
103 | 103 | public function removeVisa(Visa $visa) { |
104 | - if(isset($this->visas[$visa->getId()])) { |
|
104 | + if (isset($this->visas[$visa->getId()])) { |
|
105 | 105 | unset($this->visas[$visa->getId()]); |
106 | 106 | } |
107 | 107 | return $this; |