コード例 #1
0
 /** @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;
 }
コード例 #2
0
 public function getInfoAction()
 {
     $this->elevatorRepository = new ElevatorRepository("data/state");
     $this->elevator = $this->elevatorRepository->getElevator();
     try {
         $this->elevator->process();
         $this->elevatorRepository->saveElevator($this->elevator);
     } catch (Exception $e) {
     }
     $info = new \Lender411\ElevatorInfo($this->elevator);
     return json_encode(["description" => $info->getState(), "currentFloor" => $this->elevator->getCurrentFloor(), "targetFloor" => $this->elevator->getTargetFloor(), "state" => $this->elevator->getState()]);
 }