|
12 | 12 |
|
13 | 13 | class FeatureFlags |
14 | 14 | { |
15 | | - const STATE_ON = 'on'; |
16 | | - const STATE_OFF = 'off'; |
17 | | - const STATE_DYNAMIC = 'dynamic'; |
18 | | - |
19 | 15 | private static ?Closure $defaultDynamicHandler = null; |
20 | 16 | private static ?Closure $handleMissingFeatureClosure = null; |
21 | 17 | public static array $dynamicHandlers = []; |
@@ -75,26 +71,20 @@ public static function handleMissingFeatureWith(Closure $closure): void |
75 | 71 |
|
76 | 72 | public static function isEnabled(string $feature): bool |
77 | 73 | { |
78 | | - $state = self::getState($feature); |
79 | | - |
80 | | - switch ($state) { |
81 | | - case FeatureState::on(): |
82 | | - return true; |
83 | | - case FeatureState::off(): |
84 | | - return false; |
85 | | - case FeatureState::dynamic(): |
86 | | - { |
| 74 | + return match (self::getState($feature)) { |
| 75 | + FeatureState::on() => true, |
| 76 | + FeatureState::off() => false, |
| 77 | + FeatureState::dynamic() => call_user_func(function () use ($feature) { |
87 | 78 | if (array_key_exists($feature, self::$dynamicHandlers)) { |
88 | | - return self::$dynamicHandlers[$feature]($feature, request()) === true; |
| 79 | + return call_user_func(self::$dynamicHandlers[$feature], $feature, request()) === true; |
89 | 80 | } elseif (is_callable(self::$defaultDynamicHandler)) { |
90 | 81 | return call_user_func(self::$defaultDynamicHandler, $feature, request()) === true; |
91 | 82 | } |
92 | 83 |
|
93 | 84 | return false; |
94 | | - } |
95 | | - } |
96 | | - |
97 | | - return false; |
| 85 | + }), |
| 86 | + default => false |
| 87 | + }; |
98 | 88 | } |
99 | 89 |
|
100 | 90 | public static function reset(): void |
|
0 commit comments