ConsoleKit\Console::addCommandsFromDir PHP Метод

addCommandsFromDir() публичный Метод

Registers commands from a directory
public addCommandsFromDir ( string $dir, string $namespace = '', boolean $includeFiles = false ) : Console
$dir string
$namespace string
$includeFiles boolean
Результат Console
    public function addCommandsFromDir($dir, $namespace = '', $includeFiles = false)
    {
        foreach (new DirectoryIterator($dir) as $file) {
            $filename = $file->getFilename();
            if ($file->isDir() || substr($filename, 0, 1) === '.' || strlen($filename) <= 11 || strtolower(substr($filename, -11)) !== 'command.php') {
                continue;
            }
            if ($includeFiles) {
                include $file->getPathname();
            }
            $className = trim($namespace . '\\' . substr($filename, 0, -4), '\\');
            $this->addCommand($className);
        }
        return $this;
    }

Usage Example

Пример #1
0
 /**
  * Display the console and execute callbacks associated
  * to the command
  */
 public static function onAtomikStart()
 {
     $paths = (array) self::$config['scripts_dir'];
     foreach (Atomik::getLoadedPlugins(true) as $plugin => $path) {
         $paths[] = "{$path}/scripts";
     }
     foreach (array_filter(array_map('realpath', $paths)) as $path) {
         self::$console->addCommandsFromDir($path, '', true);
     }
     self::$console->run();
     exit;
 }