@@ -6,7 +6,7 @@ |
||
6 | 6 | |
7 | 7 | class YamlAbacLoader extends AbacLoader |
8 | 8 | { |
9 | - protected static $_EXTENSION_ALLOWED_A = ['yml','yaml']; |
|
9 | + protected static $_EXTENSION_ALLOWED_A = ['yml', 'yaml']; |
|
10 | 10 | |
11 | 11 | public function load($resource, $type = null) |
12 | 12 | { |
@@ -14,7 +14,7 @@ |
||
14 | 14 | // $path_to_load = $this->locator->locate($resource); |
15 | 15 | $path_to_load = $resource; |
16 | 16 | |
17 | - return (new JsonDecode(true))->decode(file_get_contents($path_to_load),JsonEncoder::FORMAT,[ 'json_decode_associative' => true ] ) + ['path' => $path_to_load]; |
|
17 | + return (new JsonDecode(true))->decode(file_get_contents($path_to_load), JsonEncoder::FORMAT, ['json_decode_associative' => true]) + ['path' => $path_to_load]; |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | public function supports($resource, $type = null) |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | public function getRule($ruleName, $user, $resource) |
33 | 33 | { |
34 | 34 | if (!isset($this->rules[$ruleName])) { |
35 | - throw new \InvalidArgumentException('The given rule "' . $ruleName . '" is not configured'); |
|
35 | + throw new \InvalidArgumentException('The given rule "'.$ruleName.'" is not configured'); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | // force to treat always arrays |
@@ -70,12 +70,12 @@ discard block |
||
70 | 70 | ->setComparison($attribute['comparison']) |
71 | 71 | ->setComparisonType($attribute['comparison_type']) |
72 | 72 | ->setValue((isset($attribute['value'])) ? $attribute['value'] : null) |
73 | - ->setGetterParams( isset( $attribute[ 'getter_params' ] ) ? $attribute[ 'getter_params' ] : [] ); |
|
73 | + ->setGetterParams(isset($attribute['getter_params']) ? $attribute['getter_params'] : []); |
|
74 | 74 | $this->processRuleAttributeComparisonType($pra, $user, $resource); |
75 | 75 | // In the case the user configured more keys than the basic ones |
76 | 76 | // it will be stored as extra data |
77 | 77 | foreach ($attribute as $key => $value) { |
78 | - if (!in_array($key, ['comparison', 'comparison_type', 'value','getter_params'])) { |
|
78 | + if (!in_array($key, ['comparison', 'comparison_type', 'value', 'getter_params'])) { |
|
79 | 79 | $pra->addExtraData($key, $value); |
80 | 80 | } |
81 | 81 | } |
@@ -28,12 +28,12 @@ discard block |
||
28 | 28 | { |
29 | 29 | $this->attributes = $attributes; |
30 | 30 | |
31 | - $options = array_intersect_key( $options, array_flip( [ |
|
31 | + $options = array_intersect_key($options, array_flip([ |
|
32 | 32 | 'getter_prefix', |
33 | 33 | 'getter_name_transformation_function', |
34 | - ] ) ); |
|
34 | + ])); |
|
35 | 35 | |
36 | - foreach($options as $name => $value) { |
|
36 | + foreach ($options as $name => $value) { |
|
37 | 37 | $this->$name = $value; |
38 | 38 | } |
39 | 39 | } |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | */ |
96 | 96 | public function retrieveAttribute(AbstractAttribute $attribute, $user = null, $object = null, $getter_params = []) |
97 | 97 | { |
98 | - switch($attribute->getType()) { |
|
98 | + switch ($attribute->getType()) { |
|
99 | 99 | case 'user': |
100 | 100 | return $this->retrieveClassicAttribute($attribute, $user, $getter_params); |
101 | 101 | case 'resource': |
@@ -114,18 +114,18 @@ discard block |
||
114 | 114 | { |
115 | 115 | $propertyPath = explode('.', $attribute->getProperty()); |
116 | 116 | $propertyValue = $object; |
117 | - foreach($propertyPath as $property) { |
|
117 | + foreach ($propertyPath as $property) { |
|
118 | 118 | |
119 | 119 | |
120 | - $getter = $this->getter_prefix.call_user_func($this->getter_name_transformation_function,$property); |
|
120 | + $getter = $this->getter_prefix.call_user_func($this->getter_name_transformation_function, $property); |
|
121 | 121 | // Use is_callable, instead of method_exists, to deal with __call magic method |
122 | - if(!is_callable([$propertyValue,$getter])) { |
|
122 | + if (!is_callable([$propertyValue, $getter])) { |
|
123 | 123 | throw new \InvalidArgumentException('There is no getter for the "'.$attribute->getProperty().'" attribute for object "'.get_class($propertyValue).'" with getter "'.$getter.'"'); |
124 | 124 | } |
125 | - if ( ( $propertyValue = call_user_func_array( [ |
|
125 | + if (($propertyValue = call_user_func_array([ |
|
126 | 126 | $propertyValue, |
127 | 127 | $getter, |
128 | - ], isset( $getter_params[ $property ] ) ? $getter_params[ $property ] : [] ) ) === null |
|
128 | + ], isset($getter_params[$property]) ? $getter_params[$property] : [])) === null |
|
129 | 129 | ) { |
130 | 130 | return null; |
131 | 131 | } |
@@ -27,26 +27,26 @@ discard block |
||
27 | 27 | * @param FileLocatorInterface $locator |
28 | 28 | * @param string|array $format A format or an array of format |
29 | 29 | */ |
30 | - public function __construct( FileLocatorInterface $locator, $format = [ |
|
30 | + public function __construct(FileLocatorInterface $locator, $format = [ |
|
31 | 31 | 'yaml', |
32 | 32 | 'json', |
33 | - ] ) { |
|
33 | + ]) { |
|
34 | 34 | $this->locator = $locator; |
35 | 35 | $this->attributes = []; |
36 | 36 | $this->rules = []; |
37 | 37 | $this->config_files_loaded = []; |
38 | - if ( in_array( 'yaml', $format ) ) { |
|
39 | - $this->loaders[ 'yaml' ] = new YamlAbacLoader( $locator, $this ); |
|
38 | + if (in_array('yaml', $format)) { |
|
39 | + $this->loaders['yaml'] = new YamlAbacLoader($locator, $this); |
|
40 | 40 | } |
41 | - if ( in_array( 'json', $format ) ) { |
|
42 | - $this->loaders[ 'json' ] = new JsonAbacLoader( $locator, $this ); |
|
41 | + if (in_array('json', $format)) { |
|
42 | + $this->loaders['json'] = new JsonAbacLoader($locator, $this); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | } |
46 | 46 | |
47 | 47 | public function setConfigPathRoot($configPaths_root = null) { |
48 | 48 | // $this->config_path_route = $configPaths_root; |
49 | - foreach($this->loaders as $loader) { |
|
49 | + foreach ($this->loaders as $loader) { |
|
50 | 50 | $loader->setCurrentDir($configPaths_root); |
51 | 51 | } |
52 | 52 | } |
@@ -54,11 +54,11 @@ discard block |
||
54 | 54 | /** |
55 | 55 | * @param array $configurationFiles |
56 | 56 | */ |
57 | - public function parseConfigurationFile( $configurationFiles ) { |
|
58 | - foreach ( $configurationFiles as $configurationFile ) { |
|
59 | - $config = $this->getLoader( $configurationFile )->import( $configurationFile, pathinfo( $configurationFile, PATHINFO_EXTENSION ) ); |
|
57 | + public function parseConfigurationFile($configurationFiles) { |
|
58 | + foreach ($configurationFiles as $configurationFile) { |
|
59 | + $config = $this->getLoader($configurationFile)->import($configurationFile, pathinfo($configurationFile, PATHINFO_EXTENSION)); |
|
60 | 60 | |
61 | - if (in_array($config['path'],$this->config_files_loaded)) { |
|
61 | + if (in_array($config['path'], $this->config_files_loaded)) { |
|
62 | 62 | continue; |
63 | 63 | } |
64 | 64 | |
@@ -69,11 +69,11 @@ discard block |
||
69 | 69 | unset($config['@import']); |
70 | 70 | } |
71 | 71 | |
72 | - if ( isset( $config[ 'attributes' ] ) ) { |
|
73 | - $this->attributes = array_merge( $this->attributes, $config[ 'attributes' ] ); |
|
72 | + if (isset($config['attributes'])) { |
|
73 | + $this->attributes = array_merge($this->attributes, $config['attributes']); |
|
74 | 74 | } |
75 | - if ( isset( $config[ 'rules' ] ) ) { |
|
76 | - $this->rules = array_merge( $this->rules, $config[ 'rules' ] ); |
|
75 | + if (isset($config['rules'])) { |
|
76 | + $this->rules = array_merge($this->rules, $config['rules']); |
|
77 | 77 | } |
78 | 78 | } |
79 | 79 | } |
@@ -89,14 +89,14 @@ discard block |
||
89 | 89 | * |
90 | 90 | * @throws \Exception |
91 | 91 | */ |
92 | - private function getLoader( $configurationFile ) { |
|
92 | + private function getLoader($configurationFile) { |
|
93 | 93 | |
94 | - foreach ( $this->loaders as $AbacLoader ) { |
|
95 | - if ( $AbacLoader::supportsExtension( $configurationFile ) ) { |
|
94 | + foreach ($this->loaders as $AbacLoader) { |
|
95 | + if ($AbacLoader::supportsExtension($configurationFile)) { |
|
96 | 96 | return $AbacLoader; |
97 | 97 | } |
98 | 98 | } |
99 | - throw new \Exception( 'Loader not found for the file ' . $configurationFile ); |
|
99 | + throw new \Exception('Loader not found for the file '.$configurationFile); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | $item = $pool->getItem($key); |
40 | 40 | |
41 | 41 | // In this case, the pool returned a new CacheItem |
42 | - if($item->get() === null) { |
|
42 | + if ($item->get() === null) { |
|
43 | 43 | $item->expiresAfter($ttl); |
44 | 44 | } |
45 | 45 | return $item; |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | * @return Psr\Cache\CacheItemPoolInterface |
52 | 52 | */ |
53 | 53 | public function getItemPool($driver) { |
54 | - if(!isset($this->pools[$driver])) { |
|
55 | - $poolClass = 'PhpAbac\\Cache\\Pool\\' . ucfirst($driver) . 'CacheItemPool'; |
|
54 | + if (!isset($this->pools[$driver])) { |
|
55 | + $poolClass = 'PhpAbac\\Cache\\Pool\\'.ucfirst($driver).'CacheItemPool'; |
|
56 | 56 | $this->pools[$driver] = new $poolClass($this->options); |
57 | 57 | } |
58 | 58 | return $this->pools[$driver]; |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | $user1Vehicle = $abac->enforce('vehicle-homologation', $users[0], $vehicles[0], [ |
36 | 36 | 'dynamic_attributes' => ['proprietaire' => 1] |
37 | 37 | ]); |
38 | - if($user1Vehicle === true) { |
|
38 | + if ($user1Vehicle === true) { |
|
39 | 39 | echo("GRANTED : The vehicle 1 is able to be approved for the user 1\n"); |
40 | 40 | } else { |
41 | 41 | echo("FAIL : The system didn't grant access\n"); |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | $user3Vehicle = $abac->enforce('vehicle-homologation', $users[2], $vehicles[1], [ |
44 | 44 | 'dynamic_attributes' => ['proprietaire' => 3] |
45 | 45 | ]); |
46 | - if(!$user3Vehicle !== true) { |
|
46 | + if (!$user3Vehicle !== true) { |
|
47 | 47 | echo("DENIED : The vehicle 2 is not approved for the user 3 because its last technical review is too old\n"); |
48 | 48 | } else { |
49 | 49 | echo("FAIL : The system didn't deny access\n"); |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | $user4Vehicle = $abac->enforce('vehicle-homologation', $users[3], $vehicles[3], [ |
52 | 52 | 'dynamic_attributes' => ['proprietaire' => 4] |
53 | 53 | ]); |
54 | - if($user4Vehicle !== true) { |
|
54 | + if ($user4Vehicle !== true) { |
|
55 | 55 | echo("DENIED : The vehicle 4 is not able to be approved for the user 4 because he has no driving license\n"); |
56 | 56 | } else { |
57 | 57 | echo("FAIL : The system didn't deny access\n"); |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | $user5Vehicle = $abac->enforce('vehicle-homologation', $users[3], $vehicles[3], [ |
60 | 60 | 'dynamic_attributes' => ['proprietaire' => 1] |
61 | 61 | ]); |
62 | - if($user5Vehicle !== true) { |
|
62 | + if ($user5Vehicle !== true) { |
|
63 | 63 | echo("DENIED : The vehicle 4 is not able to be approved for the user 2 because he doesn't own the vehicle\n"); |
64 | 64 | } else { |
65 | 65 | echo("FAIL : The system didn't deny access\n"); |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | 'code-pays' => 'US' |
70 | 70 | ] |
71 | 71 | ]); |
72 | - if($userTravel1 !== true) { |
|
72 | + if ($userTravel1 !== true) { |
|
73 | 73 | echo("DENIED: The user 1 is not allowed to travel to the USA because he doesn't have an US visa\n"); |
74 | 74 | } else { |
75 | 75 | echo('FAIL: The system didn\'t deny access'); |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | 'code-pays' => 'US' |
80 | 80 | ] |
81 | 81 | ]); |
82 | - if($userTravel2 === true) { |
|
82 | + if ($userTravel2 === true) { |
|
83 | 83 | echo("GRANTED: The user 2 is allowed to travel to the USA\n"); |
84 | 84 | } else { |
85 | 85 | echo('FAIL: The system didn\'t grant access'); |