Ejemplo n.º 1
0
 /**
  * Validates the option instance.
  *
  * @return void
  * @throws PEAR2\Console\CommandLine_Exception
  * @todo use exceptions instead
  */
 public function validate()
 {
     // check if the option name is valid
     if (!preg_match('/^[a-zA-Z_\x7f-\xff]+[a-zA-Z0-9_\x7f-\xff]*$/',
         $this->name)) {
         Console\CommandLine::triggerError('option_bad_name',
             E_USER_ERROR, array('{$name}' => $this->name));
     }
     // call the parent validate method
     parent::validate();
     // a short_name or a long_name must be provided
     if ($this->short_name == null && $this->long_name == null) {
         Console\CommandLine::triggerError('option_long_and_short_name_missing',
             E_USER_ERROR, array('{$name}' => $this->name));
     }
     // check if the option short_name is valid
     if ($this->short_name != null && 
         !(preg_match('/^\-[a-zA-Z]{1}$/', $this->short_name))) {
         Console\CommandLine::triggerError('option_bad_short_name',
             E_USER_ERROR, array(
                 '{$name}' => $this->name, 
                 '{$short_name}' => $this->short_name
             ));
     }
     // check if the option long_name is valid
     if ($this->long_name != null && 
         !preg_match('/^\-\-[a-zA-Z]+[a-zA-Z0-9_\-]*$/', $this->long_name)) {
         Console\CommandLine::triggerError('option_bad_long_name',
             E_USER_ERROR, array(
                 '{$name}' => $this->name, 
                 '{$long_name}' => $this->long_name
             ));
     }
     // check if we have a valid action
     if (!is_string($this->action)) {
         Console\CommandLine::triggerError('option_bad_action',
             E_USER_ERROR, array('{$name}' => $this->name));
     }
     if (!isset(Console\CommandLine::$actions[$this->action])) {
         Console\CommandLine::triggerError('option_unregistered_action',
             E_USER_ERROR, array(
                 '{$action}' => $this->action,
                 '{$name}' => $this->name
             ));
     }
     // if the action is a callback, check that we have a valid callback
     if ($this->action == 'Callback' && !is_callable($this->callback)) {
         Console\CommandLine::triggerError('option_invalid_callback',
             E_USER_ERROR, array('{$name}' => $this->name));
     }
 }
Ejemplo n.º 2
0
 /**
  * Validates the option instance.
  *
  * @return void
  * @throws ConfigParser_Exception
  * @todo use exceptions instead
  */
 public function validate()
 {
     // check if the option name is valid
     if (!preg_match('/^[a-zA-Z_\\x7f-\\xff]+[a-zA-Z0-9_\\x7f-\\xff]*$/', $this->name)) {
         ConfigParser::triggerError('option_bad_name', E_USER_ERROR, array('{$name}' => $this->name));
     }
     // call the grandparent validate method
     Console\CommandLine\Element::validate();
     // a path must be provided
     if ($this->path == null) {
         ConfigParser::triggerError('option_long_and_short_name_missing', E_USER_ERROR, array('{$name}' => $this->name));
     }
     // check if we have a valid action
     if (!is_string($this->action)) {
         ConfigParser::triggerError('option_bad_action', E_USER_ERROR, array('{$name}' => $this->name));
     }
     //var_dump(ConfigParser::$actions[$this->action]);
     if (!isset(Console\CommandLine::$actions[$this->action]) && !isset(ConfigParser::$actions[$this->action])) {
         ConfigParser::triggerError('option_unregistered_action', E_USER_ERROR, array('{$action}' => $this->action, '{$name}' => $this->name));
     }
     // if the action is a callback, check that we have a valid callback
     if ($this->action == 'Callback' && !is_callable($this->callback)) {
         ConfigParser::triggerError('option_invalid_callback', E_USER_ERROR, array('{$name}' => $this->name));
     }
 }