/**
  * @return bool
  */
 private function inTime()
 {
     $currentDate = new \DateTime();
     $startDate = new \DateTime();
     $orderStartHourExploded = explode(':', $this->restaurant->getStartHour());
     $startDate->setTime(intval($orderStartHourExploded[0]), intval($orderStartHourExploded[1]), 0);
     $endDate = new \DateTime();
     $orderEndHourExploded = explode(':', $this->restaurant->getEndHour());
     $endDate->setTime(intval($orderEndHourExploded[0]), intval($orderEndHourExploded[1]), 0);
     return $currentDate >= $startDate && $currentDate <= $endDate;
 }
示例#2
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;
 }