/** * @param string $long long name of option * @param bool $short short name of option * @param string $description description of option. Default value is empty * @param int $type option value type. Default value is boolean * @param bool $required option requirements. Default value is false * @throws UnexpectedValueException if value name is empty */ public function __construct($long, $short, $description = '', $type = self::TYPE_BOOLEAN, $required = false) { parent::__construct($description, $required); $this->long = (string) $long; if (empty($this->long)) { throw new UnexpectedValueException(); } $this->short = substr($short, 0, 1); if (empty($this->short)) { throw new UnexpectedValueException(); } $this->type = (int) $type; $this->checkType($type); }
/** * Set event for added parameter * @param Parameter $Parameter adding parameter instance * @param Closure $Handler closure function if parameter will be define * @throws ParameterNotFoundException if $Parameter instance is not added to command * @throws UnsupportedParameterTypeException if $Parameter instance has unsupported type */ public function setEvent(Parameter $Parameter, Closure $Handler) { /** @var $Parameter Option */ switch (true) { case $Parameter instanceof Option: $long = $Parameter->getLong(); if (isset($this->parameters[$long])) { $this->events[$long] = $Handler; } else { throw new ParameterNotFoundException(); } break; default: throw new UnsupportedParameterTypeException(); } }