/** * Returns the exception's "errors" property/attribute * * @param boolean $as_array Whether to return the errors as an array or not * @access public * @return array */ public function getErrors($as_array = false) { if ($as_array) { if (!is_null($this->errors)) { $errors = $this->errors->get_raw_errors(); } else { $errors = array(); } } else { $errors = $this->errors; } return $errors; }
/** * Validates the model. * * @return boolean True if passed validators otherwise false */ private function _validate() { $validator = new Validations($this); $validation_on = 'validation_on_' . ($this->is_new_record() ? 'create' : 'update'); foreach (array('before_validation', "before_{$validation_on}") as $callback) { if (!$this->invoke_callback($callback, false)) { return false; } } $this->errors = $validator->validate(); foreach (array('after_validation', "after_{$validation_on}") as $callback) { $this->invoke_callback($callback, false); } if (!$this->errors->is_empty()) { return false; } return true; }
/** * Validates the model. * * @return boolean True if passed validators otherwise false */ private function validateModel() { /** test norequire require_once 'Validations.php'; */ $validator = new Validations($this); $validation_on = 'validation_on_' . ($this->isNewRecord() ? 'create' : 'update'); foreach (['before_validation', "before_{$validation_on}"] as $callback) { if (!$this->invokeCallback($callback, false)) { return false; } } /* need to store reference before validating so that custom validators * have access to add errors */ $this->errors = $validator->getRecord(); $validator->validate(); foreach (['after_validation', "after_{$validation_on}"] as $callback) { $this->invokeCallback($callback, false); } if (!$this->errors->isEmpty()) { return false; } return true; }