Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Testwork / Cli / ServiceContainer / CliExtension.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\Cli\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  * Provides console services for testwork.
22  *
23  * @author Konstantin Kudryashov <ever.zet@gmail.com>
24  */
25 final class CliExtension implements Extension
26 {
27     /*
28      * Available services
29      */
30     const COMMAND_ID = 'cli.command';
31     const INPUT_ID = 'cli.input';
32     const OUTPUT_ID = 'cli.output';
33
34     /*
35      * Available extension points
36      */
37     const CONTROLLER_TAG = 'cli.controller';
38
39     /**
40      * @var ServiceProcessor
41      */
42     private $processor;
43
44     /**
45      * Initializes extension.
46      *
47      * @param null|ServiceProcessor $processor
48      */
49     public function __construct(ServiceProcessor $processor = null)
50     {
51         $this->processor = $processor ?: new ServiceProcessor();
52     }
53
54     /**
55      * Returns the extension config key.
56      *
57      * @return string
58      */
59     public function getConfigKey()
60     {
61         return 'cli';
62     }
63
64     /**
65      * {@inheritdoc}
66      */
67     public function initialize(ExtensionManager $extensionManager)
68     {
69     }
70
71     /**
72      * {@inheritdoc}
73      */
74     public function configure(ArrayNodeDefinition $builder)
75     {
76     }
77
78     /**
79      * {@inheritdoc}
80      */
81     public function load(ContainerBuilder $container, array $config)
82     {
83         $this->loadCommand($container);
84     }
85
86     /**
87      * {@inheritdoc}
88      */
89     public function process(ContainerBuilder $container)
90     {
91         $this->processControllers($container);
92     }
93
94     /**
95      * Loads application command.
96      *
97      * @param ContainerBuilder $container
98      */
99     protected function loadCommand(ContainerBuilder $container)
100     {
101         $definition = new Definition('Behat\Testwork\Cli\Command', array('%cli.command.name%', array()));
102         $container->setDefinition(self::COMMAND_ID, $definition);
103     }
104
105     /**
106      * Processes all controllers in container.
107      *
108      * @param ContainerBuilder $container
109      */
110     protected function processControllers(ContainerBuilder $container)
111     {
112         $references = $this->processor->findAndSortTaggedServices($container, self::CONTROLLER_TAG);
113         $container->getDefinition(self::COMMAND_ID)->replaceArgument(1, $references);
114     }
115 }