示例#1
0
 /**
  * @param Restaurant $restaurant
  * @return bool
  */
 public function validateRestaurant(Restaurant $restaurant)
 {
     if (null === $restaurant->getCommand()) {
         throw new \InvalidArgumentException('The command can\'t be null.');
     }
     if (!preg_match('/^\\/([a-z]+)$/', $restaurant->getCommand())) {
         throw new \InvalidArgumentException('Invalid command name format: /bagel, only letters are allowed and must start by /');
     }
     if (mb_strlen($restaurant->getName()) > 255) {
         throw new \InvalidArgumentException('The restaurant name must be less than 255 characters.');
     }
     if (null === $restaurant->getExample()) {
         throw new \InvalidArgumentException('The order example can\'t be null.');
     }
     if (null === $restaurant->getPhoneNumber()) {
         throw new \InvalidArgumentException('The restaurant phone number can\'t be null.');
     }
     if (!preg_match('/^[0-9]{10}$/', $restaurant->getPhoneNumber())) {
         throw new \InvalidArgumentException('Invalid restaurant phone number format: Only numbers are allowed.');
     }
     if (!preg_match('/^[0-9]{2}:[0-9]{2}$/', $restaurant->getStartHour())) {
         throw new \InvalidArgumentException('Invalid start hour format.');
     }
     if (!preg_match('/^[0-9]{2}:[0-9]{2}$/', $restaurant->getEndHour())) {
         throw new \InvalidArgumentException('Invalid end hour format.');
     }
     if (null === $restaurant->getToken()) {
         throw new \InvalidArgumentException('The token can\'t be null.');
     }
     if ($restaurant->sendOrderByEmail() && null === $restaurant->getEndHour()) {
         throw new \InvalidArgumentException('You must set the restaurant email if you want to send order by email');
     }
     if ($restaurant->sendOrderByEmail() && null === $restaurant->getSenderEmail()) {
         throw new \InvalidArgumentException('You must set the sender email if you want to send order by email');
     }
     return true;
 }
 /**
  * @param String $hour
  * @param String $phoneNumber
  * @param String $name
  * @param Order[] $orders
  * @return int
  */
 private function sendEmail($hour, $phoneNumber, $name, $orders)
 {
     $message = \Swift_Message::newInstance()->setSubject($this->translator->trans('email.subject'))->setFrom($this->restaurant->getSenderEmail())->setTo($this->restaurant->getEmail())->setBody($this->twig->render('Emails/order.html.twig', ['name' => $name, 'hour' => $hour, 'phoneNumber' => $phoneNumber, 'orders' => $orders]), 'text/html');
     return $this->mailer->send($message);
 }