4 * This file is part of the Behat Testwork.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 namespace Behat\Testwork\Specification\ServiceContainer;
13 use Behat\Testwork\ServiceContainer\Extension;
14 use Behat\Testwork\ServiceContainer\ExtensionManager;
15 use Behat\Testwork\ServiceContainer\ServiceProcessor;
16 use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
17 use Symfony\Component\DependencyInjection\ContainerBuilder;
18 use Symfony\Component\DependencyInjection\Definition;
21 * Extends testwork with test specification services.
23 * @author Konstantin Kudryashov <ever.zet@gmail.com>
25 final class SpecificationExtension implements Extension
30 const FINDER_ID = 'specifications.finder';
33 * Available extension points
35 const LOCATOR_TAG = 'specifications.locator';
38 * @var ServiceProcessor
43 * Initializes extension.
45 * @param null|ServiceProcessor $processor
47 public function __construct(ServiceProcessor $processor = null)
49 $this->processor = $processor ? : new ServiceProcessor();
55 public function getConfigKey()
57 return 'specifications';
63 public function initialize(ExtensionManager $extensionManager)
70 public function configure(ArrayNodeDefinition $builder)
77 public function load(ContainerBuilder $container, array $config)
79 $this->loadFinder($container);
85 public function process(ContainerBuilder $container)
87 $this->processLocators($container);
91 * Loads specification finder.
93 * @param ContainerBuilder $container
95 private function loadFinder(ContainerBuilder $container)
97 $definition = new Definition('Behat\Testwork\Specification\SpecificationFinder');
98 $container->setDefinition(self::FINDER_ID, $definition);
102 * Processes specification locators.
104 * @param ContainerBuilder $container
106 private function processLocators(ContainerBuilder $container)
108 $references = $this->processor->findAndSortTaggedServices($container, self::LOCATOR_TAG);
109 $definition = $container->getDefinition(self::FINDER_ID);
111 foreach ($references as $reference) {
112 $definition->addMethodCall('registerSpecificationLocator', array($reference));