6b4c6c5fc8c5a07f9b7690180ba57ba1d767ba94
[yaffs-website] / vendor / consolidation / annotated-command / tests / src / ExampleAnnotatedCommand.php
1 <?php
2 namespace Consolidation\TestUtils;
3
4 use Consolidation\AnnotatedCommand\AnnotatedCommand;
5
6 use Symfony\Component\Console\Input\InputInterface;
7 use Symfony\Component\Console\Output\OutputInterface;
8
9 /**
10  * Test file used in the Annotation Factory tests.  It is also
11  * discovered in the testCommandDiscovery() test.
12  *
13  * The testCommandDiscovery test search base is the 'src' directory;
14  * any command files located immediately inside the search base are
15  * eligible for discovery, and will be included in the search results.
16  */
17 class ExampleAnnotatedCommand extends AnnotatedCommand
18 {
19     /**
20      * Do the main function of the my:cat command.
21      */
22     public function myCat($one, $two = '', $multiple = [], $flip = false)
23     {
24         if ($flip) {
25             return "{$two}{$one}" . implode('', array_reverse($multiple));
26         }
27         return "{$one}{$two}" . implode('', $multiple);
28     }
29
30     /**
31      * This is the my:cat command implemented as an AnnotatedCommand subclass.
32      *
33      * This command will concatenate two parameters. If the --flip flag
34      * is provided, then the result is the concatenation of two and one.
35      *
36      * @command my:cat
37      * @arg string $one The first parameter.
38      * @arg string $two The other parameter.
39      * @default $two ''
40      * @option array $multiple An array of values
41      * @default $multiple []
42      * @option boolean $flip Whether or not the second parameter should come first in the result.
43      * @aliases c
44      * @usage bet alpha --flip
45      *   Concatenate "alpha" and "bet".
46      */
47     protected function execute(InputInterface $input, OutputInterface $output)
48     {
49         $one = $input->getArgument('one');
50         $two = $input->getArgument('two');
51         $multiple = $input->getOption('multiple');
52         $flip = $input->getOption('flip');
53
54         $result = $this->myCat($one, $two, $multiple, $flip);
55
56         // We could also just use $output->writeln($result) here,
57         // but calling processResults enables the use of output
58         // formatters. Note also that if you use processResults, you
59         // should correctly inject the command processor into your
60         // annotated command via AnnotatedCommand::setCommandProcessor().
61         return $this->processResults($input, $output, $result);
62     }
63 }