mako\reactor\handlers\Tasks


Description


Task handler.


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)


Runs the chosen task.


Parameters

Type Description
array Arguments
Return value

NULL

public static function run($arguments)
{
	if(!empty($arguments))
	{
		if(strpos($arguments[0], '::') !== false)
		{
			list($package, $task) = explode('::', $arguments[0]);

			try
			{
				Package::init($package);
			}
			catch(RuntimeException $e)
			{
				return CLI::stderr($e->getMessage());
			}
		}
		else
		{
			$task = $arguments[0];
		}

		list($task, $method) = explode(':', $task);

		$file = (!empty($package) ? MAKO_PACKAGES . '/' . $package : MAKO_APPLICATION ) . '/tasks/' . $task . '.php';

		if(!file_exists($file))
		{
			return CLI::stderr(vsprintf("The '%s' task does not exist.", array($task)));
		}

		include $file;

		// Validate task class

		$taskClass = new ReflectionClass($task);

		if($taskClass->isSubClassOf('\mako\reactor\Task') === false)
		{
			return CLI::stderr(vsprintf("The '%s' task needs to extend the mako\\reactor\Task class.", array($task)));
		}

		// Run task

		$task = $taskClass->newInstance();

		call_user_func_array(array($task, (empty($method) ? 'run' : $method)), array_slice($arguments, 1));
	}
	else
	{
		Reactor::help();
	}
}