Returns whether the argument is required.
public isRequired ( ) : boolean | ||
return | boolean | Returns `true` if the flag {@link REQUIRED} was passed to the constructor. |
/** * Creates an input argument for the given argument. * * @param Argument $argument The argument. * * @return InputArgument The created input argument. */ private function adaptArgument(Argument $argument) { $mode = null; if ($argument->isMultiValued()) { $mode |= InputArgument::IS_ARRAY; } if ($argument->isOptional()) { $mode |= InputArgument::OPTIONAL; } if ($argument->isRequired()) { $mode |= InputArgument::REQUIRED; } return new InputArgument($argument->getName(), $mode, $argument->getDescription(), $argument->getDefaultValue()); }
/** * Adds an argument at the end of the argument list. * * The existing arguments stored in the builder are preserved. * * You cannot add arguments after adding a multi-valued argument. If you do * so, this method throws an exception. * * Adding required arguments after optional arguments is not supported. * Also in this case an exception is thrown. * * @param Argument $argument The argument to add. * * @return static The current instance. * * @throws CannotAddArgumentException If the argument cannot be added. */ public function addArgument(Argument $argument) { $name = $argument->getName(); if ($this->hasArgument($name)) { throw CannotAddArgumentException::existsAlready($name); } if ($this->hasMultiValuedArgument()) { throw CannotAddArgumentException::cannotAddAfterMultiValued(); } if ($argument->isRequired() && $this->hasOptionalArgument()) { throw CannotAddArgumentException::cannotAddRequiredAfterOptional(); } if ($argument->isMultiValued()) { $this->hasMultiValuedArg = true; } if ($argument->isOptional()) { $this->hasOptionalArg = true; } $this->arguments[$name] = $argument; return $this; }
public function testMultiValuedArgumentWithDefaultValue() { $argument = new Argument('argument', Argument::MULTI_VALUED, null, array('one', 'two')); $this->assertSame('argument', $argument->getName()); $this->assertFalse($argument->isRequired()); $this->assertTrue($argument->isOptional()); $this->assertTrue($argument->isMultiValued()); $this->assertSame(array('one', 'two'), $argument->getDefaultValue()); $this->assertNull($argument->getDescription()); }