Example #1
0
 public function insert($key, Errors $errors)
 {
     if ($errors->any()) {
         if (empty($key)) {
             $this->combine($errors);
         } else {
             $this[$key] = $errors;
         }
     }
 }
Example #2
0
 public function validateUniqueEmail(User $user, $email, Errors $errors = NULL)
 {
     if (empty($errors)) {
         $errors = new \Northern\Core\Common\Exception\Validation\Errors();
     }
     if (!empty($email)) {
         if ($email !== $user->email) {
             $otherUser = $this->userRepository->getUserByEmail($email);
             if (!empty($otherUser)) {
                 $errors->add('email', "There already is another user with this email address.");
             }
         }
     }
     return $errors;
 }
Example #3
0
 public function validate(array $values, Errors $errors = NULL)
 {
     if (empty($errors)) {
         $errors = new Errors();
     }
     $constraints = $this->getConstraints();
     foreach ($values as $field => $value) {
         if (!isset($constraints[$field])) {
             continue;
         }
         $rules = $constraints[$field];
         foreach ($rules as $rule) {
             if (!$rule['validator']->isValid($value)) {
                 $errors->add($field, $rule['message']);
                 break;
             }
         }
     }
     return $errors;
 }