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;
13 use Symfony\Component\Console\Command\Command as BaseCommand;
14 use Symfony\Component\Console\Input\InputInterface;
15 use Symfony\Component\Console\Output\OutputInterface;
18 * Extends Symfony console command with a controller-based delegation.
20 * @author Konstantin Kudryashov <ever.zet@gmail.com>
22 final class Command extends BaseCommand
27 private $controllers = array();
30 * Initializes command.
32 * @param string $commandName
33 * @param Controller[] $controllers
35 public function __construct($commandName, array $controllers)
37 $this->controllers = $controllers;
39 parent::__construct($commandName);
43 * Configures the command by running controllers prepare().
45 protected function configure()
47 foreach ($this->controllers as $controller) {
48 $controller->configure($this);
53 * Executes the current command by executing all controllers action().
55 * @param InputInterface $input An InputInterface instance
56 * @param OutputInterface $output An OutputInterface instance
58 * @return integer Return code of one of the processors or 0 if none of them returned integer
60 protected function execute(InputInterface $input, OutputInterface $output)
62 foreach ($this->controllers as $controller) {
63 if (is_int($return = $controller->execute($input, $output))) {