1 | <?php |
||
17 | class Feature implements FeatureInterface |
||
18 | { |
||
19 | /** @var string */ |
||
20 | protected $name; |
||
21 | |||
22 | /** @var VectorInterface */ |
||
23 | protected $conditions; |
||
24 | |||
25 | /** @var int */ |
||
26 | protected $status = ToggleStatus::CONDITIONALLY_ACTIVE; |
||
27 | |||
28 | /** @var int */ |
||
29 | protected $strategy = ToggleStrategy::AFFIRMATIVE; |
||
30 | |||
31 | /** |
||
32 | * Feature constructor. |
||
33 | * @param $name - The name of the feature |
||
34 | * @param VectorInterface $conditions - The conditions to be fulfilled |
||
35 | * @param int $strategy The strategy to decide if the feature is enabled or not |
||
36 | */ |
||
37 | 6 | public function __construct($name, VectorInterface $conditions, $strategy = ToggleStrategy::AFFIRMATIVE) |
|
43 | |||
44 | /** |
||
45 | * @inheritdoc |
||
46 | */ |
||
47 | 5 | public function getName() |
|
51 | |||
52 | /** |
||
53 | * @inheritdoc |
||
54 | */ |
||
55 | public function getStrategy() |
||
59 | |||
60 | /** |
||
61 | * @inheritdoc |
||
62 | */ |
||
63 | public function getStatus() |
||
67 | |||
68 | /** |
||
69 | * @inheritdoc |
||
70 | */ |
||
71 | public function getConditions() |
||
75 | |||
76 | /** |
||
77 | * @inheritdoc |
||
78 | */ |
||
79 | public function activate($status = ToggleStatus::CONDITIONALLY_ACTIVE) |
||
85 | |||
86 | /** |
||
87 | * @inheritdoc |
||
88 | */ |
||
89 | public function deactivate() |
||
95 | |||
96 | /** |
||
97 | * Checks whether the toggle is active for the given context. |
||
98 | * |
||
99 | * @param Context $context |
||
100 | * |
||
101 | * @return boolean True, if one of conditions hold for the context. |
||
102 | */ |
||
103 | 3 | public function activeFor(Context $context) |
|
121 | |||
122 | /** |
||
123 | * @param Context $context |
||
124 | * |
||
125 | * @return bool |
||
126 | */ |
||
127 | 3 | private function atLeastOneConditionHolds(Context $context) |
|
138 | |||
139 | /** |
||
140 | * @param Context $context |
||
141 | * |
||
142 | * @return bool |
||
143 | */ |
||
144 | private function moreThanHalfConditionsHold(Context $context) |
||
156 | |||
157 | /** |
||
158 | * @param Context $context |
||
159 | * |
||
160 | * @return bool |
||
161 | */ |
||
162 | private function allConditionsHold(Context $context) |
||
173 | } |
||
174 |