mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Merge pull request #1000 from dogmatic69/validation-simplify
Validation simplify Simplify internals in Model/Validation
This commit is contained in:
commit
38c592928d
1 changed files with 15 additions and 26 deletions
|
@ -130,11 +130,10 @@ class ModelValidator implements ArrayAccess, IteratorAggregate, Countable {
|
|||
$options = array_merge(array('atomic' => true, 'deep' => false), $options);
|
||||
$model->validationErrors = $validationErrors = $return = array();
|
||||
$model->create(null);
|
||||
$return[$model->alias] = true;
|
||||
if (!($model->set($data) && $model->validates($options))) {
|
||||
$validationErrors[$model->alias] = $model->validationErrors;
|
||||
$return[$model->alias] = false;
|
||||
} else {
|
||||
$return[$model->alias] = true;
|
||||
}
|
||||
$data = $model->data;
|
||||
if (!empty($options['deep']) && isset($data[$model->alias])) {
|
||||
|
@ -156,11 +155,7 @@ class ModelValidator implements ArrayAccess, IteratorAggregate, Countable {
|
|||
$data[$association] = $model->{$association}->data[$model->{$association}->alias];
|
||||
}
|
||||
if (is_array($validates)) {
|
||||
if (in_array(false, Hash::flatten($validates), true)) {
|
||||
$validates = false;
|
||||
} else {
|
||||
$validates = true;
|
||||
}
|
||||
$validates = !in_array(false, Hash::flatten($validates), true);
|
||||
}
|
||||
$return[$association] = $validates;
|
||||
} elseif ($associations[$association] === 'hasMany') {
|
||||
|
@ -231,10 +226,7 @@ class ModelValidator implements ArrayAccess, IteratorAggregate, Countable {
|
|||
if (!$options['atomic']) {
|
||||
return $return;
|
||||
}
|
||||
if (empty($model->validationErrors)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return empty($model->validationErrors);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -322,9 +314,10 @@ class ModelValidator implements ArrayAccess, IteratorAggregate, Countable {
|
|||
*/
|
||||
public function getField($name = null) {
|
||||
$this->_parseRules();
|
||||
if ($name !== null && !empty($this->_fields[$name])) {
|
||||
return $this->_fields[$name];
|
||||
} elseif ($name !== null) {
|
||||
if ($name !== null) {
|
||||
if (!empty($this->_fields[$name])) {
|
||||
return $this->_fields[$name];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return $this->_fields;
|
||||
|
@ -401,18 +394,17 @@ class ModelValidator implements ArrayAccess, IteratorAggregate, Countable {
|
|||
unset($fieldList);
|
||||
|
||||
$validateList = array();
|
||||
if (!empty($whitelist)) {
|
||||
$this->validationErrors = array();
|
||||
|
||||
foreach ((array)$whitelist as $f) {
|
||||
if (!empty($this->_fields[$f])) {
|
||||
$validateList[$f] = $this->_fields[$f];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (empty($whitelist)) {
|
||||
return $this->_fields;
|
||||
}
|
||||
|
||||
$this->validationErrors = array();
|
||||
foreach ((array)$whitelist as $f) {
|
||||
if (!empty($this->_fields[$f])) {
|
||||
$validateList[$f] = $this->_fields[$f];
|
||||
}
|
||||
}
|
||||
|
||||
return $validateList;
|
||||
}
|
||||
|
||||
|
@ -443,9 +435,6 @@ class ModelValidator implements ArrayAccess, IteratorAggregate, Countable {
|
|||
$newData[] = $row[$join];
|
||||
}
|
||||
}
|
||||
if (empty($newData)) {
|
||||
continue;
|
||||
}
|
||||
foreach ($newData as $data) {
|
||||
$data[$model->hasAndBelongsToMany[$assoc]['foreignKey']] = $model->id;
|
||||
$model->{$join}->create($data);
|
||||
|
|
Loading…
Add table
Reference in a new issue