|
1
|
|
|
<?php |
|
2
|
|
|
namespace PSB\Core\Feature; |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
use PSB\Core\KnownSettingsEnum; |
|
6
|
|
|
use PSB\Core\Util\Settings; |
|
7
|
|
|
|
|
8
|
|
|
class FeatureSettingsExtensions |
|
9
|
|
|
{ |
|
10
|
3 |
|
public static function enableFeatureByDefault($featureFqcn, Settings $settings) |
|
11
|
|
|
{ |
|
12
|
3 |
|
static::registerFeature($featureFqcn, $settings); |
|
13
|
3 |
|
$settings->setDefault($featureFqcn, FeatureStateEnum::ENABLED); |
|
14
|
3 |
|
} |
|
15
|
|
|
|
|
16
|
2 |
|
public static function enableFeature($featureFqcn, Settings $settings) |
|
17
|
|
|
{ |
|
18
|
2 |
|
static::registerFeature($featureFqcn, $settings); |
|
19
|
2 |
|
$settings->set($featureFqcn, FeatureStateEnum::ENABLED); |
|
20
|
2 |
|
} |
|
21
|
|
|
|
|
22
|
7 |
|
public static function registerFeature($featureFqcn, Settings $settings) |
|
23
|
|
|
{ |
|
24
|
7 |
|
$fqcnList = $settings->tryGet(KnownSettingsEnum::FEATURE_FQCN_LIST) ?: []; |
|
25
|
7 |
|
$fqcnList[$featureFqcn] = $featureFqcn; |
|
26
|
7 |
|
$settings->set(KnownSettingsEnum::FEATURE_FQCN_LIST, $fqcnList); |
|
27
|
7 |
|
} |
|
28
|
|
|
|
|
29
|
2 |
|
public static function disableFeature($featureFqcn, Settings $settings) |
|
30
|
|
|
{ |
|
31
|
2 |
|
$settings->set($featureFqcn, FeatureStateEnum::DISABLED); |
|
32
|
2 |
|
} |
|
33
|
|
|
|
|
34
|
3 |
|
public static function markFeatureAsActive($featureFqcn, Settings $settings) |
|
35
|
|
|
{ |
|
36
|
3 |
|
$settings->set($featureFqcn, FeatureStateEnum::ACTIVE); |
|
37
|
3 |
|
} |
|
38
|
|
|
|
|
39
|
3 |
|
public static function markFeatureAsInactive($featureFqcn, Settings $settings) |
|
40
|
|
|
{ |
|
41
|
3 |
|
$settings->set($featureFqcn, FeatureStateEnum::INACTIVE); |
|
42
|
3 |
|
} |
|
43
|
|
|
|
|
44
|
6 |
|
public static function isFeatureEnabled($featureFqcn, Settings $settings) |
|
45
|
|
|
{ |
|
46
|
6 |
|
return $settings->tryGet($featureFqcn) == FeatureStateEnum::ENABLED; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
3 |
|
public static function isFeatureActive($featureFqcn, Settings $settings) |
|
50
|
|
|
{ |
|
51
|
3 |
|
return $settings->tryGet($featureFqcn) == FeatureStateEnum::ACTIVE; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|