1 | <?php |
||
10 | class Features |
||
11 | { |
||
12 | /** |
||
13 | * Features collections. |
||
14 | * |
||
15 | * @var array |
||
16 | */ |
||
17 | protected $features = []; |
||
18 | |||
19 | |||
20 | /** |
||
21 | * Create a new feature |
||
22 | * |
||
23 | * @param string $name Feature identifier. |
||
24 | * @param string $description Feature description |
||
25 | * @param array $strategies array of strategies |
||
26 | * |
||
27 | * @return StrategyCollection |
||
28 | */ |
||
29 | public function create($name, $description = '', $strategies = []) |
||
42 | |||
43 | |||
44 | /** |
||
45 | * Adds strategy to feature |
||
46 | * |
||
47 | * @param string $feature Feature identifier |
||
48 | * @param string $strategyName Strategy name |
||
49 | * @param string|callable|StrategyInterface $strategy Strategy class or closure |
||
50 | * @param array $args |
||
51 | */ |
||
52 | public function pushStrategy($feature, $strategyName, $strategy = null, $args = []) |
||
59 | |||
60 | |||
61 | /** |
||
62 | * Get Collection by feature name |
||
63 | * |
||
64 | * @param string $name Feature identifier |
||
65 | * |
||
66 | * @return StrategyCollection |
||
67 | */ |
||
68 | public function getCollection($name) |
||
72 | |||
73 | |||
74 | /** |
||
75 | * Checks if a feature with given name exists. |
||
76 | * |
||
77 | * @param string $name Feature identifier. |
||
78 | * |
||
79 | * @return bool |
||
80 | */ |
||
81 | public function exists($name) |
||
85 | |||
86 | |||
87 | /** |
||
88 | * Flush all features. |
||
89 | */ |
||
90 | public function flush() |
||
94 | |||
95 | |||
96 | /** |
||
97 | * Get Feature or item from feature array |
||
98 | * |
||
99 | * @param string $name |
||
100 | * @param null|string $key |
||
101 | * |
||
102 | * @return |
||
103 | */ |
||
104 | public function get($name, $key = null) |
||
112 | |||
113 | |||
114 | /** |
||
115 | * Check if feature is enabled |
||
116 | * |
||
117 | * @param string $feature Feature identifier |
||
118 | * @param array $args arguments passed to strategies checker |
||
119 | * |
||
120 | * @return bool |
||
121 | */ |
||
122 | public function isEnabled($feature, array $args = []) |
||
126 | |||
127 | |||
128 | /** |
||
129 | * Set the feature's threshold |
||
130 | * |
||
131 | * @param string $name Feature identifier |
||
132 | * @param int $threshold |
||
133 | * |
||
134 | * @return $this |
||
135 | */ |
||
136 | public function setThreshold($name, $threshold = 1) |
||
142 | } |
||
143 |