1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* See class comment |
4
|
|
|
* |
5
|
|
|
* PHP Version 5 |
6
|
|
|
* |
7
|
|
|
* @category Netresearch |
8
|
|
|
* @package Netresearch\Kite |
9
|
|
|
* @subpackage Task |
10
|
|
|
* @author Christian Opitz <[email protected]> |
11
|
|
|
* @license http://www.netresearch.de Netresearch Copyright |
12
|
|
|
* @link http://www.netresearch.de |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Netresearch\Kite\Task; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Run a composer command |
19
|
|
|
* |
20
|
|
|
* @category Netresearch |
21
|
|
|
* @package Netresearch\Kite |
22
|
|
|
* @subpackage Task |
23
|
|
|
* @author Christian Opitz <[email protected]> |
24
|
|
|
* @license http://www.netresearch.de Netresearch Copyright |
25
|
|
|
* @link http://www.netresearch.de |
26
|
|
|
*/ |
27
|
|
|
class ComposerTask extends ShellTask |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* Configure the options |
31
|
|
|
* |
32
|
|
|
* @return array |
33
|
|
|
*/ |
34
|
|
|
protected function configureVariables() |
35
|
|
|
{ |
36
|
|
|
return array( |
37
|
|
|
// Override to set pt to true by default |
38
|
|
|
'processSettings' => array( |
39
|
|
|
'type' => 'array', |
40
|
|
|
'default' => array('pt' => true), |
41
|
|
|
'label' => 'Settings for symfony process class' |
42
|
|
|
), |
43
|
|
|
'--', |
44
|
|
|
) + parent::configureVariables(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Override to infer command to composerCommand |
50
|
|
|
* |
51
|
|
|
* @param string $name The name |
52
|
|
|
* @param mixed $value The value |
53
|
|
|
* |
54
|
|
|
* @return $this |
55
|
|
|
*/ |
56
|
|
|
public function offsetSet($name, $value) |
57
|
|
|
{ |
58
|
|
|
if ($name === 'command') { |
59
|
|
|
parent::offsetSet('composerCommand', $value); |
60
|
|
|
$value = 'composer ' . $value; |
61
|
|
|
} |
62
|
|
|
parent::offsetSet($name, $value); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Run the task |
67
|
|
|
* |
68
|
|
|
* @return mixed |
69
|
|
|
*/ |
70
|
|
|
public function run() |
71
|
|
|
{ |
72
|
|
|
$this->preview(); |
73
|
|
|
if ($this->shouldExecute() && in_array($this->get('composerCommand'), array('update', 'install'), true)) { |
74
|
|
|
$this->expand('{composer.invalidatePackages()}'); |
75
|
|
|
} |
76
|
|
|
return $this->execute(); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Get the command with options and arguments |
81
|
|
|
* |
82
|
|
|
* @return string |
83
|
|
|
*/ |
84
|
|
|
protected function getCommand() |
85
|
|
|
{ |
86
|
|
|
$cmd = $this->get('command'); |
87
|
|
|
$argv = substr(parent::getCommand(), strlen($cmd)) . ' '; |
88
|
|
|
if (strpos($argv, ' --no-ansi ') === false |
89
|
|
|
&& strpos($argv, ' --ansi ') === false |
90
|
|
|
&& $this->console->getOutput()->isDecorated() |
91
|
|
|
) { |
92
|
|
|
$argv = ' --ansi' . $argv; |
93
|
|
|
} |
94
|
|
|
if (!$this->shouldExecute() |
95
|
|
|
&& strpos($argv, ' --dry-run ') === false |
96
|
|
|
) { |
97
|
|
|
$argv = ' --dry-run' . $argv; |
98
|
|
|
} |
99
|
|
|
return $cmd . rtrim($argv); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
?> |
103
|
|
|
|