GetOptionKit\OptionCollection::addOption PHP Method

addOption() public method

Add option object.
public addOption ( Option $spec )
$spec Option the option object.
    public function addOption(Option $spec)
    {
        $this->data[$spec->getId()] = $spec;
        if ($spec->long) {
            $this->longOptions[$spec->long] = $spec;
        }
        if ($spec->short) {
            $this->shortOptions[$spec->short] = $spec;
        }
        $this->options[] = $spec;
        if (!$spec->long && !$spec->short) {
            throw new Exception('Neither long option name nor short name is not given.');
        }
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * @expectedException Exception
  */
 public function testInvalidOption()
 {
     $options = new OptionCollection();
     $options->addOption(new Option(0));
 }