Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / consolidation / robo / src / Task / Composer / Base.php
1 <?php
2 namespace Robo\Task\Composer;
3
4 use Robo\Contract\CommandInterface;
5 use Robo\Exception\TaskException;
6 use Robo\Task\BaseTask;
7
8 abstract class Base extends BaseTask implements CommandInterface
9 {
10     use \Robo\Common\ExecOneCommand;
11
12     /**
13      * @var string
14      */
15     protected $command = '';
16
17     /**
18      * @var boolena
19      */
20     protected $built = false;
21
22     /**
23      * @var string
24      */
25     protected $prefer;
26
27     /**
28      * @var string
29      */
30     protected $dev;
31
32     /**
33      * @var string
34      */
35     protected $ansi;
36
37     /**
38      * @var string
39      */
40     protected $nointeraction;
41
42     /**
43      * Action to use
44      *
45      * @var string
46      */
47     protected $action = '';
48
49     /**
50      * @param null|string $pathToComposer
51      *
52      * @throws \Robo\Exception\TaskException
53      */
54     public function __construct($pathToComposer = null)
55     {
56         $this->command = $pathToComposer;
57         if (!$this->command) {
58             $this->command = $this->findExecutablePhar('composer');
59         }
60         if (!$this->command) {
61             throw new TaskException(__CLASS__, "Neither local composer.phar nor global composer installation could be found.");
62         }
63     }
64
65     /**
66      * adds `prefer-dist` option to composer
67      *
68      * @return $this
69      */
70     public function preferDist($preferDist = true)
71     {
72         if (!$preferDist) {
73             return $this->preferSource();
74         }
75         $this->prefer = '--prefer-dist';
76         return $this;
77     }
78
79     /**
80      * adds `prefer-source` option to composer
81      *
82      * @return $this
83      */
84     public function preferSource()
85     {
86         $this->prefer = '--prefer-source';
87         return $this;
88     }
89
90     /**
91      * adds `dev` option to composer
92      *
93      * @return $this
94      */
95     public function dev($dev = true)
96     {
97         if (!$dev) {
98             return $this->noDev();
99         }
100         $this->dev = '--dev';
101         return $this;
102     }
103
104     /**
105      * adds `no-dev` option to composer
106      *
107      * @return $this
108      */
109     public function noDev()
110     {
111         $this->dev = '--no-dev';
112         return $this;
113     }
114
115     /**
116      * adds `ansi` option to composer
117      *
118      * @return $this
119      */
120     public function ansi($ansi = true)
121     {
122         if (!$ansi) {
123             return $this->noAnsi();
124         }
125         $this->ansi = '--ansi';
126         return $this;
127     }
128
129     /**
130      * adds `no-ansi` option to composer
131      *
132      * @return $this
133      */
134     public function noAnsi()
135     {
136         $this->ansi = '--no-ansi';
137         return $this;
138     }
139
140     public function interaction($interaction = true)
141     {
142         if (!$interaction) {
143             return $this->noInteraction();
144         }
145         return $this;
146     }
147
148     /**
149      * adds `no-interaction` option to composer
150      *
151      * @return $this
152      */
153     public function noInteraction()
154     {
155         $this->nointeraction = '--no-interaction';
156         return $this;
157     }
158
159     /**
160      * adds `optimize-autoloader` option to composer
161      *
162      * @return $this
163      */
164     public function optimizeAutoloader($optimize = true)
165     {
166         if ($optimize) {
167             $this->option('--optimize-autoloader');
168         }
169         return $this;
170     }
171
172     /**
173      * adds `ignore-platform-reqs` option to composer
174      *
175      * @return $this
176      */
177     public function ignorePlatformRequirements($ignore = true)
178     {
179         $this->option('--ignore-platform-reqs');
180         return $this;
181     }
182
183     /**
184      * disable plugins
185      *
186      * @return $this
187      */
188     public function disablePlugins($disable = true)
189     {
190         if ($disable) {
191             $this->option('--no-plugins');
192         }
193         return $this;
194     }
195
196     /**
197      * skip scripts
198      *
199      * @return $this
200      */
201     public function noScripts($disable = true)
202     {
203         if ($disable) {
204             $this->option('--no-scripts');
205         }
206         return $this;
207     }
208
209     /**
210      * adds `--working-dir $dir` option to composer
211      *
212      * @return $this
213      */
214     public function workingDir($dir)
215     {
216         $this->option("--working-dir", $dir);
217         return $this;
218     }
219
220     /**
221      * Copy class fields into command options as directed.
222      */
223     public function buildCommand()
224     {
225         if (!isset($this->ansi) && $this->getConfig()->get(\Robo\Config\Config::DECORATED)) {
226             $this->ansi();
227         }
228         if (!isset($this->nointeraction) && !$this->getConfig()->get(\Robo\Config\Config::INTERACTIVE)) {
229             $this->noInteraction();
230         }
231         $this->option($this->prefer)
232             ->option($this->dev)
233             ->option($this->nointeraction)
234             ->option($this->ansi);
235     }
236
237     /**
238      * {@inheritdoc}
239      */
240     public function getCommand()
241     {
242         if (!$this->built) {
243             $this->buildCommand();
244             $this->built = true;
245         }
246         return "{$this->command} {$this->action}{$this->arguments}";
247     }
248 }