/** * Creates a new option. * * @param string $longName The long option name. * @param string|null $shortName The short option name. * @param int $flags A bitwise combination of the option flag * constants. * @param string $description A human-readable description of the option. * * @throws InvalidValueException If the default value is invalid. */ public function __construct($longName, $shortName = null, $flags = 0, $description = null) { $longName = $this->removeDoubleDashPrefix($longName); $shortName = $this->removeDashPrefix($shortName); Assert::nullOrString($description, 'The option description must be a string or null. Got: %s'); Assert::nullOrNotEmpty($description, 'The option description must not be empty.'); $this->assertFlagsValid($flags); $this->assertLongNameValid($longName); $this->assertShortNameValid($shortName, $flags); $this->longName = $longName; $this->shortName = $shortName; $this->description = $description; $this->addDefaultFlags($flags); $this->flags = $flags; }
/** * Creates a new argument. * * @param string $name The argument name * @param int $flags A bitwise combination of the flag constants. * @param string $description A human-readable description of the argument. * @param mixed $defaultValue The default value of the argument (must be * null for the flag {@link self::REQUIRED}). */ public function __construct($name, $flags = 0, $description = null, $defaultValue = null) { Assert::string($name, 'The argument name must be a string. Got: %s'); Assert::notEmpty($name, 'The argument name must not be empty.'); Assert::startsWithLetter($name, 'The argument name must start with a letter.'); Assert::regex($name, '~^[a-zA-Z0-9\\-]+$~', 'The argument name must contain letters, digits and hyphens only.'); Assert::nullOrString($description, 'The argument description must be a string or null. Got: %s'); Assert::nullOrNotEmpty($description, 'The argument description must not be empty.'); $this->assertFlagsValid($flags); $this->addDefaultFlags($flags); $this->name = $name; $this->flags = $flags; $this->description = $description; $this->defaultValue = $this->isMultiValued() ? array() : null; if ($this->isOptional() || null !== $defaultValue) { $this->setDefaultValue($defaultValue); } }