1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpAbac; |
4
|
|
|
|
5
|
|
|
use PhpAbac\Configuration\ConfigurationInterface; |
6
|
|
|
use PhpAbac\Configuration\Configuration; |
7
|
|
|
|
8
|
|
|
use PhpAbac\Manager\PolicyRuleManager; |
9
|
|
|
use PhpAbac\Manager\PolicyRuleManagerInterface; |
10
|
|
|
use PhpAbac\Manager\AttributeManager; |
11
|
|
|
use PhpAbac\Manager\AttributeManagerInterface; |
12
|
|
|
use PhpAbac\Manager\CacheManager; |
13
|
|
|
use PhpAbac\Manager\CacheManagerInterface; |
14
|
|
|
use PhpAbac\Manager\ComparisonManager; |
15
|
|
|
use PhpAbac\Manager\ComparisonManagerInterface; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
final class AbacFactory |
19
|
|
|
{ |
20
|
|
|
/** @var ConfigurationInterface **/ |
21
|
|
|
protected static $configuration; |
22
|
|
|
/** @var PolicyRuleManagerInterface **/ |
23
|
|
|
protected static $policyRuleManager; |
24
|
|
|
/** @var AttributeManagerInterface **/ |
25
|
|
|
protected static $attributeManager; |
26
|
|
|
/** @var CacheManagerInterface **/ |
27
|
|
|
protected static $cacheManager; |
28
|
|
|
/** @var ComparisonManagerInterface **/ |
29
|
|
|
protected static $comparisonManager; |
30
|
|
|
|
31
|
|
|
public static function setConfiguration(ConfigurationInterface $configuration) |
32
|
|
|
{ |
33
|
|
|
self::$configuration = $configuration; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public static function setPolicyRuleManager(PolicyRuleManagerInterface $policyRuleManager) |
37
|
|
|
{ |
38
|
|
|
self::$policyRuleManager = $policyRuleManager; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public static function setAttributeManager(AttributeManagerInterface $attributeManager) |
42
|
|
|
{ |
43
|
|
|
self::$attributeManager = $attributeManager; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public static function setCacheManager(CacheManagerInterface $cacheManager) |
47
|
|
|
{ |
48
|
|
|
self::$cacheManager = $cacheManager; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public static function setComparisonManager(ComparisonManagerInterface $comparisonManager) |
52
|
|
|
{ |
53
|
|
|
self::$comparisonManager = $comparisonManager; |
54
|
|
|
} |
55
|
|
|
|
56
|
4 |
|
public static function getAbac(array $configurationFiles, string $configDir = null, array $attributeOptions = [], array $cacheOptions = []) |
57
|
|
|
{ |
58
|
4 |
|
$configuration = (self::$configuration !== null) ? self::$configuration : new Configuration($configurationFiles, $configDir); |
59
|
4 |
|
$attributeManager = (self::$attributeManager !== null) ? self::$attributeManager : new AttributeManager($configuration, $attributeOptions); |
|
|
|
|
60
|
4 |
|
$policyRuleManager = (self::$policyRuleManager !== null) ? self::$policyRuleManager : new PolicyRuleManager($configuration, $attributeManager); |
|
|
|
|
61
|
4 |
|
$comparisonManager = (self::$comparisonManager !== null) ? self::$comparisonManager : new ComparisonManager($attributeManager); |
|
|
|
|
62
|
4 |
|
$cacheManager = (self::$cacheManager !== null) ? self::$cacheManager : new CacheManager($cacheOptions); |
63
|
|
|
|
64
|
4 |
|
return new Abac($policyRuleManager, $attributeManager, $comparisonManager, $cacheManager); |
|
|
|
|
65
|
|
|
} |
66
|
|
|
} |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.