Optimized whitelist jugglery.

This commit is contained in:
ADmad 2013-10-09 00:04:18 +05:30
parent 02acf636a7
commit f9c1c2aa7f

View file

@ -251,7 +251,11 @@ class ModelValidator implements ArrayAccess, IteratorAggregate, Countable {
$fieldList = $model->whitelist;
if (empty($fieldList) && !empty($options['fieldList'])) {
$fieldList = $options['fieldList'];
if (!empty($options['fieldList'][$model->alias]) && is_array($options['fieldList'][$model->alias])) {
$fieldList = $options['fieldList'][$model->alias];
} else {
$fieldList = $options['fieldList'];
}
}
$exists = $model->exists();
@ -380,32 +384,19 @@ class ModelValidator implements ArrayAccess, IteratorAggregate, Countable {
}
/**
* Processes the Model's whitelist or passed fieldList and returns the list of fields
* to be validated
* Processes the passed fieldList and returns the list of fields to be validated
*
* @param array $fieldList list of fields to be used for validation
* @return array List of validation rules to be applied
*/
protected function _validationList($fieldList = array()) {
$model = $this->getModel();
$whitelist = $model->whitelist;
if (!empty($fieldList)) {
if (!empty($fieldList[$model->alias]) && is_array($fieldList[$model->alias])) {
$whitelist = $fieldList[$model->alias];
} else {
$whitelist = $fieldList;
}
}
unset($fieldList);
if (empty($whitelist) || Hash::dimensions($whitelist) > 1) {
if (empty($fieldList) || Hash::dimensions($fieldList) > 1) {
return $this->_fields;
}
$validateList = array();
$this->validationErrors = array();
foreach ((array)$whitelist as $f) {
foreach ((array)$fieldList as $f) {
if (!empty($this->_fields[$f])) {
$validateList[$f] = $this->_fields[$f];
}