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