Container.php
1 day ago
FeatureProviderInterface.php
1 day ago
FeatureServiceProvider.php
1 day ago
Resolver.php
1 day ago
ServiceProvider.php
1 day ago
FeatureServiceProvider.php
108 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | namespace WPStaging\Framework\DI; |
| 17 | |
| 18 | use WPStaging\Framework\Exceptions\WPStagingException; |
| 19 | use WPStaging\Framework\Utils\Env; |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | abstract class FeatureServiceProvider extends ServiceProvider implements FeatureProviderInterface |
| 27 | { |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | public static function getFeatureTrigger() |
| 43 | { |
| 44 | die('As I should not be invoked.'); |
| 45 | throw new WPStagingException('Every Feature Service Provider MUST define a feature trigger.'); |
| 46 | } |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | public static function isEnabledInProduction() |
| 59 | { |
| 60 | $trigger = static::getFeatureTrigger(); |
| 61 | |
| 62 | if (defined($trigger) && constant($trigger) === false) { |
| 63 | |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | $triggerValue = Env::get($trigger); |
| 68 | if ($triggerValue !== false && (bool)$triggerValue === false) { |
| 69 | |
| 70 | return false; |
| 71 | } |
| 72 | |
| 73 | return true; |
| 74 | } |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | public static function isEnabledInDevelopment() |
| 87 | { |
| 88 | $trigger = static::getFeatureTrigger(); |
| 89 | |
| 90 | if (!defined($trigger)) { |
| 91 | return false; |
| 92 | } |
| 93 | |
| 94 | if (defined($trigger) && constant($trigger) === false) { |
| 95 | |
| 96 | return false; |
| 97 | } |
| 98 | |
| 99 | $triggerValue = Env::get($trigger); |
| 100 | if ($triggerValue !== false && (bool)$triggerValue === false) { |
| 101 | |
| 102 | return false; |
| 103 | } |
| 104 | |
| 105 | return true; |
| 106 | } |
| 107 | } |
| 108 |