protected function compileArguments(ICommand $command, IRequest $request)
    {
        $argumentValues = $request->getArgumentValues();
        $commandArguments = $command->getArguments();

        if ($this->hasTooManyArguments($argumentValues, $commandArguments)) {
            throw new RuntimeException('Too many arguments');
        }

        $hasSetArrayArgument = false;

        foreach ($commandArguments as $argument) {
            if (count($argumentValues) === 0) {
                if (!$argument->isOptional()) {
                    throw new RuntimeException("Argument \"{$argument->getName()}\" does not have default value");
                }

                $command->setArgumentValue($argument->getName(), $argument->getDefaultValue());
            } else {
                if ($hasSetArrayArgument) {
                    throw new RuntimeException('Array argument must appear at end of list of arguments');
                }

                if ($argument->isArray()) {
                    // Add the rest of the values in the request to this argument
                    $restOfArgumentValues = [];

                    while (count($argumentValues) > 0) {
                        $restOfArgumentValues[] = array_shift($argumentValues);
                    }

                    $command->setArgumentValue($argument->getName(), $restOfArgumentValues);
                    $hasSetArrayArgument = true;
                } else {
                    $command->setArgumentValue($argument->getName(), array_shift($argumentValues));
                }
            }
        }
    }
protected function compileArguments(ICommand $command, IRequest $request)
    {
        $argumentValues = $request->getArgumentValues();
        $commandArguments = $command->getArguments();

        if ($this->hasTooManyArguments($argumentValues, $commandArguments)) {
            throw new RuntimeException('Too many arguments');
        }

        $hasSetArrayArgument = false;

        foreach ($commandArguments as $argument) {
            if (count($argumentValues) === 0) {
                if (!$argument->isOptional()) {
                    throw new RuntimeException("Argument \"{$argument->getName()}\" does not have default value");
                }

                $command->setArgumentValue($argument->getName(), $argument->getDefaultValue());
            } else {
                if ($hasSetArrayArgument) {
                    throw new RuntimeException('Array argument must appear at end of list of arguments');
                }

                if ($argument->isArray()) {
                    // Add the rest of the values in the request to this argument
                    $restOfArgumentValues = [];

                    while (count($argumentValues) > 0) {
                        $restOfArgumentValues[] = array_shift($argumentValues);
                    }

                    $command->setArgumentValue($argument->getName(), $restOfArgumentValues);
                    $hasSetArrayArgument = true;
                } else {
                    $command->setArgumentValue($argument->getName(), array_shift($argumentValues));
                }
            }
        }
    }
protected function compileArguments ( ICommand $ command , IRequest $ request ) { $ argumentValues = $ request -> getArgumentValues ( ) ; $ commandArguments = $ command -> getArguments ( ) ; if ( $ this -> hasTooManyArguments ( $ argumentValues , $ commandArguments ) ) { throw new RuntimeException ( 'Too many arguments' ) ; } $ hasSetArrayArgument = false ; foreach ( $ commandArguments as $ argument ) { if ( count ( $ argumentValues ) === 0 ) { if ( ! $ argument -> isOptional ( ) ) { throw new RuntimeException ( "Argument \"{$argument->getName()}\" does not have default value" ) ; } $ command -> setArgumentValue ( $ argument -> getName ( ) , $ argument -> getDefaultValue ( ) ) ; } else { if ( $ hasSetArrayArgument ) { throw new RuntimeException ( 'Array argument must appear at end of list of arguments' ) ; } if ( $ argument -> isArray ( ) ) { // Add the rest of the values in the request to this argument $ restOfArgumentValues = [ ] ; while ( count ( $ argumentValues ) > 0 ) { $ restOfArgumentValues [ ] = array_shift ( $ argumentValues ) ; } $ command -> setArgumentValue ( $ argument -> getName ( ) , $ restOfArgumentValues ) ; $ hasSetArrayArgument = true ; } else { $ command -> setArgumentValue ( $ argument -> getName ( ) , array_shift ( $ argumentValues ) ) ; } } } }
Compiles arguments in a command

@param ICommand $command The command to compile
@param IRequest $request The user request
@throws RuntimeException Thrown if there are too many arguments
Compiles arguments in a command