示例#1
0
 /**
  * @covers Opl_Getopt_Option::__construct
  * @covers Opl_Getopt_Option::getLongFlag
  */
 public function testSettingLongFlagValid()
 {
     $option = new Opl_Getopt_Option('foo', null, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_');
     $this->assertEquals('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_', $option->getLongFlag());
 }
示例#2
0
 /**
  * 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;
     }
 }