Task handler.
Protected constructor since this is a static class.
NULL
protected function __construct()
{
// Nothing here
}
Runs the chosen task.
| Type | Description |
|---|---|
| array | Arguments |
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();
}
}