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\Cli\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 * Provides console services for testwork.
23 * @author Konstantin Kudryashov <ever.zet@gmail.com>
25 final class CliExtension implements Extension
30 const COMMAND_ID = 'cli.command';
31 const INPUT_ID = 'cli.input';
32 const OUTPUT_ID = 'cli.output';
35 * Available extension points
37 const CONTROLLER_TAG = 'cli.controller';
40 * @var ServiceProcessor
45 * Initializes extension.
47 * @param null|ServiceProcessor $processor
49 public function __construct(ServiceProcessor $processor = null)
51 $this->processor = $processor ?: new ServiceProcessor();
55 * Returns the extension config key.
59 public function getConfigKey()
67 public function initialize(ExtensionManager $extensionManager)
74 public function configure(ArrayNodeDefinition $builder)
81 public function load(ContainerBuilder $container, array $config)
83 $this->loadCommand($container);
89 public function process(ContainerBuilder $container)
91 $this->processControllers($container);
95 * Loads application command.
97 * @param ContainerBuilder $container
99 protected function loadCommand(ContainerBuilder $container)
101 $definition = new Definition('Behat\Testwork\Cli\Command', array('%cli.command.name%', array()));
102 $container->setDefinition(self::COMMAND_ID, $definition);
106 * Processes all controllers in container.
108 * @param ContainerBuilder $container
110 protected function processControllers(ContainerBuilder $container)
112 $references = $this->processor->findAndSortTaggedServices($container, self::CONTROLLER_TAG);
113 $container->getDefinition(self::COMMAND_ID)->replaceArgument(1, $references);