Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Context / Cli / ContextSnippetsController.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\Context\Cli;
12
13 use Behat\Behat\Context\Snippet\Generator\AggregatePatternIdentifier;
14 use Behat\Behat\Context\Snippet\Generator\ContextInterfaceBasedContextIdentifier;
15 use Behat\Behat\Context\Snippet\Generator\ContextInterfaceBasedPatternIdentifier;
16 use Behat\Behat\Context\Snippet\Generator\ContextSnippetGenerator;
17 use Behat\Behat\Context\Snippet\Generator\FixedContextIdentifier;
18 use Behat\Behat\Context\Snippet\Generator\FixedPatternIdentifier;
19 use Behat\Behat\Context\Snippet\Generator\AggregateContextIdentifier;
20 use Behat\Testwork\Cli\Controller;
21 use Symfony\Component\Console\Command\Command as SymfonyCommand;
22 use Symfony\Component\Console\Input\InputInterface;
23 use Symfony\Component\Console\Input\InputOption;
24 use Symfony\Component\Console\Output\OutputInterface;
25 use Symfony\Component\Translation\TranslatorInterface;
26
27 /**
28  * Configures which context snippets are generated for.
29  *
30  * @author Konstantin Kudryashov <ever.zet@gmail.com>
31  */
32 final class ContextSnippetsController implements Controller
33 {
34     /**
35      * @var ContextSnippetGenerator
36      */
37     private $generator;
38     /**
39      * @var TranslatorInterface
40      */
41     private $translator;
42
43     /**
44      * Initialises controller.
45      *
46      * @param ContextSnippetGenerator $generator
47      * @param TranslatorInterface     $translator
48      */
49     public function __construct(ContextSnippetGenerator $generator, TranslatorInterface $translator)
50     {
51         $this->generator = $generator;
52         $this->translator = $translator;
53     }
54
55     /**
56      * {@inheritdoc}
57      */
58     public function configure(SymfonyCommand $command)
59     {
60         $command
61             ->addOption(
62                 '--snippets-for', null, InputOption::VALUE_OPTIONAL,
63                 "Specifies which context class to generate snippets for."
64             )
65             ->addOption(
66                 '--snippets-type', null, InputOption::VALUE_REQUIRED,
67                 "Specifies which type of snippets (turnip, regex) to generate."
68             );
69     }
70
71     /**
72      * {@inheritdoc}
73      */
74     public function execute(InputInterface $input, OutputInterface $output)
75     {
76         $this->generator->setContextIdentifier(
77             new AggregateContextIdentifier(array(
78                 new ContextInterfaceBasedContextIdentifier(),
79                 new FixedContextIdentifier($input->getOption('snippets-for')),
80                 new InteractiveContextIdentifier($this->translator, $input, $output)
81             ))
82         );
83
84         $this->generator->setPatternIdentifier(
85             new AggregatePatternIdentifier(array(
86                 new ContextInterfaceBasedPatternIdentifier(),
87                 new FixedPatternIdentifier($input->getOption('snippets-type'))
88             ))
89         );
90     }
91 }