mako\reactor\handlers\Packages


Description


Package installer.


Class methods


Toggle source

protected __construct()


Protected constructor since this is a static class.

Return value

NULL

protected function __construct()
{
	// Nothing here
}

Toggle source

public static run($arguments)


Installs or uninstalls the requested package.


Parameters

Type Description
array Arguments
Return value

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();
}

Toggle source

protected static install($package, $silent = false)


Installs a package.


Parameters

Type Description
string Package name
boolean (optional) Silent install?
Return value

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!');
}

Toggle source

protected static remove($package)


Removes a package.


Parameters

Type Description
string Package name
Return value

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.');
}