/** * Gets the task name for the task * * @return string */ public function __toString() { static $task_name = NULL; if ($task_name === NULL) { $task_name = Minion_Util::convert_class_to_task($this); } return $task_name; }
/** * Prints out the help for a specific task * */ public function action_help() { $tasks = Minion_Util::compile_task_list(Kohana::list_files('classes/minion/task')); $view = NULL; if (empty($this->_task)) { $view = new View('minion/help/list'); $view->tasks = $tasks; } else { $inspector = new ReflectionClass($this->_retrieve_task()); list($description, $tags) = Minion_Util::parse_doccomment($inspector->getDocComment()); $view = View::factory('minion/help/task')->set('description', $description)->set('tags', (array) $tags)->set('task', $this->_task); } echo $view; }
/** * Compiles a list of available tasks from a directory structure * * @param array Directory structure of tasks * @return array Compiled tasks */ public static function compile_task_list(array $files, $prefix = '') { $output = array(); foreach ($files as $file => $path) { $file = substr($file, strrpos($file, DIRECTORY_SEPARATOR) + 1); if (is_array($path) and count($path)) { $task = Minion_Util::compile_task_list($path, $prefix . $file . Minion_Util::$task_separator); if ($task) { $output = array_merge($output, $task); } } else { $output[] = strtolower($prefix . substr($file, 0, -strlen(EXT))); } } return $output; }
/** * Tests that the task name can be found from a class name / object * * @test * @covers Minion_Util::convert_class_to_task * @dataProvider provider_convert_class_to_task * @param string Expected task name * @param mixed Input class */ public function test_convert_class_to_task($expected, $class) { $this->assertSame($expected, Minion_Util::convert_class_to_task($class)); }