Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Testwork / Specification / ServiceContainer / SpecificationExtension.php
1 <?php
2
3 /*
4  * This file is part of the Behat Testwork.
5  * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 namespace Behat\Testwork\Specification\ServiceContainer;
12
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;
19
20 /**
21  * Extends testwork with test specification services.
22  *
23  * @author Konstantin Kudryashov <ever.zet@gmail.com>
24  */
25 final class SpecificationExtension implements Extension
26 {
27     /*
28      * Available services
29      */
30     const FINDER_ID = 'specifications.finder';
31
32     /*
33      * Available extension points
34      */
35     const LOCATOR_TAG = 'specifications.locator';
36
37     /**
38      * @var ServiceProcessor
39      */
40     private $processor;
41
42     /**
43      * Initializes extension.
44      *
45      * @param null|ServiceProcessor $processor
46      */
47     public function __construct(ServiceProcessor $processor = null)
48     {
49         $this->processor = $processor ? : new ServiceProcessor();
50     }
51
52     /**
53      * {@inheritdoc}
54      */
55     public function getConfigKey()
56     {
57         return 'specifications';
58     }
59
60     /**
61      * {@inheritdoc}
62      */
63     public function initialize(ExtensionManager $extensionManager)
64     {
65     }
66
67     /**
68      * {@inheritdoc}
69      */
70     public function configure(ArrayNodeDefinition $builder)
71     {
72     }
73
74     /**
75      * {@inheritdoc}
76      */
77     public function load(ContainerBuilder $container, array $config)
78     {
79         $this->loadFinder($container);
80     }
81
82     /**
83      * {@inheritdoc}
84      */
85     public function process(ContainerBuilder $container)
86     {
87         $this->processLocators($container);
88     }
89
90     /**
91      * Loads specification finder.
92      *
93      * @param ContainerBuilder $container
94      */
95     private function loadFinder(ContainerBuilder $container)
96     {
97         $definition = new Definition('Behat\Testwork\Specification\SpecificationFinder');
98         $container->setDefinition(self::FINDER_ID, $definition);
99     }
100
101     /**
102      * Processes specification locators.
103      *
104      * @param ContainerBuilder $container
105      */
106     private function processLocators(ContainerBuilder $container)
107     {
108         $references = $this->processor->findAndSortTaggedServices($container, self::LOCATOR_TAG);
109         $definition = $container->getDefinition(self::FINDER_ID);
110
111         foreach ($references as $reference) {
112             $definition->addMethodCall('registerSpecificationLocator', array($reference));
113         }
114     }
115 }