original_string: public function rule($field, $rules = [])
      {
          $defaults = [
              'message' => null,
              'required' => true,
              'skipEmpty' => false,
              'format' => 'any',
              'not' => false,
              'on' => null
          ];
  
          $rules = $rules ? (array) $rules : [];
  
          foreach ($rules as $name => $options) {
              if (is_numeric($name)) {
                  $name = $options;
                  $options = [];
              }
              if (is_string($options)) {
                  $options = ['message' => $options];
              }
              $options += $defaults;
              $this->_rules[$field][$name] = $options;
          }
      }
code: public function rule($field, $rules = [])
      {
          $defaults = [
              'message' => null,
              'required' => true,
              'skipEmpty' => false,
              'format' => 'any',
              'not' => false,
              'on' => null
          ];
  
          $rules = $rules ? (array) $rules : [];
  
          foreach ($rules as $name => $options) {
              if (is_numeric($name)) {
                  $name = $options;
                  $options = [];
              }
              if (is_string($options)) {
                  $options = ['message' => $options];
              }
              $options += $defaults;
              $this->_rules[$field][$name] = $options;
          }
      }
code_tokens: public function rule ( $ field , $ rules = [ ] ) { $ defaults = [ 'message' => null , 'required' => true , 'skipEmpty' => false , 'format' => 'any' , 'not' => false , 'on' => null ] ; $ rules = $ rules ? ( array ) $ rules : [ ] ; foreach ( $ rules as $ name => $ options ) { if ( is_numeric ( $ name ) ) { $ name = $ options ; $ options = [ ] ; } if ( is_string ( $ options ) ) { $ options = [ 'message' => $ options ] ; } $ options += $ defaults ; $ this -> _rules [ $ field ] [ $ name ] = $ options ; } }
docstring: Sets a rule.
  
  @param mixed  $name    A fieldname.
  @param string $handler A validation handler name.
docstring_tokens: Sets a rule .