Example #1
0
 /**
  * Validate the model data for persistence.
  *
  * @param array $rules Optional rules to add to the validator.
  * @param array $mask An optional mask for patch requests.
  *
  * @return array|bool An array of validation error messages or true.
  */
 public function validate(array $rules = [], array $mask = [])
 {
     $this->_validator = Validator::instance(static::validationRules($rules));
     $all = empty($mask);
     $passed = $this->_validator->check($this->toArray($mask, false), $all);
     return $passed === true ? true : $this->_validator->failures();
 }
Example #2
0
 /**
  * Get a Validator and check an input against a set of Rules.
  *
  * @param array|object $input Input data to validate.
  * @param array        $ruleSet A set of Rules to validate the data against.
  * @param bool         $all Set to false if Rules for missing input fields should be ignored.
  *
  * @return bool Returns true if all Rules pass on the input data; false otherwise.
  */
 protected function validate($input, $ruleSet = [], $all = false)
 {
     $validator = Validator::instance($ruleSet);
     return $validator->check($input, $all);
 }
Example #3
0
 /**
  * Test the Validator::instance() method.
  *
  * @group validate
  */
 public function testInstance()
 {
     $this->assertInstanceOf('Tacit\\Validate\\Validator', Validator::instance());
 }