1 | <?php |
||
15 | abstract class RolloutAbstract |
||
16 | { |
||
17 | /** |
||
18 | * @var KeyValueStorageInterface |
||
19 | */ |
||
20 | protected $storage; |
||
21 | |||
22 | /** |
||
23 | * @var FeatureFactoryAbstract |
||
24 | */ |
||
25 | protected $featureFactory; |
||
26 | |||
27 | /** |
||
28 | * @param string $featureName |
||
29 | * @return RolloutableInterface |
||
30 | */ |
||
31 | public function getFeature($featureName) |
||
40 | |||
41 | /** |
||
42 | * Get all feature names |
||
43 | * @return string[] |
||
44 | */ |
||
45 | public function getFeatures() |
||
51 | |||
52 | /** |
||
53 | * Saves a feature to the storage |
||
54 | * @param RolloutableInterface $feature |
||
55 | */ |
||
56 | protected function saveFeature(RolloutableInterface $feature) |
||
65 | |||
66 | /** |
||
67 | * Get the storage key for a feature name |
||
68 | * @param string $featureName |
||
69 | * @return string |
||
70 | */ |
||
71 | protected function getKey($featureName) |
||
75 | |||
76 | /** |
||
77 | * Get the storage key for all features (the feature list) |
||
78 | * @return string |
||
79 | */ |
||
80 | protected function getFeaturesKey() |
||
84 | |||
85 | /** |
||
86 | * Activates a feature (for everyone) |
||
87 | * @param string $featureName |
||
88 | */ |
||
89 | public function activate($featureName) |
||
95 | |||
96 | /** |
||
97 | * Deactivates a feature (for everyone) |
||
98 | * @param string $featureName |
||
99 | */ |
||
100 | public function deactivate($featureName) |
||
106 | |||
107 | /** |
||
108 | * Activates a feature for a specific role |
||
109 | * @param string $featureName |
||
110 | * @param string $roleName |
||
111 | */ |
||
112 | public function activateRole($featureName, $roleName) |
||
118 | |||
119 | /** |
||
120 | * Deactivates a feature for a specific role. |
||
121 | * @param string $featureName |
||
122 | * @param string $roleName |
||
123 | */ |
||
124 | public function deactivateRole($featureName, $roleName) |
||
130 | |||
131 | /** |
||
132 | * Activates a feature for a specific group |
||
133 | * @param string $featureName |
||
134 | * @param string $groupName |
||
135 | */ |
||
136 | public function activateGroup($featureName, $groupName) |
||
142 | |||
143 | /** |
||
144 | * Deactivates a feature for a specific group. |
||
145 | * @param string $featureName |
||
146 | * @param string $groupName |
||
147 | */ |
||
148 | public function deactivateGroup($featureName, $groupName) |
||
154 | |||
155 | /** |
||
156 | * Activates a feature for a specific user |
||
157 | * @param string $featureName |
||
158 | * @param integer $userId |
||
159 | */ |
||
160 | public function activateUser($featureName, $userId) |
||
166 | |||
167 | /** |
||
168 | * Deactivates a feature for a specific user |
||
169 | * @param string $featureName |
||
170 | * @param integer $userId |
||
171 | */ |
||
172 | public function deactivateUser($featureName, $userId) |
||
178 | |||
179 | /** |
||
180 | * Activates a feature for a percentage of users |
||
181 | * @param string $featureName |
||
182 | * @param integer $percentage |
||
183 | */ |
||
184 | public function activatePercentage($featureName, $percentage) |
||
190 | |||
191 | /** |
||
192 | * Deactivates the percentage activation for a feature |
||
193 | * @param string $featureName |
||
194 | */ |
||
195 | public function deactivatePercentage($featureName) |
||
201 | |||
202 | /** |
||
203 | * Checks if a feature is active |
||
204 | * @param string $featureName |
||
205 | * @param DeterminableUserInterface $user |
||
206 | * @return bool |
||
207 | */ |
||
208 | public function isActive($featureName, DeterminableUserInterface $user = null) |
||
213 | |||
214 | /** |
||
215 | * Checks if a user has the given role |
||
216 | * @param string $roleName |
||
217 | * @param DeterminableUserInterface $user |
||
218 | * @return bool |
||
219 | */ |
||
220 | public function userHasRole($roleName, DeterminableUserInterface $user) |
||
228 | |||
229 | /** |
||
230 | * Checks if a user has the given group |
||
231 | * @param string $groupName |
||
232 | * @param DeterminableUserInterface $user |
||
233 | * @return bool |
||
234 | */ |
||
235 | public function userHasGroup($groupName, DeterminableUserInterface $user) |
||
243 | } |