4 * This file is part of the Behat.
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\Behat\Gherkin\Cli;
13 use Behat\Gherkin\Keywords\KeywordsDumper;
14 use Behat\Testwork\Cli\Controller;
15 use Symfony\Component\Console\Command\Command;
16 use Symfony\Component\Console\Formatter\OutputFormatterStyle;
17 use Symfony\Component\Console\Input\InputInterface;
18 use Symfony\Component\Console\Input\InputOption;
19 use Symfony\Component\Console\Output\OutputInterface;
20 use Symfony\Component\Translation\TranslatorInterface;
23 * Prints example of the feature to present all available syntax keywords.
25 * @author Konstantin Kudryashov <ever.zet@gmail.com>
27 final class SyntaxController implements Controller
32 private $keywordsDumper;
34 * @var TranslatorInterface
39 * Initializes controller.
41 * @param KeywordsDumper $dumper
42 * @param TranslatorInterface $translator
44 public function __construct(KeywordsDumper $dumper, TranslatorInterface $translator)
46 $dumper->setKeywordsDumperFunction(array($this, 'dumpKeywords'));
47 $this->keywordsDumper = $dumper;
48 $this->translator = $translator;
52 * Configures command to be executable by the controller.
54 * @param Command $command
56 public function configure(Command $command)
60 '--story-syntax', null, InputOption::VALUE_NONE,
61 "Print <comment>*.feature</comment> example." . PHP_EOL .
62 "Use <info>--lang</info> to see specific language."
67 * Executes controller.
69 * @param InputInterface $input
70 * @param OutputInterface $output
72 * @return null|integer
74 public function execute(InputInterface $input, OutputInterface $output)
76 if (!$input->getOption('story-syntax')) {
80 $output->getFormatter()->setStyle('gherkin_keyword', new OutputFormatterStyle('green', null, array('bold')));
81 $output->getFormatter()->setStyle('gherkin_comment', new OutputFormatterStyle('yellow'));
83 $story = $this->keywordsDumper->dump($this->translator->getLocale());
84 $story = preg_replace('/^\#.*/', '<gherkin_comment>$0</gherkin_comment>', $story);
85 $output->writeln($story);
94 * @param array $keywords keywords list
98 public function dumpKeywords(array $keywords)
100 $dump = '<gherkin_keyword>' . implode('</gherkin_keyword>|<gherkin_keyword>', $keywords) . '</gherkin_keyword>';
102 if (1 < count($keywords)) {
103 return '[' . $dump . ']';