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;
        }
    }
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;
        }
    }
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 ; } }
Sets a rule.

@param mixed  $name    A fieldname.
@param string $handler A validation handler name.
Sets a rule .