Pull merge.
[yaffs-website] / vendor / consolidation / robo / src / Task / Base / SymfonyCommand.php
1 <?php
2 namespace Robo\Task\Base;
3
4 use Robo\Robo;
5 use Robo\Result;
6 use Robo\Task\BaseTask;
7 use Symfony\Component\Console\Command\Command;
8 use Symfony\Component\Console\Input\ArrayInput;
9
10 /**
11  * Executes Symfony Command
12  *
13  * ``` php
14  * <?php
15  * // Symfony Command
16  * $this->taskSymfonyCommand(new \Codeception\Command\Run('run'))
17  *      ->arg('suite','acceptance')
18  *      ->opt('debug')
19  *      ->run();
20  *
21  * // Artisan Command
22  * $this->taskSymfonyCommand(new ModelGeneratorCommand())
23  *      ->arg('name', 'User')
24  *      ->run();
25  * ?>
26  * ```
27  */
28 class SymfonyCommand extends BaseTask
29 {
30     /**
31      * @var \Symfony\Component\Console\Command\Command
32      */
33     protected $command;
34
35     /**
36      * @var string[]
37      */
38     protected $input;
39
40     public function __construct(Command $command)
41     {
42         $this->command = $command;
43         $this->input = [];
44     }
45
46     /**
47      * @param string $arg
48      * @param string $value
49      *
50      * @return $this
51      */
52     public function arg($arg, $value)
53     {
54         $this->input[$arg] = $value;
55         return $this;
56     }
57
58     public function opt($option, $value = null)
59     {
60         $this->input["--$option"] = $value;
61         return $this;
62     }
63
64     /**
65      * {@inheritdoc}
66      */
67     public function run()
68     {
69         $this->printTaskInfo('Running command {command}', ['command' => $this->command->getName()]);
70         return new Result(
71             $this,
72             $this->command->run(new ArrayInput($this->input), Robo::output())
73         );
74     }
75 }