Example #1
0
 /**
  * @param int $hour
  */
 public function __construct($hour)
 {
     if (DayState::isDay($hour)) {
         $this->state = DayState::getInstance();
     } else {
         $this->state = NightState::getInstance();
     }
 }
Example #2
0
 public function doClock(Context $context, $time)
 {
     if (strtotime($time) >= strtotime(service_start_time) && strtotime($time) < strtotime(lunch_start_time)) {
         $context->changeState(DayState::getInstance());
     }
     if (strtotime($time) >= strtotime(lunch_start_time) && strtotime($time) < strtotime(lunch_end_time)) {
         $context->changeState(LunchState::getInstance());
     }
     if (strtotime($time) >= strtotime(lunch_end_time) && strtotime($time) < strtotime(service_end_time)) {
         $context->changeState(DayState::getInstance());
     }
     if (strtotime($time) >= strtotime(service_end_time)) {
         $context->changeState(NightState::getInstance());
     }
 }
Example #3
0
 public function doClock(Context $context, $time)
 {
     if (strtotime($time) < strtotime(service_start_time) || strtotime(service_end_time) <= strtotime($time)) {
         //MEMO Stateクラス同士はどうしても密結合になってしまう
         $context->changeState(NightState::getInstance());
     }
 }
 /**
  * @param ContextInterface $context
  * @param int              $hour
  */
 public function doClock(ContextInterface $context, $hour)
 {
     if (!self::isDay($hour)) {
         $context->changeState(NightState::getInstance());
     }
 }