1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Rocketeer |
5
|
|
|
* |
6
|
|
|
* (c) Maxime Fabre <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
* |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Rocketeer\Tasks\Plugins; |
14
|
|
|
|
15
|
|
|
use Rocketeer\Tasks\AbstractTask; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Installs one or more plugins. |
19
|
|
|
*/ |
20
|
|
|
class Installer extends AbstractTask |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* The console command description. |
24
|
|
|
* |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $description = 'Installs one or more plugins'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Whether to run the commands locally |
31
|
|
|
* or on the server. |
32
|
|
|
* |
33
|
|
|
* @var bool |
34
|
|
|
*/ |
35
|
|
|
protected $local = true; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* {@inheritdoc} |
39
|
|
|
*/ |
40
|
8 |
|
public function execute() |
41
|
|
|
{ |
42
|
|
|
// Get package and destination folder |
43
|
8 |
|
$package = $this->getPackage(); |
44
|
8 |
|
$method = $package ? 'require' : 'install'; |
45
|
|
|
|
46
|
8 |
|
if (!$this->files->has($this->paths->getRocketeerPath().'/composer.json')) { |
|
|
|
|
47
|
6 |
|
$this->igniter->exportComposerFile(); |
48
|
6 |
|
} |
49
|
|
|
|
50
|
|
|
// Install plugin |
51
|
8 |
|
$this->explainer->line($package ? 'Installing '.$package : 'Setting up Composer'); |
52
|
8 |
|
$this->runComposerMethod($method, $package); |
|
|
|
|
53
|
8 |
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param string $method |
57
|
|
|
* @param string|string[] $arguments |
58
|
|
|
*/ |
59
|
8 |
|
protected function runComposerMethod($method, $arguments) |
60
|
|
|
{ |
61
|
8 |
|
$noDev = $method === 'install' ? '--no-dev' : '--update-no-dev'; |
62
|
8 |
|
$options = [$noDev => '', '--working-dir' => $this->paths->getRocketeerPath()]; |
|
|
|
|
63
|
8 |
|
$env = ['COMPOSER_DISCARD_CHANGES' => 1]; |
64
|
|
|
|
65
|
|
|
// Install plugin |
66
|
8 |
|
$command = $this->composer()->$method($arguments, $options, $env); |
67
|
8 |
|
$this->run($this->shellCommand($command)); |
|
|
|
|
68
|
8 |
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return array|null|string |
72
|
|
|
*/ |
73
|
8 |
|
protected function getPackage() |
74
|
|
|
{ |
75
|
8 |
|
return array_key_exists('package', $this->command->getInput()->getArguments()) |
76
|
8 |
|
? $this->command->argument('package') |
77
|
8 |
|
: null; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: