Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Testwork / Cli / Command.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;
12
13 use Symfony\Component\Console\Command\Command as BaseCommand;
14 use Symfony\Component\Console\Input\InputInterface;
15 use Symfony\Component\Console\Output\OutputInterface;
16
17 /**
18  * Extends Symfony console command with a controller-based delegation.
19  *
20  * @author Konstantin Kudryashov <ever.zet@gmail.com>
21  */
22 final class Command extends BaseCommand
23 {
24     /**
25      * @var Controller[]
26      */
27     private $controllers = array();
28
29     /**
30      * Initializes command.
31      *
32      * @param string       $commandName
33      * @param Controller[] $controllers
34      */
35     public function __construct($commandName, array $controllers)
36     {
37         $this->controllers = $controllers;
38
39         parent::__construct($commandName);
40     }
41
42     /**
43      * Configures the command by running controllers prepare().
44      */
45     protected function configure()
46     {
47         foreach ($this->controllers as $controller) {
48             $controller->configure($this);
49         }
50     }
51
52     /**
53      * Executes the current command by executing all controllers action().
54      *
55      * @param InputInterface  $input  An InputInterface instance
56      * @param OutputInterface $output An OutputInterface instance
57      *
58      * @return integer Return code of one of the processors or 0 if none of them returned integer
59      */
60     protected function execute(InputInterface $input, OutputInterface $output)
61     {
62         foreach ($this->controllers as $controller) {
63             if (is_int($return = $controller->execute($input, $output))) {
64                 return $return;
65             }
66         }
67
68         return 0;
69     }
70 }