本文整理匯總了PHP中Fuel::list_files方法的典型用法代碼示例。如果您正苦於以下問題:PHP Fuel::list_files方法的具體用法?PHP Fuel::list_files怎麽用?PHP Fuel::list_files使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Fuel
的用法示例。
在下文中一共展示了Fuel::list_files方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: run
public static function run($task, $args)
{
// Make sure something is set
if ($task === null or $task === 'help') {
static::help();
return;
}
// Just call and run() or did they have a specific method in mind?
list($task, $method) = array_pad(explode(':', $task), 2, 'run');
$task = ucfirst(strtolower($task));
// Find the task
if (!($file = \Fuel::find_file('tasks', $task))) {
$files = \Fuel::list_files('tasks');
$possibilities = array();
foreach ($files as $file) {
$possible_task = pathinfo($file, \PATHINFO_FILENAME);
$difference = levenshtein($possible_task, $task);
$possibilities[$difference] = $possible_task;
}
ksort($possibilities);
if ($possibilities and current($possibilities) <= 5) {
throw new Exception(sprintf('Task "%s" does not exist. Did you mean "%s"?', strtolower($task), current($possibilities)));
} else {
throw new Exception(sprintf('Task "%s" does not exist.', strtolower($task)));
}
return;
}
require $file;
$task = '\\Fuel\\Tasks\\' . $task;
$new_task = new $task();
// The help option hs been called, so call help instead
if (\Cli::option('help') && is_callable(array($new_task, 'help'))) {
$method = 'help';
}
if ($return = call_user_func_array(array($new_task, $method), $args)) {
\Cli::write($return);
}
}
示例2: _discover_tasks
/**
* Find all of the task classes in the system and use reflection to discover the
* commands we can call.
*
* @return array $taskname => array($taskmethods)
**/
protected static function _discover_tasks()
{
$result = array();
$files = \Fuel::list_files('tasks');
if (count($files) > 0) {
foreach ($files as $file) {
$task_name = str_replace('.php', '', basename($file));
$class_name = '\\Fuel\\Tasks\\' . $task_name;
require $file;
$reflect = new \ReflectionClass($class_name);
// Ensure we only pull out the public methods
$methods = $reflect->getMethods(\ReflectionMethod::IS_PUBLIC);
$result[$task_name] = array();
if (count($methods) > 0) {
foreach ($methods as $method) {
$result[$task_name][] = $method->name;
}
}
}
}
return $result;
}