config = $config; } /** * @internal */ public function isFeatureActive(FeatureFlagInterface $feature): ?bool { try { $featureFlagsConfig = $this->config->FeatureFlags; } catch (Exception $e) { return false; }; $configNameForFeature = $this->getConfigNameForFeature($feature->getName()); if (!isset($featureFlagsConfig[$configNameForFeature])) { return null; } $flagValue = $featureFlagsConfig[$configNameForFeature]; return $flagValue === self::CONFIG_FEATURE_ENABLED_VALUE; } /** * @internal */ public function disableFeatureFlag(FeatureFlagInterface $feature): void { if (!isset($this->config->FeatureFlags[$this->getConfigNameForFeature($feature->getName())])) { return; } $this->config->FeatureFlags[$this->getConfigNameForFeature($feature->getName())] = self::CONFIG_FEATURE_DISABLED_VALUE; $this->config->forceSave(); } /** * @internal */ public function enableFeatureFlag(FeatureFlagInterface $feature): void { if (!isset($this->config->FeatureFlags)) { $this->config->FeatureFlags = []; } $this->config->FeatureFlags[$this->getConfigNameForFeature($feature->getName())] = self::CONFIG_FEATURE_ENABLED_VALUE; $this->config->forceSave(); } /** * @internal */ public function deleteFeatureFlag(string $featureName): void { if (!isset($this->config->FeatureFlags[$this->getConfigNameForFeature($featureName)])) { return; } unset($this->config->FeatureFlags[$this->getConfigNameForFeature($featureName)]); $this->config->forceSave(); } private function getConfigNameForFeature(string $featureName): string { return $featureName . self::CONFIG_FEATURE_NAME_SUFFIX; } }