libs/App/Command.php
/**
     * Import and add a command from a php script.
     *
     * @param   string      $name               Name of command to import.
     * @param   string      $class              Name of class to import command from, must implent \Octris\App\CommandInterface.
     * @param   array       $inject             Arguments to inject into command instance.
     * @param   callable    $default_command    Optional default command (default: help).
     * @return  \Aaparser\Command               Instance of new object.
     */
Import and add a command from a php script.
@param   string      $name               Name of command to import.
@param   string      $class              Name of class to import command from, must implent \Octris\App\CommandInterface.
@param   array       $inject             Arguments to inject into command instance.
@param   callable    $default_command    Optional default command (default: help).
@return  \Aaparser\Command               Instance of new object.
Import and add a command from a php script . @param string $name Name of command to import . @param string $class Name of class to import command from must implent \ Octris \ App \ CommandInterface . @param array $inject Arguments to inject into command instance . @param callable $default_command Optional default command ( default : help ) . @return \ Aaparser \ Command Instance of new object .
public function importCommand($name, $class, array $inject = [], callable $default_command = null)
    {
        if (!is_subclass_of($class, '\Octris\Cli\App\CommandInterface')) {
            throw new \InvalidArgumentException('Class is not a valid command "' . $class . '".');
        }
        $cmd = $this->addCommand($name);
        $cmd->setAction(function(array $options, array $operands) use ($class, $inject) {
            $instance = new $class(...$inject);
            $instance->run($options, $operands, new Output());
        });
        if (is_null($default_command)) {
            $default_command = function() use ($cmd) {
                $this->app->printHelp($cmd);
            };
        }
        $cmd->setDefaultAction($default_command);
        $class::configure($cmd);
        return $cmd;
    }
public function importCommand ( $ name , $ class , array $ inject = [ ] , callable $ default_command = null ) { if ( ! is_subclass_of ( $ class , '\Octris\Cli\App\CommandInterface' ) ) { throw new \ InvalidArgumentException ( 'Class is not a valid command "' . $ class . '".' ) ; } $ cmd = $ this -> addCommand ( $ name ) ; $ cmd -> setAction ( function ( array $ options , array $ operands ) use ( $ class , $ inject ) { $ instance = new $ class ( ... $ inject ) ; $ instance -> run ( $ options , $ operands , new Output ( ) ) ; } ) ; if ( is_null ( $ default_command ) ) { $ default_command = function ( ) use ( $ cmd ) { $ this -> app -> printHelp ( $ cmd ) ; } ; } $ cmd -> setDefaultAction ( $ default_command ) ; $ class :: configure ( $ cmd ) ; return $ cmd ; }
Import and add a command from a php script.
Import and add a command from a php script .