@@ -16,10 +16,10 @@ discard block |
||
16 | 16 | * {@inheritdoc} |
17 | 17 | */ |
18 | 18 | public function deleteItem($key) { |
19 | - if(isset($this->items[$key])) { |
|
19 | + if (isset($this->items[$key])) { |
|
20 | 20 | unset($this->items[$key]); |
21 | 21 | } |
22 | - if(isset($this->deferredItems[$key])) { |
|
22 | + if (isset($this->deferredItems[$key])) { |
|
23 | 23 | unset($this->deferredItems[$key]); |
24 | 24 | } |
25 | 25 | return true; |
@@ -29,8 +29,8 @@ discard block |
||
29 | 29 | * {@inheritdoc} |
30 | 30 | */ |
31 | 31 | public function deleteItems(array $keys) { |
32 | - foreach($keys as $key) { |
|
33 | - if(!$this->deleteItem($key)) { |
|
32 | + foreach ($keys as $key) { |
|
33 | + if (!$this->deleteItem($key)) { |
|
34 | 34 | return false; |
35 | 35 | } |
36 | 36 | } |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * {@inheritdoc} |
60 | 60 | */ |
61 | 61 | public function commit() { |
62 | - foreach($this->deferredItems as $key => $item) { |
|
62 | + foreach ($this->deferredItems as $key => $item) { |
|
63 | 63 | $this->items[$key] = $item; |
64 | 64 | unset($this->deferredItems[$key]); |
65 | 65 | } |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * {@inheritdoc} |
78 | 78 | */ |
79 | 79 | public function getItem($key) { |
80 | - if(!$this->hasItem($key)) { |
|
80 | + if (!$this->hasItem($key)) { |
|
81 | 81 | return new MemoryCacheItem($key); |
82 | 82 | } |
83 | 83 | return $this->items[$key]; |
@@ -88,8 +88,8 @@ discard block |
||
88 | 88 | */ |
89 | 89 | public function getItems(array $keys = array()) { |
90 | 90 | $items = []; |
91 | - foreach($keys as $key) { |
|
92 | - if($this->hasItem($key)) { |
|
91 | + foreach ($keys as $key) { |
|
92 | + if ($this->hasItem($key)) { |
|
93 | 93 | $items[$key] = $this->getItem($key); |
94 | 94 | } |
95 | 95 | } |
@@ -53,7 +53,7 @@ |
||
53 | 53 | * {@inheritdoc} |
54 | 54 | */ |
55 | 55 | public function get() { |
56 | - if(!$this->isHit()) { |
|
56 | + if (!$this->isHit()) { |
|
57 | 57 | throw new ExpiredCacheException('Cache item is expired'); |
58 | 58 | } |
59 | 59 | return $this->value; |
@@ -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; |
@@ -14,8 +14,8 @@ discard block |
||
14 | 14 | protected $value; |
15 | 15 | /** @var array **/ |
16 | 16 | protected $extraData; |
17 | - /** @var array Extended parameter */ |
|
18 | - protected $getter_params_a = []; |
|
17 | + /** @var array Extended parameter */ |
|
18 | + protected $getter_params_a = []; |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @param \PhpAbac\Model\AbstractAttribute $attribute |
@@ -136,21 +136,21 @@ discard block |
||
136 | 136 | return $this->extraData; |
137 | 137 | } |
138 | 138 | |
139 | - /** |
|
140 | - * @param array $value |
|
141 | - * |
|
142 | - * @return static |
|
143 | - */ |
|
144 | - public function setGetterParams($value) { |
|
145 | - $this->getter_params_a = $value; |
|
139 | + /** |
|
140 | + * @param array $value |
|
141 | + * |
|
142 | + * @return static |
|
143 | + */ |
|
144 | + public function setGetterParams($value) { |
|
145 | + $this->getter_params_a = $value; |
|
146 | 146 | |
147 | - return $this; |
|
148 | - } |
|
147 | + return $this; |
|
148 | + } |
|
149 | 149 | |
150 | - /** |
|
151 | - * @return array |
|
152 | - */ |
|
153 | - public function getGetterParams() { |
|
154 | - return $this->getter_params_a; |
|
155 | - } |
|
150 | + /** |
|
151 | + * @return array |
|
152 | + */ |
|
153 | + public function getGetterParams() { |
|
154 | + return $this->getter_params_a; |
|
155 | + } |
|
156 | 156 | } |
@@ -60,22 +60,22 @@ discard block |
||
60 | 60 | : $pra->getValue() |
61 | 61 | ; |
62 | 62 | // Checking that the configured comparison type is available |
63 | - if(!isset($this->comparisons[$pra->getComparisonType()])) { |
|
63 | + if (!isset($this->comparisons[$pra->getComparisonType()])) { |
|
64 | 64 | throw new \InvalidArgumentException('The requested comparison class does not exist'); |
65 | 65 | } |
66 | 66 | // The comparison class will perform the attribute check with the configured method |
67 | 67 | // For more complex comparisons, the comparison manager is injected |
68 | 68 | $comparison = new $this->comparisons[$pra->getComparisonType()]($this); |
69 | - if(!method_exists($comparison, $pra->getComparison())) { |
|
69 | + if (!method_exists($comparison, $pra->getComparison())) { |
|
70 | 70 | throw new \InvalidArgumentException('The requested comparison method does not exist'); |
71 | 71 | } |
72 | 72 | // Then the comparison is performed with needed |
73 | 73 | $result = $comparison->{$pra->getComparison()}($praValue, $attribute->getValue(), $pra->getExtraData()); |
74 | 74 | // If the checked attribute is not valid, the attribute slug is marked as rejected |
75 | 75 | // The rejected attributes will be returned instead of the expected true boolean |
76 | - if($result !== true) { |
|
76 | + if ($result !== true) { |
|
77 | 77 | // In case of sub comparing, the error reporting is disabled |
78 | - if(!in_array($attribute->getSlug(), $this->rejectedAttributes) && $subComparing === false) { |
|
78 | + if (!in_array($attribute->getSlug(), $this->rejectedAttributes) && $subComparing === false) { |
|
79 | 79 | $this->rejectedAttributes[] = $attribute->getSlug(); |
80 | 80 | } |
81 | 81 | return false; |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | * @throws \InvalidArgumentException |
103 | 103 | */ |
104 | 104 | public function getDynamicAttribute($attributeSlug) { |
105 | - if(!isset($this->dynamicAttributes[$attributeSlug])) { |
|
105 | + if (!isset($this->dynamicAttributes[$attributeSlug])) { |
|
106 | 106 | throw new \InvalidArgumentException("The dynamic value for attribute $attributeSlug was not given"); |
107 | 107 | } |
108 | 108 | return $this->dynamicAttributes[$attributeSlug]; |
@@ -3,7 +3,6 @@ |
||
3 | 3 | namespace PhpAbac\Manager; |
4 | 4 | |
5 | 5 | use PhpAbac\Model\PolicyRuleAttribute; |
6 | - |
|
7 | 6 | use PhpAbac\Comparison\ArrayComparison; |
8 | 7 | use PhpAbac\Comparison\BooleanComparison; |
9 | 8 | use PhpAbac\Comparison\DatetimeComparison; |
@@ -55,23 +55,23 @@ |
||
55 | 55 | * @return boolean |
56 | 56 | */ |
57 | 57 | public function contains($policyRuleAttributes, $attributes, $extraData = []) { |
58 | - foreach($extraData['attribute']->getValue() as $attribute) { |
|
58 | + foreach ($extraData['attribute']->getValue() as $attribute) { |
|
59 | 59 | $result = true; |
60 | 60 | // For each attribute, we check the whole rules set |
61 | - foreach($policyRuleAttributes as $pra) { |
|
61 | + foreach ($policyRuleAttributes as $pra) { |
|
62 | 62 | $attributeData = $pra->getAttribute(); |
63 | 63 | $attributeData->setValue( |
64 | 64 | $this->comparisonManager->getAttributeManager()->retrieveAttribute($attributeData, $extraData['user'], $attribute) |
65 | 65 | ); |
66 | 66 | // If one field is not matched, the whole attribute is rejected |
67 | - if(!$this->comparisonManager->compare($pra, true)) { |
|
67 | + if (!$this->comparisonManager->compare($pra, true)) { |
|
68 | 68 | //var_dump($attributeData->getName(), $attributeData->getValue(), $pra->getValue()); |
69 | 69 | $result = false; |
70 | 70 | break; |
71 | 71 | } |
72 | 72 | } |
73 | 73 | // If the result is still true at the end of the attribute check, the rule is enforced |
74 | - if($result === true) { |
|
74 | + if ($result === true) { |
|
75 | 75 | return true; |
76 | 76 | } |
77 | 77 | } |
@@ -53,7 +53,7 @@ |
||
53 | 53 | * {@inheritdoc} |
54 | 54 | */ |
55 | 55 | public function get() { |
56 | - if(!$this->isHit()) { |
|
56 | + if (!$this->isHit()) { |
|
57 | 57 | throw new ExpiredCacheException('Cache item is expired'); |
58 | 58 | } |
59 | 59 | return $this->value; |
@@ -128,7 +128,7 @@ |
||
128 | 128 | public function clear() { |
129 | 129 | $items = glob("{$this->cacheFolder}/*.txt"); // get all file names |
130 | 130 | foreach($items as $item){ // iterate files |
131 | - if(is_file($item)) |
|
131 | + if(is_file($item)) |
|
132 | 132 | unlink($item); // delete file |
133 | 133 | } |
134 | 134 | $this->deferredItems = []; |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | $this->cacheFolder = |
28 | 28 | (isset($options['cache_folder'])) |
29 | 29 | ? "{$options['cache_folder']}/text" |
30 | - : __DIR__ . '/../../../data/cache/text' |
|
30 | + : __DIR__.'/../../../data/cache/text' |
|
31 | 31 | ; |
32 | 32 | } |
33 | 33 | |
@@ -35,10 +35,10 @@ discard block |
||
35 | 35 | * {@inheritdoc} |
36 | 36 | */ |
37 | 37 | public function deleteItem($key) { |
38 | - if(is_file("{$this->cacheFolder}/$key.txt")) { |
|
38 | + if (is_file("{$this->cacheFolder}/$key.txt")) { |
|
39 | 39 | unlink("{$this->cacheFolder}/$key.txt"); |
40 | 40 | } |
41 | - if(isset($this->deferredItems[$key])) { |
|
41 | + if (isset($this->deferredItems[$key])) { |
|
42 | 42 | unset($this->deferredItems[$key]); |
43 | 43 | } |
44 | 44 | return true; |
@@ -48,8 +48,8 @@ discard block |
||
48 | 48 | * {@inheritdoc} |
49 | 49 | */ |
50 | 50 | public function deleteItems(array $keys) { |
51 | - foreach($keys as $key) { |
|
52 | - if(!$this->deleteItem($key)) { |
|
51 | + foreach ($keys as $key) { |
|
52 | + if (!$this->deleteItem($key)) { |
|
53 | 53 | return false; |
54 | 54 | } |
55 | 55 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * {@inheritdoc} |
81 | 81 | */ |
82 | 82 | public function commit() { |
83 | - foreach($this->deferredItems as $key => $item) { |
|
83 | + foreach ($this->deferredItems as $key => $item) { |
|
84 | 84 | $this->save($item); |
85 | 85 | unset($this->deferredItems[$key]); |
86 | 86 | } |
@@ -99,10 +99,10 @@ discard block |
||
99 | 99 | */ |
100 | 100 | public function getItem($key) { |
101 | 101 | $item = new TextCacheItem($key); |
102 | - if(!$this->hasItem($key)) { |
|
102 | + if (!$this->hasItem($key)) { |
|
103 | 103 | return $item; |
104 | 104 | } |
105 | - $data = explode(';',file_get_contents("{$this->cacheFolder}/{$key}.txt")); |
|
105 | + $data = explode(';', file_get_contents("{$this->cacheFolder}/{$key}.txt")); |
|
106 | 106 | return $item |
107 | 107 | ->set($data[0]) |
108 | 108 | ->expiresAt((new \DateTime($data[1]))) |
@@ -114,8 +114,8 @@ discard block |
||
114 | 114 | */ |
115 | 115 | public function getItems(array $keys = array()) { |
116 | 116 | $items = []; |
117 | - foreach($keys as $key) { |
|
118 | - if($this->hasItem($key)) { |
|
117 | + foreach ($keys as $key) { |
|
118 | + if ($this->hasItem($key)) { |
|
119 | 119 | $items[$key] = $this->getItem($key); |
120 | 120 | } |
121 | 121 | } |
@@ -127,8 +127,8 @@ discard block |
||
127 | 127 | */ |
128 | 128 | public function clear() { |
129 | 129 | $items = glob("{$this->cacheFolder}/*.txt"); // get all file names |
130 | - foreach($items as $item){ // iterate files |
|
131 | - if(is_file($item)) |
|
130 | + foreach ($items as $item) { // iterate files |
|
131 | + if (is_file($item)) |
|
132 | 132 | unlink($item); // delete file |
133 | 133 | } |
134 | 134 | $this->deferredItems = []; |
@@ -128,8 +128,10 @@ |
||
128 | 128 | public function clear() { |
129 | 129 | $items = glob("{$this->cacheFolder}/*.txt"); // get all file names |
130 | 130 | foreach($items as $item){ // iterate files |
131 | - if(is_file($item)) |
|
132 | - unlink($item); // delete file |
|
131 | + if(is_file($item)) { |
|
132 | + unlink($item); |
|
133 | + } |
|
134 | + // delete file |
|
133 | 135 | } |
134 | 136 | $this->deferredItems = []; |
135 | 137 | return true; |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
85 | - * @return bool |
|
85 | + * @return string |
|
86 | 86 | */ |
87 | 87 | public function getParentNationality() { |
88 | 88 | return $this->parentNationality; |
@@ -119,7 +119,6 @@ discard block |
||
119 | 119 | /** |
120 | 120 | * Return a specific visa |
121 | 121 | * |
122 | - * @param Visa $visa |
|
123 | 122 | * |
124 | 123 | * @return mixed|null |
125 | 124 | */ |
@@ -116,22 +116,22 @@ |
||
116 | 116 | return $this->visas; |
117 | 117 | } |
118 | 118 | |
119 | - /** |
|
120 | - * Return a specific visa |
|
121 | - * |
|
122 | - * @param Visa $visa |
|
123 | - * |
|
124 | - * @return mixed|null |
|
125 | - */ |
|
119 | + /** |
|
120 | + * Return a specific visa |
|
121 | + * |
|
122 | + * @param Visa $visa |
|
123 | + * |
|
124 | + * @return mixed|null |
|
125 | + */ |
|
126 | 126 | public function getVisa($country_code) { |
127 | - /** @var Visa $visa */ |
|
128 | - $visas = []; |
|
129 | - foreach($this->visas as $visa) { |
|
130 | - if ($visa->getCountry()->getCode() == $country_code) |
|
131 | - $visas[] = $visa; |
|
132 | - } |
|
133 | - return $visas; |
|
134 | - } |
|
127 | + /** @var Visa $visa */ |
|
128 | + $visas = []; |
|
129 | + foreach($this->visas as $visa) { |
|
130 | + if ($visa->getCountry()->getCode() == $country_code) |
|
131 | + $visas[] = $visa; |
|
132 | + } |
|
133 | + return $visas; |
|
134 | + } |
|
135 | 135 | |
136 | 136 | /** |
137 | 137 | * @param bool $hasDoneJapd |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | * @return \PhpAbac\Example\User |
104 | 104 | */ |
105 | 105 | public function removeVisa(Visa $visa) { |
106 | - if(isset($this->visas[$visa->getId()])) { |
|
106 | + if (isset($this->visas[$visa->getId()])) { |
|
107 | 107 | unset($this->visas[$visa->getId()]); |
108 | 108 | } |
109 | 109 | return $this; |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | public function getVisa($country_code) { |
127 | 127 | /** @var Visa $visa */ |
128 | 128 | $visas = []; |
129 | - foreach($this->visas as $visa) { |
|
129 | + foreach ($this->visas as $visa) { |
|
130 | 130 | if ($visa->getCountry()->getCode() == $country_code) |
131 | 131 | $visas[] = $visa; |
132 | 132 | } |
@@ -127,8 +127,9 @@ |
||
127 | 127 | /** @var Visa $visa */ |
128 | 128 | $visas = []; |
129 | 129 | foreach($this->visas as $visa) { |
130 | - if ($visa->getCountry()->getCode() == $country_code) |
|
131 | - $visas[] = $visa; |
|
130 | + if ($visa->getCountry()->getCode() == $country_code) { |
|
131 | + $visas[] = $visa; |
|
132 | + } |
|
132 | 133 | } |
133 | 134 | return $visas; |
134 | 135 | } |
@@ -49,7 +49,7 @@ |
||
49 | 49 | * Method to check if a resource is supported by the loader |
50 | 50 | * This method check only extension file |
51 | 51 | * |
52 | - * @param $resource |
|
52 | + * @param string $resource |
|
53 | 53 | * |
54 | 54 | * @return boolean Return true if the extension of the ressource is supported by the loader |
55 | 55 | */ |
@@ -13,27 +13,27 @@ discard block |
||
13 | 13 | use Symfony\Component\Config\Loader\FileLoader; |
14 | 14 | |
15 | 15 | abstract class AbacLoader extends FileLoader { |
16 | - /** |
|
17 | - * Must be overrided to contains an array of allowed extension |
|
18 | - */ |
|
19 | - protected static $_EXTENSION_ALLOWED_A = []; |
|
16 | + /** |
|
17 | + * Must be overrided to contains an array of allowed extension |
|
18 | + */ |
|
19 | + protected static $_EXTENSION_ALLOWED_A = []; |
|
20 | 20 | |
21 | - /** @var ConfigurationManager The configuration manage instanciator and user of this AbacLoader Instance */ |
|
22 | - protected $configurationManger; |
|
21 | + /** @var ConfigurationManager The configuration manage instanciator and user of this AbacLoader Instance */ |
|
22 | + protected $configurationManger; |
|
23 | 23 | |
24 | - public function __construct( FileLocatorInterface $locator ) { |
|
25 | - parent::__construct( $locator ); |
|
26 | - } |
|
24 | + public function __construct( FileLocatorInterface $locator ) { |
|
25 | + parent::__construct( $locator ); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * Method to load a resource and return an array that contains decoded data of the resource |
|
30 | - * |
|
31 | - * @param string $resource The path of the resource to load |
|
32 | - * @param null $type ?? |
|
33 | - * |
|
34 | - * @return string |
|
35 | - */ |
|
36 | - abstract public function load( $resource, $type = null ); |
|
28 | + /** |
|
29 | + * Method to load a resource and return an array that contains decoded data of the resource |
|
30 | + * |
|
31 | + * @param string $resource The path of the resource to load |
|
32 | + * @param null $type ?? |
|
33 | + * |
|
34 | + * @return string |
|
35 | + */ |
|
36 | + abstract public function load( $resource, $type = null ); |
|
37 | 37 | |
38 | 38 | // /** |
39 | 39 | // * Method to check if a resource ( by his path ) is supported by the loader |
@@ -45,25 +45,25 @@ discard block |
||
45 | 45 | // */ |
46 | 46 | // abstract public function supports( $resource, $type = null ); |
47 | 47 | |
48 | - /** |
|
49 | - * Method to check if a resource is supported by the loader |
|
50 | - * This method check only extension file |
|
51 | - * |
|
52 | - * @param $resource |
|
53 | - * |
|
54 | - * @return boolean Return true if the extension of the ressource is supported by the loader |
|
55 | - */ |
|
56 | - public static final function supportsExtension( $resource ) { |
|
57 | - return in_array( pathinfo( $resource, PATHINFO_EXTENSION ), self::getExtensionAllowed() ); |
|
58 | - } |
|
48 | + /** |
|
49 | + * Method to check if a resource is supported by the loader |
|
50 | + * This method check only extension file |
|
51 | + * |
|
52 | + * @param $resource |
|
53 | + * |
|
54 | + * @return boolean Return true if the extension of the ressource is supported by the loader |
|
55 | + */ |
|
56 | + public static final function supportsExtension( $resource ) { |
|
57 | + return in_array( pathinfo( $resource, PATHINFO_EXTENSION ), self::getExtensionAllowed() ); |
|
58 | + } |
|
59 | 59 | |
60 | 60 | /** |
61 | - * Method to return allowed extension for file to load with the loader |
|
61 | + * Method to return allowed extension for file to load with the loader |
|
62 | 62 | * @return mixed |
63 | 63 | */ |
64 | - private static final function getExtensionAllowed() { |
|
65 | - return static::$_EXTENSION_ALLOWED_A; |
|
66 | - } |
|
64 | + private static final function getExtensionAllowed() { |
|
65 | + return static::$_EXTENSION_ALLOWED_A; |
|
66 | + } |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | ?> |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | /** @var ConfigurationManager The configuration manage instanciator and user of this AbacLoader Instance */ |
22 | 22 | protected $configurationManger; |
23 | 23 | |
24 | - public function __construct( FileLocatorInterface $locator ) { |
|
25 | - parent::__construct( $locator ); |
|
24 | + public function __construct(FileLocatorInterface $locator) { |
|
25 | + parent::__construct($locator); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * |
34 | 34 | * @return string |
35 | 35 | */ |
36 | - abstract public function load( $resource, $type = null ); |
|
36 | + abstract public function load($resource, $type = null); |
|
37 | 37 | |
38 | 38 | // /** |
39 | 39 | // * Method to check if a resource ( by his path ) is supported by the loader |
@@ -53,8 +53,8 @@ discard block |
||
53 | 53 | * |
54 | 54 | * @return boolean Return true if the extension of the ressource is supported by the loader |
55 | 55 | */ |
56 | - public static final function supportsExtension( $resource ) { |
|
57 | - return in_array( pathinfo( $resource, PATHINFO_EXTENSION ), self::getExtensionAllowed() ); |
|
56 | + public static final function supportsExtension($resource) { |
|
57 | + return in_array(pathinfo($resource, PATHINFO_EXTENSION), self::getExtensionAllowed()); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |