/** * * @param string $name * @param int $length * @param mixed $default */ public function addArgument($name, $length = 1, $default = null) { //TODO check unique name $argument = new CommandArgument($name, $length); if ($default !== null) { $argument->setDefault($default); } $this->arguments[] = $argument; }
/** * * @param CommandArgument $argument * @param int $index * @return mixed * @throws CommandInvalidArgumentLengthException */ private function getValue(CommandArgument $argument, $index) { $length = $argument->getLength(); if ($length == 0) { return true; } $value = []; for ($i = $index + 1, $j = $length; $i < count($this->arguments) && $j > 0; $i++, $j--) { $value[] = $this->arguments[$i]; } if ($j != 0) { throw new CommandInvalidArgumentLengthException($argument->getName(), $argument->getLength(), $argument->getLength() - $j); } if (count($value) == 1) { $value = $value[0]; } return $value; }