/**
  * Generates host order particiapnt's invites
  */
 public function generate()
 {
     if (is_null($this->participantsEmailsArray) || !is_array($this->participantsEmailsArray)) {
         throw new \Exception("Participants array must be set in order to generate invite list");
     } else {
         if (is_null($this->hostOrder)) {
             throw new \Exception("Host_order must be set in order to generate invite list");
         } else {
             if (empty($this->participantsEmailsArray)) {
                 throw new \Exception("Participants array can't be an empty array");
             } else {
                 if (is_array($this->participantsEmailsArray)) {
                     // Removing duplicate Emails
                     $this->participantsEmailsArray = array_unique($this->participantsEmailsArray);
                 }
             }
         }
     }
     $validEmails = array();
     foreach ($this->participantsEmailsArray as $email) {
         if (!filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
             $validEmails[] = $email;
         }
     }
     foreach ($validEmails as $email) {
         $inviteToken = bin2hex(openssl_random_pseudo_bytes(32));
         $orderParticipant = new Order_participants();
         $orderParticipant->setHostOrderId($this->hostOrder);
         $orderParticipant->setUsersEmail($email);
         $orderParticipant->setInviteToken($inviteToken);
         $this->hostOrderInvites[] = $orderParticipant;
     }
 }
 public function load(ObjectManager $manager)
 {
     for ($i = 1; $i <= 5; $i++) {
         $orderParticipants = new Order_participants();
         $orderParticipants->setHostOrderId($this->getReference('hostOrder1'));
         $orderParticipants->setUsersEmail("user{$i}@mailinator.com");
         $orderParticipants->setDeleted(0);
         $orderParticipants->setConfirmed(1);
         $orderParticipants->setInviteToken("inviteToken{$i}");
         $manager->persist($orderParticipants);
         $manager->flush();
     }
 }