public function beforeValidate(Model $model, $options = array()) {
        if (empty($this->settings[$model->alias])) {
            return true;
        }

        foreach ($this->settings[$model->alias] as $field => $rules) {
            $validations = array();

            foreach ($rules as $rule => $setting) {
                $set = $this->_defaults[$rule];

                // Parse out values
                if (!is_array($setting) || !isset($setting['value'])) {
                    $setting = array('value' => $setting);
                }

                switch ($rule) {
                    case 'required':
                        $arg = (bool) $setting['value'];
                    break;
                    case 'type':
                    case 'mimeType':
                    case 'extension':
                        $arg = (array) $setting['value'];
                    break;
                    default:
                        $arg = (int) $setting['value'];
                    break;
                }

                if (!isset($setting['rule'])) {
                    $setting['rule'] = array($rule, $arg);
                }

                if (isset($setting['error'])) {
                    $setting['message'] = $setting['error'];
                    unset($setting['error']);
                }

                unset($setting['value']);

                // Merge settings
                $set = array_merge($set, $setting);

                // Apply validations
                if (is_array($arg)) {
                    $arg = implode(', ', $arg);
                }

                $set['message'] = __d('uploader', $set['message'], $arg);

                $validations[$rule] = $set;
            }

            if ($validations) {
                if (!empty($model->validate[$field])) {
                    $currentRules = $model->validate[$field];

                    // Fix single rule validate
                    if (isset($currentRules['rule'])) {
                        $currentRules = array(
                            $currentRules['rule'] => $currentRules
                        );
                    }

                    $validations = $currentRules + $validations;
                }

                // Remove notEmpty for uploads
                if (isset($model->data[$model->alias][$field]['tmp_name']) && isset($validations['notEmpty'])) {
                    unset($validations['notEmpty']);
                }

                $this->_validations[$field] = $validations;
                $model->validate[$field] = $validations;
            }
        }

        return true;
    }
public function beforeValidate(Model $model, $options = array()) {
        if (empty($this->settings[$model->alias])) {
            return true;
        }

        foreach ($this->settings[$model->alias] as $field => $rules) {
            $validations = array();

            foreach ($rules as $rule => $setting) {
                $set = $this->_defaults[$rule];

                // Parse out values
                if (!is_array($setting) || !isset($setting['value'])) {
                    $setting = array('value' => $setting);
                }

                switch ($rule) {
                    case 'required':
                        $arg = (bool) $setting['value'];
                    break;
                    case 'type':
                    case 'mimeType':
                    case 'extension':
                        $arg = (array) $setting['value'];
                    break;
                    default:
                        $arg = (int) $setting['value'];
                    break;
                }

                if (!isset($setting['rule'])) {
                    $setting['rule'] = array($rule, $arg);
                }

                if (isset($setting['error'])) {
                    $setting['message'] = $setting['error'];
                    unset($setting['error']);
                }

                unset($setting['value']);

                // Merge settings
                $set = array_merge($set, $setting);

                // Apply validations
                if (is_array($arg)) {
                    $arg = implode(', ', $arg);
                }

                $set['message'] = __d('uploader', $set['message'], $arg);

                $validations[$rule] = $set;
            }

            if ($validations) {
                if (!empty($model->validate[$field])) {
                    $currentRules = $model->validate[$field];

                    // Fix single rule validate
                    if (isset($currentRules['rule'])) {
                        $currentRules = array(
                            $currentRules['rule'] => $currentRules
                        );
                    }

                    $validations = $currentRules + $validations;
                }

                // Remove notEmpty for uploads
                if (isset($model->data[$model->alias][$field]['tmp_name']) && isset($validations['notEmpty'])) {
                    unset($validations['notEmpty']);
                }

                $this->_validations[$field] = $validations;
                $model->validate[$field] = $validations;
            }
        }

        return true;
    }
public function beforeValidate ( Model $ model , $ options = array ( ) ) { if ( empty ( $ this -> settings [ $ model -> alias ] ) ) { return true ; } foreach ( $ this -> settings [ $ model -> alias ] as $ field => $ rules ) { $ validations = array ( ) ; foreach ( $ rules as $ rule => $ setting ) { $ set = $ this -> _defaults [ $ rule ] ; // Parse out values if ( ! is_array ( $ setting ) || ! isset ( $ setting [ 'value' ] ) ) { $ setting = array ( 'value' => $ setting ) ; } switch ( $ rule ) { case 'required' : $ arg = ( bool ) $ setting [ 'value' ] ; break ; case 'type' : case 'mimeType' : case 'extension' : $ arg = ( array ) $ setting [ 'value' ] ; break ; default : $ arg = ( int ) $ setting [ 'value' ] ; break ; } if ( ! isset ( $ setting [ 'rule' ] ) ) { $ setting [ 'rule' ] = array ( $ rule , $ arg ) ; } if ( isset ( $ setting [ 'error' ] ) ) { $ setting [ 'message' ] = $ setting [ 'error' ] ; unset ( $ setting [ 'error' ] ) ; } unset ( $ setting [ 'value' ] ) ; // Merge settings $ set = array_merge ( $ set , $ setting ) ; // Apply validations if ( is_array ( $ arg ) ) { $ arg = implode ( ', ' , $ arg ) ; } $ set [ 'message' ] = __d ( 'uploader' , $ set [ 'message' ] , $ arg ) ; $ validations [ $ rule ] = $ set ; } if ( $ validations ) { if ( ! empty ( $ model -> validate [ $ field ] ) ) { $ currentRules = $ model -> validate [ $ field ] ; // Fix single rule validate if ( isset ( $ currentRules [ 'rule' ] ) ) { $ currentRules = array ( $ currentRules [ 'rule' ] => $ currentRules ) ; } $ validations = $ currentRules + $ validations ; } // Remove notEmpty for uploads if ( isset ( $ model -> data [ $ model -> alias ] [ $ field ] [ 'tmp_name' ] ) && isset ( $ validations [ 'notEmpty' ] ) ) { unset ( $ validations [ 'notEmpty' ] ) ; } $ this -> _validations [ $ field ] = $ validations ; $ model -> validate [ $ field ] = $ validations ; } } return true ; }
Build the validation rules and validate.

@param Model $model
@param array $options
@return bool
Build the validation rules and validate .