@@ -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 = []; |
@@ -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 |
@@ -13,165 +13,165 @@ |
||
13 | 13 | use PhpAbac\Model\PolicyRuleAttribute; |
14 | 14 | |
15 | 15 | class Abac { |
16 | - /** @var \PhpAbac\Manager\ConfigurationManager * */ |
|
17 | - private $configuration; |
|
18 | - /** @var \PhpAbac\Manager\PolicyRuleManager * */ |
|
19 | - private $policyRuleManager; |
|
20 | - /** @var \PhpAbac\Manager\AttributeManager * */ |
|
21 | - private $attributeManager; |
|
22 | - /** @var \PhpAbac\Manager\CacheManager * */ |
|
23 | - private $cacheManager; |
|
24 | - /** @var \PhpAbac\Manager\ComparisonManager * */ |
|
25 | - private $comparisonManager; |
|
16 | + /** @var \PhpAbac\Manager\ConfigurationManager * */ |
|
17 | + private $configuration; |
|
18 | + /** @var \PhpAbac\Manager\PolicyRuleManager * */ |
|
19 | + private $policyRuleManager; |
|
20 | + /** @var \PhpAbac\Manager\AttributeManager * */ |
|
21 | + private $attributeManager; |
|
22 | + /** @var \PhpAbac\Manager\CacheManager * */ |
|
23 | + private $cacheManager; |
|
24 | + /** @var \PhpAbac\Manager\ComparisonManager * */ |
|
25 | + private $comparisonManager; |
|
26 | 26 | |
27 | - /** |
|
28 | - * @param array $configPaths |
|
29 | - * @param array $cacheOptions Option for cache |
|
30 | - * @param string $configPaths_root The origin folder to find $configPaths |
|
31 | - * @param array $options |
|
32 | - */ |
|
33 | - public function __construct( $configPaths, $cacheOptions = [], $configPaths_root = null, $options = [] ) { |
|
34 | - $this->configure( $configPaths, $configPaths_root ); |
|
35 | - $this->attributeManager = new AttributeManager( $this->configuration->getAttributes(), $options ); |
|
36 | - $this->policyRuleManager = new PolicyRuleManager( $this->attributeManager, $this->configuration->getRules() ); |
|
37 | - $this->cacheManager = new CacheManager( $cacheOptions ); |
|
38 | - $this->comparisonManager = new ComparisonManager( $this->attributeManager ); |
|
39 | - } |
|
27 | + /** |
|
28 | + * @param array $configPaths |
|
29 | + * @param array $cacheOptions Option for cache |
|
30 | + * @param string $configPaths_root The origin folder to find $configPaths |
|
31 | + * @param array $options |
|
32 | + */ |
|
33 | + public function __construct( $configPaths, $cacheOptions = [], $configPaths_root = null, $options = [] ) { |
|
34 | + $this->configure( $configPaths, $configPaths_root ); |
|
35 | + $this->attributeManager = new AttributeManager( $this->configuration->getAttributes(), $options ); |
|
36 | + $this->policyRuleManager = new PolicyRuleManager( $this->attributeManager, $this->configuration->getRules() ); |
|
37 | + $this->cacheManager = new CacheManager( $cacheOptions ); |
|
38 | + $this->comparisonManager = new ComparisonManager( $this->attributeManager ); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param array $configPaths |
|
43 | - * @param string $configPaths_root The origin folder to find $configPaths |
|
44 | - */ |
|
45 | - public function configure( $configPaths, $configPaths_root = null ) { |
|
41 | + /** |
|
42 | + * @param array $configPaths |
|
43 | + * @param string $configPaths_root The origin folder to find $configPaths |
|
44 | + */ |
|
45 | + public function configure( $configPaths, $configPaths_root = null ) { |
|
46 | 46 | // foreach ( $configPaths as &$configPath ) { |
47 | 47 | // $configPath = $configPaths_root . $configPath; |
48 | 48 | // } |
49 | - $locator = new FileLocator( $configPaths_root ); |
|
50 | - $this->configuration = new ConfigurationManager( $locator ); |
|
51 | - $this->configuration->setConfigPathRoot( $configPaths_root ); |
|
52 | - $this->configuration->parseConfigurationFile( $configPaths ); |
|
53 | - } |
|
49 | + $locator = new FileLocator( $configPaths_root ); |
|
50 | + $this->configuration = new ConfigurationManager( $locator ); |
|
51 | + $this->configuration->setConfigPathRoot( $configPaths_root ); |
|
52 | + $this->configuration->parseConfigurationFile( $configPaths ); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Return true if both user and object respects all the rules conditions |
|
57 | - * If the objectId is null, policy rules about its attributes will be ignored |
|
58 | - * In case of mismatch between attributes and expected values, |
|
59 | - * an array with the concerned attributes slugs will be returned. |
|
60 | - * |
|
61 | - * Available options are : |
|
62 | - * * dynamic_attributes: array |
|
63 | - * * cache_result: boolean |
|
64 | - * * cache_ttl: integer |
|
65 | - * * cache_driver: string |
|
66 | - * |
|
67 | - * Available cache drivers are : |
|
68 | - * * memory |
|
69 | - * |
|
70 | - * @param string $ruleName |
|
71 | - * @param object $user |
|
72 | - * @param object $resource |
|
73 | - * @param array $options |
|
74 | - * |
|
75 | - * @return boolean|array |
|
76 | - */ |
|
77 | - public function enforce( $ruleName, $user, $resource = null, $options = [] ) { |
|
78 | - // If there is dynamic attributes, we pass them to the comparison manager |
|
79 | - // When a comparison will be performed, the passed values will be retrieved and used |
|
80 | - if ( isset( $options[ 'dynamic_attributes' ] ) ) { |
|
81 | - $this->comparisonManager->setDynamicAttributes( $options[ 'dynamic_attributes' ] ); |
|
82 | - } |
|
83 | - // Retrieve cache value for the current rule and values if cache item is valid |
|
84 | - if ( ( $cacheResult = isset( $options[ 'cache_result' ] ) && $options[ 'cache_result' ] === true ) === true ) { |
|
85 | - $cacheItem = $this->cacheManager->getItem( "$ruleName-{$user->getId()}-" . ( ( $resource !== null ) ? $resource->getId() : '' ), ( isset( $options[ 'cache_driver' ] ) ) ? $options[ 'cache_driver' ] : null, ( isset( $options[ 'cache_ttl' ] ) ) ? $options[ 'cache_ttl' ] : null ); |
|
86 | - // We check if the cache value s valid before returning it |
|
87 | - if ( ( $cacheValue = $cacheItem->get() ) !== null ) { |
|
88 | - return $cacheValue; |
|
89 | - } |
|
90 | - } |
|
91 | - $policyRule_a = $this->policyRuleManager->getRule( $ruleName, $user, $resource ); |
|
55 | + /** |
|
56 | + * Return true if both user and object respects all the rules conditions |
|
57 | + * If the objectId is null, policy rules about its attributes will be ignored |
|
58 | + * In case of mismatch between attributes and expected values, |
|
59 | + * an array with the concerned attributes slugs will be returned. |
|
60 | + * |
|
61 | + * Available options are : |
|
62 | + * * dynamic_attributes: array |
|
63 | + * * cache_result: boolean |
|
64 | + * * cache_ttl: integer |
|
65 | + * * cache_driver: string |
|
66 | + * |
|
67 | + * Available cache drivers are : |
|
68 | + * * memory |
|
69 | + * |
|
70 | + * @param string $ruleName |
|
71 | + * @param object $user |
|
72 | + * @param object $resource |
|
73 | + * @param array $options |
|
74 | + * |
|
75 | + * @return boolean|array |
|
76 | + */ |
|
77 | + public function enforce( $ruleName, $user, $resource = null, $options = [] ) { |
|
78 | + // If there is dynamic attributes, we pass them to the comparison manager |
|
79 | + // When a comparison will be performed, the passed values will be retrieved and used |
|
80 | + if ( isset( $options[ 'dynamic_attributes' ] ) ) { |
|
81 | + $this->comparisonManager->setDynamicAttributes( $options[ 'dynamic_attributes' ] ); |
|
82 | + } |
|
83 | + // Retrieve cache value for the current rule and values if cache item is valid |
|
84 | + if ( ( $cacheResult = isset( $options[ 'cache_result' ] ) && $options[ 'cache_result' ] === true ) === true ) { |
|
85 | + $cacheItem = $this->cacheManager->getItem( "$ruleName-{$user->getId()}-" . ( ( $resource !== null ) ? $resource->getId() : '' ), ( isset( $options[ 'cache_driver' ] ) ) ? $options[ 'cache_driver' ] : null, ( isset( $options[ 'cache_ttl' ] ) ) ? $options[ 'cache_ttl' ] : null ); |
|
86 | + // We check if the cache value s valid before returning it |
|
87 | + if ( ( $cacheValue = $cacheItem->get() ) !== null ) { |
|
88 | + return $cacheValue; |
|
89 | + } |
|
90 | + } |
|
91 | + $policyRule_a = $this->policyRuleManager->getRule( $ruleName, $user, $resource ); |
|
92 | 92 | |
93 | - foreach ( $policyRule_a as $policyRule ) { |
|
94 | - // For each policy rule attribute, we retrieve the attribute value and proceed configured extra data |
|
95 | - foreach ( $policyRule->getPolicyRuleAttributes() as $pra ) { |
|
96 | - /** @var PolicyRuleAttribute $pra */ |
|
97 | - $attribute = $pra->getAttribute(); |
|
93 | + foreach ( $policyRule_a as $policyRule ) { |
|
94 | + // For each policy rule attribute, we retrieve the attribute value and proceed configured extra data |
|
95 | + foreach ( $policyRule->getPolicyRuleAttributes() as $pra ) { |
|
96 | + /** @var PolicyRuleAttribute $pra */ |
|
97 | + $attribute = $pra->getAttribute(); |
|
98 | 98 | |
99 | - $getter_params = $this->prepareGetterParams($pra->getGetterParams(), $user, $resource); |
|
99 | + $getter_params = $this->prepareGetterParams($pra->getGetterParams(), $user, $resource); |
|
100 | 100 | // var_dump($pra->getGetterParams()); |
101 | 101 | // var_dump($getter_params); |
102 | - $attribute->setValue( $this->attributeManager->retrieveAttribute( $attribute, $user, $resource, $getter_params ) ); |
|
103 | - if ( count( $pra->getExtraData() ) > 0 ) { |
|
104 | - $this->processExtraData( $pra, $user, $resource ); |
|
105 | - } |
|
106 | - $this->comparisonManager->compare( $pra ); |
|
107 | - } |
|
108 | - // The given result could be an array of rejected attributes or true |
|
109 | - // True means that the rule is correctly enforced for the given user and resource |
|
110 | - $result = $this->comparisonManager->getResult(); |
|
111 | - if ( true === $result ) { |
|
112 | - break; |
|
113 | - } |
|
114 | - } |
|
115 | - if ( $cacheResult ) { |
|
116 | - $cacheItem->set( $result ); |
|
117 | - $this->cacheManager->save( $cacheItem ); |
|
118 | - } |
|
102 | + $attribute->setValue( $this->attributeManager->retrieveAttribute( $attribute, $user, $resource, $getter_params ) ); |
|
103 | + if ( count( $pra->getExtraData() ) > 0 ) { |
|
104 | + $this->processExtraData( $pra, $user, $resource ); |
|
105 | + } |
|
106 | + $this->comparisonManager->compare( $pra ); |
|
107 | + } |
|
108 | + // The given result could be an array of rejected attributes or true |
|
109 | + // True means that the rule is correctly enforced for the given user and resource |
|
110 | + $result = $this->comparisonManager->getResult(); |
|
111 | + if ( true === $result ) { |
|
112 | + break; |
|
113 | + } |
|
114 | + } |
|
115 | + if ( $cacheResult ) { |
|
116 | + $cacheItem->set( $result ); |
|
117 | + $this->cacheManager->save( $cacheItem ); |
|
118 | + } |
|
119 | 119 | |
120 | - return $result; |
|
121 | - } |
|
120 | + return $result; |
|
121 | + } |
|
122 | 122 | |
123 | - /** |
|
124 | - * Function to prepare Getter Params when getter require parameters ( this parameters must be specified in configuration file) |
|
125 | - * |
|
126 | - * @param $getter_params |
|
127 | - * @param $user |
|
128 | - * @param $resource |
|
129 | - * |
|
130 | - * @return array |
|
131 | - */ |
|
132 | - private function prepareGetterParams($getter_params, $user, $resource) { |
|
133 | - if (empty($getter_params)) return []; |
|
134 | - $values = []; |
|
135 | - foreach($getter_params as $getter_name=>$params) { |
|
136 | - foreach($params as $param) { |
|
137 | - if ( '@' !== $param[ 'param_name' ][ 0 ] ) { |
|
138 | - $values[$getter_name][] = $param[ 'param_value' ]; |
|
139 | - } |
|
140 | - else { |
|
141 | - $values[$getter_name][] = $this->attributeManager->retrieveAttribute( $this->attributeManager->getAttribute( $param[ 'param_value' ] ) , $user, $resource ); |
|
142 | - } |
|
143 | - } |
|
144 | - } |
|
145 | - return $values; |
|
146 | - } |
|
123 | + /** |
|
124 | + * Function to prepare Getter Params when getter require parameters ( this parameters must be specified in configuration file) |
|
125 | + * |
|
126 | + * @param $getter_params |
|
127 | + * @param $user |
|
128 | + * @param $resource |
|
129 | + * |
|
130 | + * @return array |
|
131 | + */ |
|
132 | + private function prepareGetterParams($getter_params, $user, $resource) { |
|
133 | + if (empty($getter_params)) return []; |
|
134 | + $values = []; |
|
135 | + foreach($getter_params as $getter_name=>$params) { |
|
136 | + foreach($params as $param) { |
|
137 | + if ( '@' !== $param[ 'param_name' ][ 0 ] ) { |
|
138 | + $values[$getter_name][] = $param[ 'param_value' ]; |
|
139 | + } |
|
140 | + else { |
|
141 | + $values[$getter_name][] = $this->attributeManager->retrieveAttribute( $this->attributeManager->getAttribute( $param[ 'param_value' ] ) , $user, $resource ); |
|
142 | + } |
|
143 | + } |
|
144 | + } |
|
145 | + return $values; |
|
146 | + } |
|
147 | 147 | |
148 | - /** |
|
149 | - * @param \PhpAbac\Model\PolicyRuleAttribute $pra |
|
150 | - * @param object $user |
|
151 | - * @param object $resource |
|
152 | - */ |
|
153 | - public function processExtraData( PolicyRuleAttribute $pra, $user, $resource ) { |
|
154 | - foreach ( $pra->getExtraData() as $key => $data ) { |
|
155 | - switch ( $key ) { |
|
156 | - case 'with': |
|
157 | - // This data has to be removed for it will be stored elsewhere |
|
158 | - // in the policy rule attribute |
|
159 | - $pra->removeExtraData( 'with' ); |
|
160 | - // The "with" extra data is an array of attributes, which are objects |
|
161 | - // Once we process it as policy rule attributes, we set it as the main policy rule attribute value |
|
162 | - $subPolicyRuleAttributes = []; |
|
163 | - $extraData = []; |
|
148 | + /** |
|
149 | + * @param \PhpAbac\Model\PolicyRuleAttribute $pra |
|
150 | + * @param object $user |
|
151 | + * @param object $resource |
|
152 | + */ |
|
153 | + public function processExtraData( PolicyRuleAttribute $pra, $user, $resource ) { |
|
154 | + foreach ( $pra->getExtraData() as $key => $data ) { |
|
155 | + switch ( $key ) { |
|
156 | + case 'with': |
|
157 | + // This data has to be removed for it will be stored elsewhere |
|
158 | + // in the policy rule attribute |
|
159 | + $pra->removeExtraData( 'with' ); |
|
160 | + // The "with" extra data is an array of attributes, which are objects |
|
161 | + // Once we process it as policy rule attributes, we set it as the main policy rule attribute value |
|
162 | + $subPolicyRuleAttributes = []; |
|
163 | + $extraData = []; |
|
164 | 164 | |
165 | - foreach ( $this->policyRuleManager->processRuleAttributes( $data, $user, $resource ) as $subPolicyRuleAttribute ) { |
|
166 | - $subPolicyRuleAttributes[] = $subPolicyRuleAttribute; |
|
167 | - } |
|
168 | - $pra->setValue( $subPolicyRuleAttributes ); |
|
169 | - // This data can be used in complex comparisons |
|
170 | - $pra->addExtraData( 'attribute', $pra->getAttribute() ); |
|
171 | - $pra->addExtraData( 'user', $user ); |
|
172 | - $pra->addExtraData( 'resource', $resource ); |
|
173 | - break; |
|
174 | - } |
|
175 | - } |
|
176 | - } |
|
165 | + foreach ( $this->policyRuleManager->processRuleAttributes( $data, $user, $resource ) as $subPolicyRuleAttribute ) { |
|
166 | + $subPolicyRuleAttributes[] = $subPolicyRuleAttribute; |
|
167 | + } |
|
168 | + $pra->setValue( $subPolicyRuleAttributes ); |
|
169 | + // This data can be used in complex comparisons |
|
170 | + $pra->addExtraData( 'attribute', $pra->getAttribute() ); |
|
171 | + $pra->addExtraData( 'user', $user ); |
|
172 | + $pra->addExtraData( 'resource', $resource ); |
|
173 | + break; |
|
174 | + } |
|
175 | + } |
|
176 | + } |
|
177 | 177 | } |
@@ -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 | ?> |
@@ -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 | } |
@@ -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) |
@@ -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 |
@@ -19,23 +19,23 @@ discard block |
||
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @param array $attributes |
22 | - * @param array $options A List of option to configure This Abac Instance |
|
23 | - * Options list : |
|
24 | - * 'getter_prefix' => Prefix to add before getter name (default)'get' |
|
25 | - * 'getter_name_transformation_function' => Function to apply on the getter name ( before adding prefix ) (default)'ucfirst' |
|
22 | + * @param array $options A List of option to configure This Abac Instance |
|
23 | + * Options list : |
|
24 | + * 'getter_prefix' => Prefix to add before getter name (default)'get' |
|
25 | + * 'getter_name_transformation_function' => Function to apply on the getter name ( before adding prefix ) (default)'ucfirst' |
|
26 | 26 | */ |
27 | 27 | public function __construct($attributes, $options = []) |
28 | 28 | { |
29 | 29 | $this->attributes = $attributes; |
30 | 30 | |
31 | - $options = array_intersect_key( $options, array_flip( [ |
|
32 | - 'getter_prefix', |
|
33 | - 'getter_name_transformation_function', |
|
34 | - ] ) ); |
|
31 | + $options = array_intersect_key( $options, array_flip( [ |
|
32 | + 'getter_prefix', |
|
33 | + 'getter_name_transformation_function', |
|
34 | + ] ) ); |
|
35 | 35 | |
36 | - foreach($options as $name => $value) { |
|
37 | - $this->$name = $value; |
|
38 | - } |
|
36 | + foreach($options as $name => $value) { |
|
37 | + $this->$name = $value; |
|
38 | + } |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
@@ -117,18 +117,18 @@ discard block |
||
117 | 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 | 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( [ |
|
126 | - $propertyValue, |
|
127 | - $getter, |
|
128 | - ], isset( $getter_params[ $property ] ) ? $getter_params[ $property ] : [] ) ) === null |
|
129 | - ) { |
|
130 | - return null; |
|
131 | - } |
|
125 | + if ( ( $propertyValue = call_user_func_array( [ |
|
126 | + $propertyValue, |
|
127 | + $getter, |
|
128 | + ], isset( $getter_params[ $property ] ) ? $getter_params[ $property ] : [] ) ) === null |
|
129 | + ) { |
|
130 | + return null; |
|
131 | + } |
|
132 | 132 | } |
133 | 133 | return $propertyValue; |
134 | 134 | } |
@@ -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 |