This class isn't meant to be directly used. Instead you define
validators thru static variables in your {@link Model}. Example:
class Person extends Activerecord\Model {
static $validatesLengthOf = array(
array('name', 'within' => array(30,100),
array('state', 'is' => 2)
);
}
$person = new Person();
$person->name = 'Tito';
$person->state = 'this is not two characters';
if (!$person->is_valid())
print_r($person->errors);
/** * Validates the model. * * @return boolean True if passed validators otherwise false */ private function _validate() { require_once 'Validations.php'; $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; }