/** * Registers a new option in the Getopt parser. If the option is * already registered under the specified name (which is hold * by the $option object), the method throws an exception. * * @throws Opl_Getopt_Exception * @param Opl_Getopt_Option $option The option to register. */ public function addOption(Opl_Getopt_Option $option) { $name = (string) $option->getName(); if (isset($this->_availableOpts[$name])) { throw new Opl_Getopt_Exception('The option ' . $name . ' is already registered in getopt.'); } $this->_availableOpts[$name] = $option; $ok = false; if (($flag = $option->getShortFlag()) !== null) { if (isset($this->_shortFlags[$flag])) { throw new Opl_Getopt_Exception('The option ' . $name . ' tries to register -' . $flag . ' which is already registered.'); } $this->_shortFlags[$flag] = $option; $ok = true; } if (($flag = $option->getLongFlag()) !== null) { if (isset($this->_longFlags[$flag])) { throw new Opl_Getopt_Exception('The option ' . $name . ' tries to register --' . $flag . ' which is already registered.'); } $this->_longFlags[$flag] = $option; $ok = true; } if (!$ok) { if ($this->_data !== null) { throw new Opl_Getopt_Exception('The plain text option ' . $name . ' is already registered in getopt.'); } $this->_data = $option; } }
/** * @covers Opl_Getopt_Option::__construct * @covers Opl_Getopt_Option::getName */ public function testSettingName() { $option = new Opl_Getopt_Option('foo'); $this->assertEquals('foo', $option->getName()); }