@@ -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 | /** |
@@ -44,6 +44,9 @@ |
||
44 | 44 | |
45 | 45 | } |
46 | 46 | |
47 | + /** |
|
48 | + * @param string $configPaths_root |
|
49 | + */ |
|
47 | 50 | public function setConfigPathRoot($configPaths_root = null) { |
48 | 51 | // $this->config_path_route = $configPaths_root; |
49 | 52 | foreach($this->loaders as $loader) { |
@@ -6,7 +6,6 @@ |
||
6 | 6 | use PhpAbac\Manager\PolicyRuleManager; |
7 | 7 | use PhpAbac\Manager\ConfigurationManager; |
8 | 8 | use PhpAbac\Manager\CacheManager; |
9 | - |
|
10 | 9 | use Symfony\Component\Config\FileLocator; |
11 | 10 | |
12 | 11 | class Abac |
@@ -9,107 +9,107 @@ |
||
9 | 9 | use Symfony\Component\Config\FileLocatorInterface; |
10 | 10 | |
11 | 11 | class ConfigurationManager { |
12 | - /** @var FileLocatorInterface * */ |
|
13 | - protected $locator; |
|
14 | - /** @var AbacLoader[] * */ |
|
15 | - protected $loaders; |
|
16 | - /** @var array * */ |
|
17 | - protected $rules; |
|
18 | - /** @var array * */ |
|
19 | - protected $attributes; |
|
12 | + /** @var FileLocatorInterface * */ |
|
13 | + protected $locator; |
|
14 | + /** @var AbacLoader[] * */ |
|
15 | + protected $loaders; |
|
16 | + /** @var array * */ |
|
17 | + protected $rules; |
|
18 | + /** @var array * */ |
|
19 | + protected $attributes; |
|
20 | 20 | |
21 | 21 | // protected $config_path_route; |
22 | 22 | |
23 | - /** @var array List of File Already Loader */ |
|
24 | - protected $config_files_loaded; |
|
23 | + /** @var array List of File Already Loader */ |
|
24 | + protected $config_files_loaded; |
|
25 | 25 | |
26 | - /** |
|
27 | - * @param FileLocatorInterface $locator |
|
28 | - * @param string|array $format A format or an array of format |
|
29 | - */ |
|
30 | - public function __construct( FileLocatorInterface $locator, $format = [ |
|
31 | - 'yaml', |
|
32 | - 'json', |
|
33 | - ] ) { |
|
34 | - $this->locator = $locator; |
|
35 | - $this->attributes = []; |
|
36 | - $this->rules = []; |
|
37 | - $this->config_files_loaded = []; |
|
38 | - if ( in_array( 'yaml', $format ) ) { |
|
39 | - $this->loaders[ 'yaml' ] = new YamlAbacLoader( $locator, $this ); |
|
40 | - } |
|
41 | - if ( in_array( 'json', $format ) ) { |
|
42 | - $this->loaders[ 'json' ] = new JsonAbacLoader( $locator, $this ); |
|
43 | - } |
|
26 | + /** |
|
27 | + * @param FileLocatorInterface $locator |
|
28 | + * @param string|array $format A format or an array of format |
|
29 | + */ |
|
30 | + public function __construct( FileLocatorInterface $locator, $format = [ |
|
31 | + 'yaml', |
|
32 | + 'json', |
|
33 | + ] ) { |
|
34 | + $this->locator = $locator; |
|
35 | + $this->attributes = []; |
|
36 | + $this->rules = []; |
|
37 | + $this->config_files_loaded = []; |
|
38 | + if ( in_array( 'yaml', $format ) ) { |
|
39 | + $this->loaders[ 'yaml' ] = new YamlAbacLoader( $locator, $this ); |
|
40 | + } |
|
41 | + if ( in_array( 'json', $format ) ) { |
|
42 | + $this->loaders[ 'json' ] = new JsonAbacLoader( $locator, $this ); |
|
43 | + } |
|
44 | 44 | |
45 | - } |
|
45 | + } |
|
46 | 46 | |
47 | - public function setConfigPathRoot($configPaths_root = null) { |
|
47 | + public function setConfigPathRoot($configPaths_root = null) { |
|
48 | 48 | // $this->config_path_route = $configPaths_root; |
49 | - foreach($this->loaders as $loader) { |
|
50 | - $loader->setCurrentDir($configPaths_root); |
|
51 | - } |
|
52 | - } |
|
49 | + foreach($this->loaders as $loader) { |
|
50 | + $loader->setCurrentDir($configPaths_root); |
|
51 | + } |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @param array $configurationFiles |
|
56 | - */ |
|
57 | - public function parseConfigurationFile( $configurationFiles ) { |
|
58 | - foreach ( $configurationFiles as $configurationFile ) { |
|
59 | - $config = $this->getLoader( $configurationFile )->import( $configurationFile, pathinfo( $configurationFile, PATHINFO_EXTENSION ) ); |
|
54 | + /** |
|
55 | + * @param array $configurationFiles |
|
56 | + */ |
|
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)) { |
|
62 | - continue; |
|
63 | - } |
|
61 | + if (in_array($config['path'],$this->config_files_loaded)) { |
|
62 | + continue; |
|
63 | + } |
|
64 | 64 | |
65 | - $this->config_files_loaded[] = $config['path']; |
|
65 | + $this->config_files_loaded[] = $config['path']; |
|
66 | 66 | |
67 | - if (isset($config['@import'])) { |
|
68 | - $this->parseConfigurationFile($config['@import']); |
|
69 | - unset($config['@import']); |
|
70 | - } |
|
67 | + if (isset($config['@import'])) { |
|
68 | + $this->parseConfigurationFile($config['@import']); |
|
69 | + unset($config['@import']); |
|
70 | + } |
|
71 | 71 | |
72 | - if ( isset( $config[ 'attributes' ] ) ) { |
|
73 | - $this->attributes = array_merge( $this->attributes, $config[ 'attributes' ] ); |
|
74 | - } |
|
75 | - if ( isset( $config[ 'rules' ] ) ) { |
|
76 | - $this->rules = array_merge( $this->rules, $config[ 'rules' ] ); |
|
77 | - } |
|
78 | - } |
|
79 | - } |
|
72 | + if ( isset( $config[ 'attributes' ] ) ) { |
|
73 | + $this->attributes = array_merge( $this->attributes, $config[ 'attributes' ] ); |
|
74 | + } |
|
75 | + if ( isset( $config[ 'rules' ] ) ) { |
|
76 | + $this->rules = array_merge( $this->rules, $config[ 'rules' ] ); |
|
77 | + } |
|
78 | + } |
|
79 | + } |
|
80 | 80 | |
81 | 81 | |
82 | 82 | |
83 | - /** |
|
84 | - * Function to retrieve the good loader for the configuration file |
|
85 | - * |
|
86 | - * @param $configurationFile |
|
87 | - * |
|
88 | - * @return AbacLoader |
|
89 | - * |
|
90 | - * @throws \Exception |
|
91 | - */ |
|
92 | - private function getLoader( $configurationFile ) { |
|
83 | + /** |
|
84 | + * Function to retrieve the good loader for the configuration file |
|
85 | + * |
|
86 | + * @param $configurationFile |
|
87 | + * |
|
88 | + * @return AbacLoader |
|
89 | + * |
|
90 | + * @throws \Exception |
|
91 | + */ |
|
92 | + private function getLoader( $configurationFile ) { |
|
93 | 93 | |
94 | - foreach ( $this->loaders as $AbacLoader ) { |
|
95 | - if ( $AbacLoader::supportsExtension( $configurationFile ) ) { |
|
96 | - return $AbacLoader; |
|
97 | - } |
|
98 | - } |
|
99 | - throw new \Exception( 'Loader not found for the file ' . $configurationFile ); |
|
100 | - } |
|
94 | + foreach ( $this->loaders as $AbacLoader ) { |
|
95 | + if ( $AbacLoader::supportsExtension( $configurationFile ) ) { |
|
96 | + return $AbacLoader; |
|
97 | + } |
|
98 | + } |
|
99 | + throw new \Exception( 'Loader not found for the file ' . $configurationFile ); |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * @return array |
|
104 | - */ |
|
105 | - public function getAttributes() { |
|
106 | - return $this->attributes; |
|
107 | - } |
|
102 | + /** |
|
103 | + * @return array |
|
104 | + */ |
|
105 | + public function getAttributes() { |
|
106 | + return $this->attributes; |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * @return array |
|
111 | - */ |
|
112 | - public function getRules() { |
|
113 | - return $this->rules; |
|
114 | - } |
|
109 | + /** |
|
110 | + * @return array |
|
111 | + */ |
|
112 | + public function getRules() { |
|
113 | + return $this->rules; |
|
114 | + } |
|
115 | 115 | } |
116 | 116 | \ No newline at end of file |
@@ -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 | /** |
@@ -6,12 +6,12 @@ |
||
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 | { |
13 | - // $path_to_load = $this->locator->locate($resource); |
|
14 | - $path_to_load = $resource; |
|
13 | + // $path_to_load = $this->locator->locate($resource); |
|
14 | + $path_to_load = $resource; |
|
15 | 15 | |
16 | 16 | return Yaml::parse(file_get_contents($path_to_load)) + ['path' => $path_to_load]; |
17 | 17 | } |
@@ -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 | { |
@@ -7,14 +7,14 @@ |
||
7 | 7 | |
8 | 8 | class JsonAbacLoader extends AbacLoader |
9 | 9 | { |
10 | - protected static $_EXTENSION_ALLOWED_A = ['json']; |
|
10 | + protected static $_EXTENSION_ALLOWED_A = ['json']; |
|
11 | 11 | |
12 | 12 | public function load($resource, $type = null) |
13 | 13 | { |
14 | 14 | // $path_to_load = $this->locator->locate($resource); |
15 | - $path_to_load = $resource; |
|
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) |
@@ -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) |
@@ -70,7 +70,7 @@ |
||
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 |
@@ -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 | } |