'index',
'$TaskName' => 'runTask'
);
function index() {
$tasks = $this->getTasks();
// Web mode
if(!Director::is_cli()) {
$renderer = new DebugView();
$renderer->writeHeader();
$renderer->writeInfo("Sapphire Development Tools: Tasks", Director::absoluteBaseURL());
$base = Director::baseURL();
echo "
";
foreach($tasks as $task) {
echo "- ";
echo "" . $task['title'] . "
";
echo "" . $task['description'] . "";
echo " \n";
}
echo "
";
$renderer->writeFooter();
// CLI mode
} else {
echo "SAPPHIRE DEVELOPMENT TOOLS: Tasks\n--------------------------\n\n";
foreach($tasks as $task) {
echo " * $task: sake dev/tasks/" . $task['class'] . "\n";
}
}
}
function runTask($request) {
$taskName = $request->param('TaskName');
if (class_exists($taskName) && is_subclass_of($taskName, 'BuildTask')) {
$title = singleton($taskName)->getTitle();
if(Director::is_cli()) echo "Running task '$title'...\n\n";
else echo "Running task '$title'...
\n";
$task = new $taskName();
if ($task->isEnabled()) $task->run($request);
} else {
echo "Build task '$taskName' not found.";
if(class_exists($taskName)) echo " It isn't a subclass of BuildTask.";
echo "\n";
}
}
/**
* @return array Array of associative arrays for each task (Keys: 'class', 'title', 'description')
*/
protected function getTasks() {
$availableTasks = array();
$taskClasses = ClassInfo::subclassesFor('BuildTask');
// remove the base class
array_shift($taskClasses);
if($taskClasses) foreach($taskClasses as $class) {
if(!singleton($class)->isEnabled()) continue;
$desc = (Director::is_cli()) ? Convert::html2raw(singleton($class)->getDescription()) : singleton($class)->getDescription();
$availableTasks[] = array(
'class' => $class,
'title' => singleton($class)->getTitle(),
'description' => $desc,
);
}
return $availableTasks;
}
}
?>