src/Console.php
public function loadCommands($path, $prefix = null) {
        // load commands
        try {
            $iterator = new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS);

            /** @var \RecursiveDirectoryIterator $child */
            foreach($iterator as $child)
                if($child->isFile() && \preg_match('/Command.php$/', $child->getBasename())) {
                    $namespace = $class = "";
                    $gettingNamespace = $gettingClass = false;
                    foreach(\token_get_all(\file_get_contents($child->getRealPath())) as $token) {
                        if(\is_array($token) && ($token[0] === T_ABSTRACT || $token[0] === T_INTERFACE)) {
                            $namespace = $class = '';
                            break;
                        }
                        if(\is_array($token) && $token[0] === T_NAMESPACE)
                            $gettingNamespace = true;
                        if(\is_array($token) && $token[0] === T_CLASS)
                            $gettingClass = true;
                        if($gettingNamespace === true)
                            if(\is_array($token) && \in_array($token[0], [T_STRING, T_NS_SEPARATOR]))
                                $namespace .= $token[1];
                            else if($token === ';')
                                $gettingNamespace = false;
                        if($gettingClass === true)
                            if(\is_array($token) && $token[0] === T_STRING) {
                                $class = $token[1];
                                break;
                            }
                    }

                    $className = $namespace ? $namespace . '\\' . $class : $class;
                    if(\preg_match('/Command$/', $className) > 0) {
                        // make sure file with class is loaded
                        require_once $child->getRealPath();
                        /** @var Command $command */
                        $command = new $className;
                        if($prefix !== null)
                            $command->setName($prefix . ':' . $command->getName());
                        $this['console']->add($command);
                    }
                }
        } catch(\UnexpectedValueException $ex) {
            // do nothing - no commands to load
        }
    }
public function loadCommands($path, $prefix = null) {
        // load commands
        try {
            $iterator = new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS);

            /** @var \RecursiveDirectoryIterator $child */
            foreach($iterator as $child)
                if($child->isFile() && \preg_match('/Command.php$/', $child->getBasename())) {
                    $namespace = $class = "";
                    $gettingNamespace = $gettingClass = false;
                    foreach(\token_get_all(\file_get_contents($child->getRealPath())) as $token) {
                        if(\is_array($token) && ($token[0] === T_ABSTRACT || $token[0] === T_INTERFACE)) {
                            $namespace = $class = '';
                            break;
                        }
                        if(\is_array($token) && $token[0] === T_NAMESPACE)
                            $gettingNamespace = true;
                        if(\is_array($token) && $token[0] === T_CLASS)
                            $gettingClass = true;
                        if($gettingNamespace === true)
                            if(\is_array($token) && \in_array($token[0], [T_STRING, T_NS_SEPARATOR]))
                                $namespace .= $token[1];
                            else if($token === ';')
                                $gettingNamespace = false;
                        if($gettingClass === true)
                            if(\is_array($token) && $token[0] === T_STRING) {
                                $class = $token[1];
                                break;
                            }
                    }

                    $className = $namespace ? $namespace . '\\' . $class : $class;
                    if(\preg_match('/Command$/', $className) > 0) {
                        // make sure file with class is loaded
                        require_once $child->getRealPath();
                        /** @var Command $command */
                        $command = new $className;
                        if($prefix !== null)
                            $command->setName($prefix . ':' . $command->getName());
                        $this['console']->add($command);
                    }
                }
        } catch(\UnexpectedValueException $ex) {
            // do nothing - no commands to load
        }
    }
public function loadCommands ( $ path , $ prefix = null ) { // load commands try { $ iterator = new \ RecursiveDirectoryIterator ( $ path , \ FilesystemIterator :: SKIP_DOTS ) ; /** @var \RecursiveDirectoryIterator $child */ foreach ( $ iterator as $ child ) if ( $ child -> isFile ( ) && \ preg_match ( '/Command.php$/' , $ child -> getBasename ( ) ) ) { $ namespace = $ class = "" ; $ gettingNamespace = $ gettingClass = false ; foreach ( \ token_get_all ( \ file_get_contents ( $ child -> getRealPath ( ) ) ) as $ token ) { if ( \ is_array ( $ token ) && ( $ token [ 0 ] === T_ABSTRACT || $ token [ 0 ] === T_INTERFACE ) ) { $ namespace = $ class = '' ; break ; } if ( \ is_array ( $ token ) && $ token [ 0 ] === T_NAMESPACE ) $ gettingNamespace = true ; if ( \ is_array ( $ token ) && $ token [ 0 ] === T_CLASS ) $ gettingClass = true ; if ( $ gettingNamespace === true ) if ( \ is_array ( $ token ) && \ in_array ( $ token [ 0 ] , [ T_STRING , T_NS_SEPARATOR ] ) ) $ namespace .= $ token [ 1 ] ; else if ( $ token === ';' ) $ gettingNamespace = false ; if ( $ gettingClass === true ) if ( \ is_array ( $ token ) && $ token [ 0 ] === T_STRING ) { $ class = $ token [ 1 ] ; break ; } } $ className = $ namespace ? $ namespace . '\\' . $ class : $ class ; if ( \ preg_match ( '/Command$/' , $ className ) > 0 ) { // make sure file with class is loaded require_once $ child -> getRealPath ( ) ; /** @var Command $command */ $ command = new $ className ; if ( $ prefix !== null ) $ command -> setName ( $ prefix . ':' . $ command -> getName ( ) ) ; $ this [ 'console' ] -> add ( $ command ) ; } } } catch ( \ UnexpectedValueException $ ex ) { // do nothing - no commands to load } }
Load all Command files from $path directory.

Traverse all files inside specified directory, but loads only those files with suffix 'Command.php'.

@param string      $path   Directory with Command files
@param string|null $prefix Commands namespace

@return void
Load all Command files from $path directory .