1 | <?php |
||
15 | class Abac |
||
16 | { |
||
17 | /** @var \PhpAbac\Manager\ConfigurationManager **/ |
||
18 | private $configuration; |
||
19 | /** @var \PhpAbac\Manager\PolicyRuleManager **/ |
||
20 | private $policyRuleManager; |
||
21 | /** @var \PhpAbac\Manager\AttributeManager **/ |
||
22 | private $attributeManager; |
||
23 | /** @var \PhpAbac\Manager\CacheManager **/ |
||
24 | private $cacheManager; |
||
25 | /** @var \PhpAbac\Manager\ComparisonManager **/ |
||
26 | private $comparisonManager; |
||
27 | |||
28 | /** |
||
29 | * @param array $configPaths |
||
30 | */ |
||
31 | 1 | public function __construct($configPaths) |
|
32 | { |
||
33 | 1 | $this->configure($configPaths); |
|
34 | 1 | $this->attributeManager = new AttributeManager($this->configuration->getAttributes()); |
|
35 | 1 | $this->policyRuleManager = new PolicyRuleManager($this->attributeManager, $this->configuration->getRules()); |
|
36 | 1 | $this->cacheManager = new CacheManager(); |
|
37 | 1 | $this->comparisonManager = new ComparisonManager($this->attributeManager); |
|
38 | 1 | } |
|
39 | |||
40 | /** |
||
41 | * @param array $configPaths |
||
42 | */ |
||
43 | 1 | public function configure($configPaths) { |
|
48 | |||
49 | /** |
||
50 | * Return true if both user and object respects all the rules conditions |
||
51 | * If the objectId is null, policy rules about its attributes will be ignored |
||
52 | * In case of mismatch between attributes and expected values, |
||
53 | * an array with the concerned attributes slugs will be returned. |
||
54 | * |
||
55 | * Available options are : |
||
56 | * * dynamic_attributes: array |
||
57 | * * cache_result: boolean |
||
58 | * * cache_ttl: integer |
||
59 | * * cache_driver: string |
||
60 | * |
||
61 | * Available cache drivers are : |
||
62 | * * memory |
||
63 | * |
||
64 | * @param string $ruleName |
||
65 | * @param object $user |
||
66 | * @param object $resource |
||
67 | * @param array $options |
||
68 | * @return boolean|array |
||
69 | */ |
||
70 | 1 | public function enforce($ruleName, $user, $resource = null, $options = []) { |
|
107 | |||
108 | /** |
||
109 | * @param \PhpAbac\Model\PolicyRuleAttribute $pra |
||
110 | * @param object $user |
||
111 | * @param object $resource |
||
112 | */ |
||
113 | 1 | public function processExtraData(PolicyRuleAttribute $pra, $user, $resource) { |
|
135 | } |
||
136 |