original_string: public function addRule($rule, $messageOrRunAt = '', $options = null,
                              $runAt = HTML_QuickForm2_Rule::RUNAT_SERVER)
      {
          if ($rule instanceof HTML_QuickForm2_Rule) {
              $rule->setOwner($this);
              $runAt = '' == $messageOrRunAt? HTML_QuickForm2_Rule::RUNAT_SERVER: $messageOrRunAt;
          } elseif (is_string($rule)) {
              $rule = HTML_QuickForm2_Factory::createRule($rule, $this, $messageOrRunAt, $options);
          } else {
              throw new HTML_QuickForm2_InvalidArgumentException(
                  'addRule() expects either a rule type or ' .
                  'a HTML_QuickForm2_Rule instance'
              );
          }
  
          $this->rules[] = array($rule, $runAt);
          return $rule;
      }
code: public function addRule($rule, $messageOrRunAt = '', $options = null,
                              $runAt = HTML_QuickForm2_Rule::RUNAT_SERVER)
      {
          if ($rule instanceof HTML_QuickForm2_Rule) {
              $rule->setOwner($this);
              $runAt = '' == $messageOrRunAt? HTML_QuickForm2_Rule::RUNAT_SERVER: $messageOrRunAt;
          } elseif (is_string($rule)) {
              $rule = HTML_QuickForm2_Factory::createRule($rule, $this, $messageOrRunAt, $options);
          } else {
              throw new HTML_QuickForm2_InvalidArgumentException(
                  'addRule() expects either a rule type or ' .
                  'a HTML_QuickForm2_Rule instance'
              );
          }
  
          $this->rules[] = array($rule, $runAt);
          return $rule;
      }
code_tokens: public function addRule ( $ rule , $ messageOrRunAt = '' , $ options = null , $ runAt = HTML_QuickForm2_Rule :: RUNAT_SERVER ) { if ( $ rule instanceof HTML_QuickForm2_Rule ) { $ rule -> setOwner ( $ this ) ; $ runAt = '' == $ messageOrRunAt ? HTML_QuickForm2_Rule :: RUNAT_SERVER : $ messageOrRunAt ; } elseif ( is_string ( $ rule ) ) { $ rule = HTML_QuickForm2_Factory :: createRule ( $ rule , $ this , $ messageOrRunAt , $ options ) ; } else { throw new HTML_QuickForm2_InvalidArgumentException ( 'addRule() expects either a rule type or ' . 'a HTML_QuickForm2_Rule instance' ) ; } $ this -> rules [ ] = array ( $ rule , $ runAt ) ; return $ rule ; }
docstring: Adds a validation rule
  
  @param    HTML_QuickForm2_Rule|string     Validation rule or rule type
  @param    string|int                      If first parameter is rule type, then
  message to display if validation fails, otherwise constant showing
  whether to perfom validation client-side and/or server-side
  @param    mixed                           Additional data for the rule
  @param    int                             Whether to perfom validation server-side
  and/or client side. Combination of HTML_QuickForm2_Rule::RUNAT_* constants
  @return   HTML_QuickForm2_Rule            The added rule
  @throws   HTML_QuickForm2_InvalidArgumentException    if $rule is of a
  wrong type or rule name isn't registered with Factory
  @throws   HTML_QuickForm2_NotFoundException   if class for a given rule
  name cannot be found
  @todo     Need some means to mark the Rules for running client-side
docstring_tokens: Adds a validation rule