/** * 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; }