Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Definition / Printer / ConsoleDefinitionPrinter.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\Printer;
12
13 use Behat\Behat\Definition\Definition;
14 use Behat\Behat\Definition\Pattern\PatternTransformer;
15 use Behat\Behat\Definition\Translator\DefinitionTranslator;
16 use Behat\Gherkin\Keywords\KeywordsInterface;
17 use Behat\Testwork\Suite\Suite;
18 use Symfony\Component\Console\Formatter\OutputFormatterStyle;
19 use Symfony\Component\Console\Output\OutputInterface;
20
21 /**
22  * Represents console-based definition printer.
23  *
24  * @author Konstantin Kudryashov <ever.zet@gmail.com>
25  */
26 abstract class ConsoleDefinitionPrinter implements DefinitionPrinter
27 {
28     /**
29      * @var OutputInterface
30      */
31     private $output;
32     /**
33      * @var PatternTransformer
34      */
35     private $patternTransformer;
36     /**
37      * @var DefinitionTranslator
38      */
39     private $translator;
40     /**
41      * @var KeywordsInterface
42      */
43     private $keywords;
44
45     /**
46      * Initializes printer.
47      *
48      * @param OutputInterface     $output
49      * @param PatternTransformer  $patternTransformer
50      * @param DefinitionTranslator $translator
51      * @param KeywordsInterface   $keywords
52      */
53     public function __construct(
54         OutputInterface $output,
55         PatternTransformer $patternTransformer,
56         DefinitionTranslator $translator,
57         KeywordsInterface $keywords
58     ) {
59         $this->output = $output;
60         $this->patternTransformer = $patternTransformer;
61         $this->translator = $translator;
62         $this->keywords = $keywords;
63
64         $output->getFormatter()->setStyle('def_regex', new OutputFormatterStyle('yellow'));
65         $output->getFormatter()->setStyle(
66             'def_regex_capture',
67             new OutputFormatterStyle('yellow', null, array('bold'))
68         );
69         $output->getFormatter()->setStyle(
70             'def_dimmed',
71             new OutputFormatterStyle('black', null, array('bold'))
72         );
73     }
74
75     /**
76      * Writes text to the console.
77      *
78      * @param string $text
79      */
80     final protected function write($text)
81     {
82         $this->output->writeln($text);
83         $this->output->writeln('');
84     }
85
86     final protected function getDefinitionType(Definition $definition, $onlyOne = false)
87     {
88         $this->keywords->setLanguage($this->translator->getLocale());
89
90         $method = 'get'.ucfirst($definition->getType()).'Keywords';
91
92         $keywords = explode('|', $this->keywords->$method());
93
94         if ($onlyOne) {
95             return current($keywords);
96         }
97
98         return 1 < count($keywords) ? '['.implode('|', $keywords).']' : implode('|', $keywords);
99     }
100
101     /**
102      * Translates definition using translator.
103      *
104      * @param Suite      $suite
105      * @param Definition $definition
106      *
107      * @return Definition
108      */
109     final protected function translateDefinition(Suite $suite, Definition $definition)
110     {
111         return $this->translator->translateDefinition($suite, $definition);
112     }
113
114     /**
115      * Returns whether verbosity is verbose (-v).
116      *
117      * @return bool true if verbosity is set to VERBOSITY_VERBOSE, false otherwise
118      */
119     final protected function isVerbose()
120     {
121         return $this->output->isVerbose();
122     }
123 }