public function validate() {
        if (!$this->_data) {
            return false;
        }

        $fields = $this->getFields();
        $messages = $this->getMessages();

        foreach ($this->_data as $field => $value) {
            if (empty($this->_rules[$field])) {
                continue;
            }

            foreach ($this->_rules[$field] as $rule => $params) {
                $options = $params['options'];
                $arguments = $options;
                array_unshift($arguments, $value);

                // Use G11n if it is available
                if (class_exists('Titon\G11n\Utility\Validate')) {
                    $class = 'Titon\G11n\Utility\Validate';
                } else {
                    $class = 'Titon\Utility\Validate';
                }

                if (!call_user_func(array($class, 'hasMethod'), $rule)) {
                    throw new InvalidValidationRuleException(sprintf('Validation rule %s does not exist', $rule));
                }

                // Prepare messages
                $message = $params['message'];

                if (!$message && isset($messages[$rule])) {
                    $message = $messages[$rule];
                }

                if ($message) {
                    $message = String::insert($message, array_map(function($value) {
                        return is_array($value) ? implode(', ', $value) : $value;
                    }, $options + array(
                        'field' => $field,
                        'title' => $fields[$field]
                    )));
                } else {
                    throw new InvalidValidationRuleException(sprintf('Error message for rule %s does not exist', $rule));
                }

                if (!call_user_func_array(array($class, $rule), $arguments)) {
                    $this->addError($field, $message);
                    break;
                }
            }
        }

        return empty($this->_errors);
    }
public function validate() {
        if (!$this->_data) {
            return false;
        }

        $fields = $this->getFields();
        $messages = $this->getMessages();

        foreach ($this->_data as $field => $value) {
            if (empty($this->_rules[$field])) {
                continue;
            }

            foreach ($this->_rules[$field] as $rule => $params) {
                $options = $params['options'];
                $arguments = $options;
                array_unshift($arguments, $value);

                // Use G11n if it is available
                if (class_exists('Titon\G11n\Utility\Validate')) {
                    $class = 'Titon\G11n\Utility\Validate';
                } else {
                    $class = 'Titon\Utility\Validate';
                }

                if (!call_user_func(array($class, 'hasMethod'), $rule)) {
                    throw new InvalidValidationRuleException(sprintf('Validation rule %s does not exist', $rule));
                }

                // Prepare messages
                $message = $params['message'];

                if (!$message && isset($messages[$rule])) {
                    $message = $messages[$rule];
                }

                if ($message) {
                    $message = String::insert($message, array_map(function($value) {
                        return is_array($value) ? implode(', ', $value) : $value;
                    }, $options + array(
                        'field' => $field,
                        'title' => $fields[$field]
                    )));
                } else {
                    throw new InvalidValidationRuleException(sprintf('Error message for rule %s does not exist', $rule));
                }

                if (!call_user_func_array(array($class, $rule), $arguments)) {
                    $this->addError($field, $message);
                    break;
                }
            }
        }

        return empty($this->_errors);
    }
public function validate ( ) { if ( ! $ this -> _data ) { return false ; } $ fields = $ this -> getFields ( ) ; $ messages = $ this -> getMessages ( ) ; foreach ( $ this -> _data as $ field => $ value ) { if ( empty ( $ this -> _rules [ $ field ] ) ) { continue ; } foreach ( $ this -> _rules [ $ field ] as $ rule => $ params ) { $ options = $ params [ 'options' ] ; $ arguments = $ options ; array_unshift ( $ arguments , $ value ) ; // Use G11n if it is available if ( class_exists ( 'Titon\G11n\Utility\Validate' ) ) { $ class = 'Titon\G11n\Utility\Validate' ; } else { $ class = 'Titon\Utility\Validate' ; } if ( ! call_user_func ( array ( $ class , 'hasMethod' ) , $ rule ) ) { throw new InvalidValidationRuleException ( sprintf ( 'Validation rule %s does not exist' , $ rule ) ) ; } // Prepare messages $ message = $ params [ 'message' ] ; if ( ! $ message && isset ( $ messages [ $ rule ] ) ) { $ message = $ messages [ $ rule ] ; } if ( $ message ) { $ message = String :: insert ( $ message , array_map ( function ( $ value ) { return is_array ( $ value ) ? implode ( ', ' , $ value ) : $ value ; } , $ options + array ( 'field' => $ field , 'title' => $ fields [ $ field ] ) ) ) ; } else { throw new InvalidValidationRuleException ( sprintf ( 'Error message for rule %s does not exist' , $ rule ) ) ; } if ( ! call_user_func_array ( array ( $ class , $ rule ) , $ arguments ) ) { $ this -> addError ( $ field , $ message ) ; break ; } } } return empty ( $ this -> _errors ) ; }
Validate the data against the rules schema. Return true if all fields passed validation.

@return bool
@throws \Titon\Utility\Exception\InvalidValidationRuleException
Validate the data against the rules schema . Return true if all fields passed validation .