1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Geekish\Crap\Command; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
6
|
|
|
use Symfony\Component\Process\Process; |
7
|
|
|
use Symfony\Component\Process\ProcessBuilder; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class BaseComposerCommand |
11
|
|
|
* @package Geekish\Crap\Command |
12
|
|
|
*/ |
13
|
|
|
abstract class BaseComposerCommand extends BaseCommand |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Return options that are NOT default |
17
|
|
|
* We don't want to call Composer commands with every possible option set... |
18
|
|
|
* @codeCoverageIgnore |
19
|
|
|
* |
20
|
|
|
* @param InputInterface $input |
21
|
|
|
* @param bool $decorated |
22
|
|
|
* @return array |
23
|
|
|
*/ |
24
|
|
|
protected function getOptions(InputInterface $input, $decorated = true) |
25
|
|
|
{ |
26
|
|
|
$inputOptions = $input->getOptions(); |
27
|
|
|
$options = []; |
28
|
|
|
|
29
|
|
|
foreach ($this->getDefinition()->getOptions() as $option) { |
30
|
|
|
$name = $option->getName(); |
31
|
|
|
if ($inputOptions[$name] !== $option->getDefault()) { |
32
|
|
|
$options[] = $name; |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
if ($decorated) { |
37
|
|
|
$options[] = 'ansi'; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
return $options; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Create Process for Composer command |
45
|
|
|
* @codeCoverageIgnore |
46
|
|
|
* |
47
|
|
|
* @param $command |
48
|
|
|
* @param array $packages |
49
|
|
|
* @param array $options |
50
|
|
|
* @return Process |
51
|
|
|
*/ |
52
|
|
|
protected function createProcess($command, array $packages, array $options) |
53
|
|
|
{ |
54
|
|
|
$arguments = []; |
55
|
|
|
|
56
|
|
|
$arguments[] = $command; |
57
|
|
|
|
58
|
|
|
if (count($options) > 0) { |
59
|
|
|
$options = array_map(function ($value) { |
60
|
|
|
return str_pad($value, strlen($value) + 2, '-', STR_PAD_LEFT); |
61
|
|
|
}, $options); |
62
|
|
|
|
63
|
|
|
array_push($arguments, ...$options); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
array_push($arguments, ...$packages); |
67
|
|
|
|
68
|
|
|
return (new ProcessBuilder) |
|
|
|
|
69
|
|
|
->setPrefix('composer') |
70
|
|
|
->setArguments($arguments) |
71
|
|
|
->setTimeout(null) |
72
|
|
|
->getProcess(); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.