/** * 检查当前对象的数据是否合法 * * @param Validation $extraValidation Validation object * @throws ValidationException * @return Model */ public function check(Validation $extraValidation = null) { // Determine if any external validation failed $extraErrors = $extraValidation && !$extraValidation->check(); // Always build a new validation object $this->_validation(); $array = $this->_validation; if (false === ($this->_valid = $array->check()) || $extraErrors) { $exception = new ValidationException($this->errorFileName(), $array); if ($extraErrors) { // 合并附加的验证规则 $exception->addObject('_external', $extraValidation); } throw $exception; } return $this; }
/** * Merges an ValidationException object into the current exception * Useful when you want to combine errors into one array * * @param ValidationException $object The exception to merge * @param mixed $hasMany The array key to use if this exception can be merged multiple times * @return ValidationException */ public function merge(ValidationException $object, $hasMany = false) { $alias = $object->alias(); // We will need this when generating errors $this->_objects[$alias]['_hasMany'] = false !== $hasMany; if (true === $hasMany) { // This is most likely a hasMany relationship $this->_objects[$alias][] = $object->objects(); } elseif ($hasMany) { // This is most likely a hasMany relationship $this->_objects[$alias][$hasMany] = $object->objects(); } else { $this->_objects[$alias] = $object->objects(); } return $this; }