Extends
lithium\console\Command
Install plugins or extensions to the current application.
For plugins, the install commands specified in the formula is run.
Parameters
- string $name name of plugin to add
Returns
booleanSource
public function install($name = null) {
$results = array();
foreach ($this->_settings['servers'] as $server => $enabled) {
if (!$enabled) { continue; }
$service = $this->_instance('service', array(
'host' => $server, 'port' => $this->port
));
if ($plugin = json_decode($service->get("lab/{$name}.json"))) {
break;
}
}
if (empty($plugin->sources)) {
$this->error("{$name} not found.");
return false;
}
$hasGit = function () {
return (strpos(shell_exec('git --version'), 'git version') !== false);
};
foreach ((array) $plugin->sources as $source) {
if (strpos($source, 'phar.gz') !== false && file_exists($source)) {
$written = file_put_contents(
"{$this->path}/{$plugin->name}.phar.gz", file_get_contents($source)
);
if (!$written) {
$this->error("{$plugin->name}.phar.gz could not be saved");
return false;
}
$this->out("{$plugin->name}.phar.gz saved to {$this->path}");
try {
$archive = new Phar("{$this->path}/{$plugin->name}.phar.gz");
if ($archive->extractTo("{$this->path}/{$plugin->name}")) {
$this->out("{$plugin->name} installed to {$this->path}/{$plugin->name}");
$this->out("Remember to update the bootstrap.");
return true;
}
} catch (Exception $e) {
$this->error($e->getMessage());
}
}
$url = parse_url($source);
if (!empty($url['scheme']) && $url['scheme'] == 'git' && $hasGit()) {
$result = shell_exec(
"cd {$this->path} && git clone {$source} {$plugin->name}"
);
if (is_dir("{$this->path}/{$plugin->name}")) {
$this->out("{$plugin->name} installed to {$this->path}/{$plugin->name}");
$this->out("Remember to update the bootstrap.");
return true;
}
}
}
$this->out("{$plugin->name} not installed.");
return false;
}