mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Optimized whitelist jugglery.
This commit is contained in:
parent
02acf636a7
commit
f9c1c2aa7f
1 changed files with 8 additions and 17 deletions
|
@ -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];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue