/** * Merges an Jelly_Validation_Exception object into the current exception * Useful when you want to combine errors into one array * * @param Jelly_Validation_Exception $object The exception to merge * @param mixed $has_many The array key to use if this exception can be merged multiple times * @return Jelly_Validation_Exception */ public function merge(Jelly_Validation_Exception $object, $has_many = FALSE) { $alias = $object->alias(); // We will need this when generating errors $this->_objects[$alias]['_has_many'] = $has_many !== FALSE; if ($has_many === TRUE) { // This is most likely a has_many relationship $this->_objects[$alias][] = $object->objects(); } elseif ($has_many) { // This is most likely a has_many relationship $this->_objects[$alias][$has_many] = $object->objects(); } else { $this->_objects[$alias] = $object->objects(); } return $this; }
/** * Validates the current model's data * * @throws Jelly_Validation_Exception * @param Validation|null $extra_validation * @return Jelly_Core_Model */ public function check($extra_validation = NULL) { $key = $this->_original[$this->_meta->primary_key()]; // Determine if any external validation failed $extra_errors = ($extra_validation instanceof Validation and !$extra_validation->check()); // For loaded models, we're only checking what's changed, otherwise we check it all $data = $key ? $this->_changed : $this->_changed + $this->_original; // Always build a new validation object $this->_validation($data, (bool) $key); // Run validation if (!$this->_valid) { $array = $this->_validation; $this->_meta->events()->trigger('model.before_validate', $this, array($this->_validation)); if (($this->_valid = $array->check()) === FALSE or $extra_errors) { $exception = new Jelly_Validation_Exception($this->_meta->errors_filename(), $array); if ($extra_errors) { // Merge any possible errors from the external object $exception->add_object('_external', $extra_validation); } throw $exception; } $this->_meta->events()->trigger('model.after_validate', $this, array($this->_validation)); } else { $this->_valid = TRUE; } return $this; }