本文整理汇总了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;
}