1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nwidart\Modules\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use Nwidart\Modules\Process\Installer; |
7
|
|
|
use Pingpong\Support\Json; |
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
9
|
|
|
use Symfony\Component\Console\Input\InputOption; |
10
|
|
|
|
11
|
|
|
class InstallCommand extends Command |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* The console command name. |
15
|
|
|
* |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
protected $name = 'module:install'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* The console command description. |
22
|
|
|
* |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected $description = 'Install the specified module by given package name (vendor/name).'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Create a new command instance. |
29
|
|
|
*/ |
30
|
16 |
|
public function __construct() |
31
|
|
|
{ |
32
|
16 |
|
parent::__construct(); |
33
|
16 |
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Execute the console command. |
37
|
|
|
* |
38
|
|
|
* @return mixed |
39
|
|
|
*/ |
40
|
|
|
public function fire() |
41
|
|
|
{ |
42
|
|
|
if (is_null($this->argument('name'))) { |
43
|
|
|
$this->installFromFile(); |
44
|
|
|
|
45
|
|
|
return; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
$this->install( |
49
|
|
|
$this->argument('name'), |
|
|
|
|
50
|
|
|
$this->argument('version'), |
|
|
|
|
51
|
|
|
$this->option('type'), |
|
|
|
|
52
|
|
|
$this->option('tree') |
|
|
|
|
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Install modules from modules.json file. |
58
|
|
|
*/ |
59
|
|
|
protected function installFromFile() |
60
|
|
|
{ |
61
|
|
|
if (!file_exists($path = base_path('modules.json'))) { |
62
|
|
|
$this->error("File 'modules.json' does not exist in your project root."); |
63
|
|
|
|
64
|
|
|
return; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$modules = Json::make($path); |
68
|
|
|
|
69
|
|
|
$dependencies = $modules->get('require', []); |
70
|
|
|
|
71
|
|
|
foreach ($dependencies as $module) { |
72
|
|
|
$module = collect($module); |
73
|
|
|
|
74
|
|
|
$this->install( |
75
|
|
|
$module->get('name'), |
76
|
|
|
$module->get('version'), |
77
|
|
|
$module->get('type') |
78
|
|
|
); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Install the specified module. |
84
|
|
|
* |
85
|
|
|
* @param string $name |
86
|
|
|
* @param string $version |
87
|
|
|
* @param string $type |
88
|
|
|
* @param bool $tree |
89
|
|
|
*/ |
90
|
|
|
protected function install($name, $version = 'dev-master', $type = 'composer', $tree = false) |
91
|
|
|
{ |
92
|
|
|
$installer = new Installer( |
93
|
|
|
$name, |
94
|
|
|
$version, |
95
|
|
|
$type ?: $this->option('type'), |
|
|
|
|
96
|
|
|
$tree ?: $this->option('tree') |
97
|
|
|
); |
98
|
|
|
|
99
|
|
|
$installer->setRepository($this->laravel['modules']); |
100
|
|
|
|
101
|
|
|
$installer->setConsole($this); |
102
|
|
|
|
103
|
|
|
if ($timeout = $this->option('timeout')) { |
104
|
|
|
$installer->setTimeout($timeout); |
|
|
|
|
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
if ($path = $this->option('path')) { |
108
|
|
|
$installer->setPath($path); |
|
|
|
|
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
$installer->run(); |
112
|
|
|
|
113
|
|
|
if (!$this->option('no-update')) { |
114
|
|
|
$this->call('module:update', [ |
115
|
|
|
'module' => $installer->getModuleName(), |
116
|
|
|
]); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Get the console command arguments. |
122
|
|
|
* |
123
|
|
|
* @return array |
124
|
|
|
*/ |
125
|
16 |
|
protected function getArguments() |
126
|
|
|
{ |
127
|
|
|
return array( |
128
|
16 |
|
array('name', InputArgument::OPTIONAL, 'The name of module will be installed.'), |
129
|
16 |
|
array('version', InputArgument::OPTIONAL, 'The version of module will be installed.'), |
130
|
16 |
|
); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Get the console command options. |
135
|
|
|
* |
136
|
|
|
* @return array |
137
|
|
|
*/ |
138
|
16 |
|
protected function getOptions() |
139
|
|
|
{ |
140
|
|
|
return array( |
141
|
16 |
|
array('timeout', null, InputOption::VALUE_OPTIONAL, 'The process timeout.', null), |
142
|
16 |
|
array('path', null, InputOption::VALUE_OPTIONAL, 'The installation path.', null), |
143
|
16 |
|
array('type', null, InputOption::VALUE_OPTIONAL, 'The type of installation.', null), |
144
|
16 |
|
array('tree', null, InputOption::VALUE_NONE, 'Install the module as a git subtree', null), |
145
|
16 |
|
array('no-update', null, InputOption::VALUE_NONE, 'Disables the automatic update of the dependencies.', null), |
146
|
16 |
|
); |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.