Package installer.
Protected constructor since this is a static class.
NULL
protected function __construct()
{
// Nothing here
}
Installs or uninstalls the requested package.
| Type | Description |
|---|---|
| array | Arguments |
NULL
public static function run($arguments)
{
if(count($arguments) > 1)
{
switch($arguments[0])
{
case 'i':
case 'install':
foreach(array_slice($arguments, 1) as $package)
{
static::install($package);
}
return;
break;
case 'r':
case 'remove':
foreach(array_slice($arguments, 1) as $package)
{
static::remove($package);
}
return;
}
}
Reactor::help();
}
Installs a package.
| Type | Description |
|---|---|
| string | Package name |
| boolean | (optional) Silent install? |
NULL
protected static function install($package, $silent = false)
{
$repo = true;
if(strpos($package, '://') !== false)
{
$repo = false;
$url = $package;
preg_match('/^(.*):\/\/(.*)\/(.*).git$/i', $package, $matches);
if(empty($matches))
{
return CLI::stderr('Invalid package URL.');
}
$name = $package = $matches[3];
}
if(is_dir(MAKO_PACKAGES . DIRECTORY_SEPARATOR . $package))
{
return ($silent) ? null : CLI::stderr('The ' . $package . ' package has already been installed.');
}
if($repo === true)
{
CLI::stdout('Fetching package info from packages.makoframework.com ...');
$response = Rest::factory(static::API . $package)->get($info);
if($info['http_code'] != 200)
{
return CLI::stderr('No response from server.');
}
$response = json_decode($response);
if($response->status !== 'ok')
{
return CLI::stderr('The ' . $package . ' package does not exist.');
}
foreach($response->package->dependencies as $dep)
{
static::_install($dep, true);
}
$url = sprintf('git://github.com/%s.git', $response->package->repo);
$name = $response->package->name;
}
CLI::stdout(sprintf('Fetching package from %s ...', $url));
passthru(sprintf(MAKO_IS_WINDOWS ? static::INSTALL_W : static::INSTALL_X, $url, MAKO_PACKAGES, $name));
if($repo === true)
{
@file_put_contents(MAKO_PACKAGES . DIRECTORY_SEPARATOR . $package . DIRECTORY_SEPARATOR . 'package.json', json_encode($response->package));
}
CLI::stdout('The '. $package . ' package has been installed!');
}
Removes a package.
| Type | Description |
|---|---|
| string | Package name |
NULL
protected static function remove($package)
{
if(!is_dir(MAKO_PACKAGES . DIRECTORY_SEPARATOR . $package))
{
return CLI::stderr('The ' . $package . ' package is not installed.');
}
CLI::stdout('Deleting ' . $package . ' files ...');
passthru(sprintf(MAKO_IS_WINDOWS ? static::REMOVE_W : static::REMOVE_X, MAKO_PACKAGES, $package));
CLI::stdout('The ' . $package . ' package has been removed.');
}