Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Definition / Cli / AvailableDefinitionsController.php
1 <?php
2
3 /*
4  * This file is part of the Behat.
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\Behat\Definition\Cli;
12
13 use Behat\Behat\Definition\DefinitionWriter;
14 use Behat\Behat\Definition\Printer\ConsoleDefinitionInformationPrinter;
15 use Behat\Behat\Definition\Printer\ConsoleDefinitionListPrinter;
16 use Behat\Behat\Definition\Printer\DefinitionPrinter;
17 use Behat\Testwork\Cli\Controller;
18 use Behat\Testwork\Suite\SuiteRepository;
19 use Symfony\Component\Console\Command\Command;
20 use Symfony\Component\Console\Input\InputInterface;
21 use Symfony\Component\Console\Input\InputOption;
22 use Symfony\Component\Console\Output\OutputInterface;
23
24 /**
25  * Shows all currently available definitions to the user.
26  *
27  * @author Konstantin Kudryashov <ever.zet@gmail.com>
28  */
29 final class AvailableDefinitionsController implements Controller
30 {
31     /**
32      * @var SuiteRepository
33      */
34     private $suiteRepository;
35     /**
36      * @var DefinitionWriter
37      */
38     private $writer;
39     /**
40      * @var ConsoleDefinitionListPrinter
41      */
42     private $listPrinter;
43     /**
44      * @var ConsoleDefinitionInformationPrinter
45      */
46     private $infoPrinter;
47
48     /**
49      * Initializes controller.
50      *
51      * @param SuiteRepository                     $suiteRepository
52      * @param DefinitionWriter                    $writer
53      * @param ConsoleDefinitionListPrinter        $listPrinter
54      * @param ConsoleDefinitionInformationPrinter $infoPrinter
55      */
56     public function __construct(
57         SuiteRepository $suiteRepository,
58         DefinitionWriter $writer,
59         ConsoleDefinitionListPrinter $listPrinter,
60         ConsoleDefinitionInformationPrinter $infoPrinter
61     ) {
62         $this->suiteRepository = $suiteRepository;
63         $this->writer = $writer;
64         $this->listPrinter = $listPrinter;
65         $this->infoPrinter = $infoPrinter;
66     }
67
68     /**
69      * {@inheritdoc}
70      */
71     public function configure(Command $command)
72     {
73         $command->addOption('--definitions', '-d', InputOption::VALUE_REQUIRED,
74             "Print all available step definitions:" . PHP_EOL .
75             "- use <info>--definitions l</info> to just list definition expressions." . PHP_EOL .
76             "- use <info>--definitions i</info> to show definitions with extended info." . PHP_EOL .
77             "- use <info>--definitions 'needle'</info> to find specific definitions." . PHP_EOL .
78             "Use <info>--lang</info> to see definitions in specific language."
79         );
80     }
81
82     /**
83      * {@inheritdoc}
84      */
85     public function execute(InputInterface $input, OutputInterface $output)
86     {
87         if (null === $argument = $input->getOption('definitions')) {
88             return null;
89         }
90
91         $printer = $this->getDefinitionPrinter($argument);
92         foreach ($this->suiteRepository->getSuites() as $suite) {
93             $this->writer->printSuiteDefinitions($printer, $suite);
94         }
95
96         return 0;
97     }
98
99     /**
100      * Returns definition printer for provided option argument.
101      *
102      * @param string $argument
103      *
104      * @return DefinitionPrinter
105      */
106     private function getDefinitionPrinter($argument)
107     {
108         if ('l' === $argument) {
109             return $this->listPrinter;
110         }
111
112         if ('i' !== $argument) {
113             $this->infoPrinter->setSearchCriterion($argument);
114         }
115
116         return $this->infoPrinter;
117     }
118 }