src/Valitron/Validator.php
/**
     * Convenience method to add a single validation rule
     */
Convenience method to add a single validation rule
Convenience method to add a single validation rule
public function rule($rule, $fields)
    {
        if(!isset(static::$_rules[$rule])) {
            $ruleMethod = 'validate' . ucfirst($rule);
            if(!method_exists($this, $ruleMethod)) {
                throw new \InvalidArgumentException("Rule '" . $rule . "' has not been registered with " . __CLASS__ . "::addRule().");
            }
        }
        $message = isset(static::$_ruleMessages[$rule]) ? static::$_ruleMessages[$rule] : self::ERROR_DEFAULT;
        $params = array_slice(func_get_args(), 2);
        $this->_validations[] = array(
            'rule' => $rule,
            'fields' => (array) $fields,
            'params' => (array) $params,
            'message' => '{field} ' . $message
        );
        return $this;
    }
public function rule ( $ rule , $ fields ) { if ( ! isset ( static :: $ _rules [ $ rule ] ) ) { $ ruleMethod = 'validate' . ucfirst ( $ rule ) ; if ( ! method_exists ( $ this , $ ruleMethod ) ) { throw new \ InvalidArgumentException ( " Rule ' " . $ rule . " ' has not been registered with  " . __CLASS__ . " ::addRule(). " ) ; } } $ message = isset ( static :: $ _ruleMessages [ $ rule ] ) ? static :: $ _ruleMessages [ $ rule ] : self :: ERROR_DEFAULT ; $ params = array_slice ( func_get_args ( ) , 2 ) ; $ this -> _validations [ ] = array ( 'rule' => $ rule , 'fields' => ( array ) $ fields , 'params' => ( array ) $ params , 'message' => '{field} ' . $ message ) ; return $ this ; }
Convenience method to add a single validation rule
Convenience method to add a single validation rule
// Ensure rule has an accompanying message // Get any other arguments passed to function