Esempio n. 1
0
 /**
  * Sets email for a user.
  *
  * @param User   $user
  * @param string $email
  *
  * @throws InvalidArgumentException if email is not valid or already exists.
  * @throws RuntimeException         if email already exists.
  */
 private function doSetEmail(User $user, $email)
 {
     if (null !== $email && false === (bool) \Swift_Validate::email($email)) {
         throw new InvalidArgumentException(sprintf('Email %s is not legal.', $email));
     }
     if (null !== $this->repository->findByEmail($email)) {
         throw new RuntimeException(sprintf('User with email %s already exists.', $email));
     }
     $user->setEmail($email);
 }