Ejemplo n.º 1
0
 /**
  * Processes the email and adds it to the user.
  *
  * @param UserInterface $user
  * @param string        $email
  * @param null|array    $contact
  *
  * @throws EmailNotUniqueException
  */
 private function processEmail(UserInterface $user, $email, $contact = null)
 {
     if ($contact) {
         // if no email passed try to use the contact's first email
         if ($email === null && array_key_exists('emails', $contact) && count($contact['emails']) > 0 && $this->isEmailUnique($contact['emails'][0]['email'])) {
             $email = $contact['emails'][0]['email'];
         }
         if ($email !== null) {
             if (!$this->isEmailUnique($email)) {
                 throw new EmailNotUniqueException($email);
             }
             $user->setEmail($email);
         }
     } else {
         if ($email !== null) {
             if ($email !== $user->getEmail() && !$this->isEmailUnique($email)) {
                 throw new EmailNotUniqueException($email);
             }
             $user->setEmail($email);
         } else {
             $user->setEmail(null);
         }
     }
 }