public function addRequestAction($request) { $this->elevatorRepository = new ElevatorRepository("data/state"); $this->elevator = $this->elevatorRepository->getElevator(); $this->elevator->addRequest(new ElevatorRequest($request->from, $request->to)); $this->elevatorRepository->saveElevator($this->elevator); return json_encode(["success" => "Request successfully received."]); }
/** @retrun QueueService */ private function route(ElevatorRequest $request) { // Insert current elevator floor as a starting point array_unshift($this->queue, $this->elevator->getCurrentFloor()); // Find the best place and insert source request (where to pick up) $position = $this->insertRequest(0, $request->getSourceFloor()); // Find the best place after picking-up to land $this->insertRequest($position, $request->getTargetFloor()); // Remove current elevator floor after successful routing array_shift($this->queue); return $this; }
public function handleSignal(Elevator $elevator, $signal) { if ($signal === Elevator::STATE_DOOR_CLOSE) { if ($elevator->isDoorOpen()) { $state = Elevator::STATE_STANDING; } else { $state = NULL; } } else { $state = $this->delegate($elevator, $signal); } return $state; }
public function handleSignal(Elevator $elevator, $signal) { if ($signal === Elevator::STATE_DOOR_OPEN) { if ($elevator->isDoorOpen() || $elevator->isStanding()) { $state = Elevator::STATE_DOOR_OPEN; } else { throw new Exception("Elevator is on it's way. Can not open door right now, sorry!"); } } else { $state = $this->delegate($elevator, $signal); } return $state; }
public function handleSignal(Elevator $elevator, $signal) { if ($signal === Elevator::STATE_ALARM) { if ($elevator->isDoorOpen()) { throw new Exception("Elevator has door open, why should you push an alarm button?"); } else { $state = Elevator::STATE_ALARM; } } else { $state = $this->delegate($elevator, $signal); } return $state; }