*/ class TestRunnerFeatureService extends ConfigurableService implements LoggerAwareInterface { use LoggerAwareTrait; const SERVICE_ID = 'taoTests/testRunnerFeature'; const OPTION_AVAILABLE = 'available'; /** * Register a feature * * @param TestRunnerFeature $testRunnerFeature * @return string Id of the registered feature * @throws \common_exception_InconsistentData */ public function register(TestRunnerFeature $testRunnerFeature) { $registeredFeatures = $this->getOption(self::OPTION_AVAILABLE); if ($registeredFeatures == null) { $registeredFeatures = []; } $featureId = $testRunnerFeature->getId(); if (array_key_exists($featureId, $registeredFeatures)) { throw new \common_exception_InconsistentData('Cannot register two features with the same id ' . $featureId); } $registeredFeatures[$featureId] = $testRunnerFeature; $this->setOption(self::OPTION_AVAILABLE, $registeredFeatures); return $featureId; } /** * Unregister a feature * * @param string $featureId * @throws \common_exception_InconsistentData */ public function unregister($featureId) { $registeredFeatures = $this->getOption(self::OPTION_AVAILABLE); if (is_array($registeredFeatures) && array_key_exists($featureId, $registeredFeatures)) { unset($registeredFeatures[$featureId]); $this->setOption(self::OPTION_AVAILABLE, $registeredFeatures); } else { $this->logWarning('Cannot unregister inexistant feature ' . $featureId); } } /** * Return all available features * @param boolean $filterDisabled * @return TestRunnerFeature[] */ public function getAll($filterDisabled = true) { $result = []; /** @var TestRunnerFeatureInterface[] $features */ $features = $this->getOption(self::OPTION_AVAILABLE); if (!$features) { $features = []; } foreach ($features as $id => $feature) { $feature->setServiceLocator($this->getServiceLocator()); $this->propagate($feature); if ($filterDisabled) { if ($feature->isActive()) { $result[$id] = $feature; } } else { $result[$id] = $feature; } } return $result; } }