/**
  * Sets the directions response status.
  *
  * @param string $status The directions response status.
  *
  * @throws \Ivory\GoogleMap\Exception\DirectionsException If the status is not valid.
  */
 public function setStatus($status)
 {
     if (!in_array($status, DirectionsStatus::getDirectionsStatus())) {
         throw DirectionsException::invalidDirectionsResponseStatus();
     }
     $this->status = $status;
 }
示例#2
0
 /**
  * Routes the given request.
  *
  * Available prototypes:
  * - function route(string $origin, string $destination)
  * - function route(Ivory\GoogleMap\Services\Directions\DirectionsRequest $request)
  *
  * @throws \Ivory\GoogleMap\Exception\DirectionsException If the request is not valid (prototypes).
  */
 public function route()
 {
     $args = func_get_args();
     if (isset($args[0]) && $args[0] instanceof DirectionsRequest) {
         $directionsRequest = $args[0];
     } elseif (isset($args[0]) && is_string($args[0]) && (isset($args[1]) && is_string($args[1]))) {
         $directionsRequest = new DirectionsRequest();
         $directionsRequest->setOrigin($args[0]);
         $directionsRequest->setDestination($args[1]);
     } else {
         throw DirectionsException::invalidDirectionsRequestParameters();
     }
     if (!$directionsRequest->isValid()) {
         throw DirectionsException::invalidDirectionsRequest();
     }
     $response = $this->send($this->generateUrl($directionsRequest));
     $directionsResponse = $this->buildDirectionsResponse($this->parse($response->getBody()));
     return $directionsResponse;
 }
 /**
  * Sets the directions request sensor.
  *
  * @param boolean $sensor TRUE if the directions request has a sensor else FALSE.
  *
  * @throws \Ivory\GoogleMap\Exception\DirectionsException If the sensor flag is not valid.
  */
 public function setSensor($sensor)
 {
     if (!is_bool($sensor)) {
         throw DirectionsException::invalidDirectionsRequestSensor();
     }
     $this->sensor = $sensor;
 }
 /**
  * Sets the step travel mode.
  *
  * @param string $travelMode The step travel mode.
  *
  * @throws \Ivory\GoogleMap\Exception\DirectionsException If the travel mode is not valid.
  */
 public function setTravelMode($travelMode)
 {
     if (!in_array($travelMode, TravelMode::getTravelModes())) {
         throw DirectionsException::invalidDirectionsStepTravelMode();
     }
     $this->travelMode = $travelMode;
 }
 /**
  * Adds a waypoint order to the route.
  *
  * @param integer $waypointOrder The waypoint to add.
  *
  * @throws \Ivory\GoogleMap\Exception\DirectionsException If the waypoint order is not valid.
  */
 public function addWaypointOrder($waypointOrder)
 {
     if (!is_int($waypointOrder)) {
         throw DirectionsException::invalidDirectionsRouteWaypointOrder();
     }
     $this->waypointOrder[] = $waypointOrder;
 }
 /**
  * Sets the directions waypoint stopover flag.
  *
  * @param boolean $stopover The directions waypoint stopover flag.
  */
 public function setStopover($stopover = null)
 {
     if (!is_bool($stopover) && $stopover !== null) {
         throw DirectionsException::invalidDirectionsWaypointStopover();
     }
     $this->stopover = $stopover;
 }
 /**
  * Sets the leg start address.
  *
  * @param string $startAddress The leg start address.
  *
  * @throws \Ivory\GoogleMap\Exception\DirectionsException If the start address is not valid.
  */
 public function setStartAddress($startAddress)
 {
     if (!is_string($startAddress)) {
         throw DirectionsException::invalidDirectionsLegStartAddress();
     }
     $this->startAddress = $startAddress;
 }