Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / consolidation / robo / src / Task / Docker / Exec.php
1 <?php
2 namespace Robo\Task\Docker;
3
4 use Robo\Common\CommandReceiver;
5
6 /**
7  * Executes command inside running Docker container
8  *
9  * ```php
10  * <?php
11  * $test = $this->taskDockerRun('test_env')
12  *      ->detached()
13  *      ->run();
14  *
15  * $this->taskDockerExec($test)
16  *      ->interactive()
17  *      ->exec('./runtests')
18  *      ->run();
19  *
20  * // alternatively use commands from other tasks
21  *
22  * $this->taskDockerExec($test)
23  *      ->interactive()
24  *      ->exec($this->taskCodecept()->suite('acceptance'))
25  *      ->run();
26  * ?>
27  * ```
28  *
29  */
30 class Exec extends Base
31 {
32     use CommandReceiver;
33
34     /**
35      * @var string
36      */
37     protected $command = "docker exec";
38
39     /**
40      * @var string
41      */
42     protected $cid;
43
44     /**
45      * @var string
46      */
47     protected $run = '';
48
49     /**
50      * @param string|\Robo\Result $cidOrResult
51      */
52     public function __construct($cidOrResult)
53     {
54         $this->cid = $cidOrResult instanceof Result ? $cidOrResult->getCid() : $cidOrResult;
55     }
56
57     /**
58      * @return $this
59      */
60     public function detached()
61     {
62         $this->option('-d');
63         return $this;
64     }
65
66     /**
67      * {@inheritdoc)}
68      */
69     public function interactive($interactive = true)
70     {
71         if ($interactive) {
72             $this->option('-i');
73         }
74         return parent::interactive($interactive);
75     }
76
77     /**
78      * @param string|\Robo\Contract\CommandInterface $command
79      *
80      * @return $this
81      */
82     public function exec($command)
83     {
84         $this->run = $this->receiveCommand($command);
85         return $this;
86     }
87
88     /**
89      * {@inheritdoc}
90      */
91     public function getCommand()
92     {
93         return $this->command . ' ' . $this->arguments . ' ' . $this->cid.' '.$this->run;
94     }
95 }