From 25453b3e0f302a912257c50c531eb266c26747bd Mon Sep 17 00:00:00 2001 From: Ciro Vargas Date: Mon, 10 Jul 2017 18:10:32 -0300 Subject: [PATCH] Exceptions, response mapping objects --- src/Response/Address.php | 0 src/Response/Distance.php | 0 src/Response/Duration.php | 0 src/Response/Element.php | 0 src/Response/GoogleDistanceMatrixResponse.php | 123 ++++++++++++++++++ src/Response/Row.php | 32 +++++ 6 files changed, 155 insertions(+) mode change 100644 => 100755 src/Response/Address.php mode change 100644 => 100755 src/Response/Distance.php mode change 100644 => 100755 src/Response/Duration.php mode change 100644 => 100755 src/Response/Element.php create mode 100755 src/Response/GoogleDistanceMatrixResponse.php create mode 100755 src/Response/Row.php diff --git a/src/Response/Address.php b/src/Response/Address.php old mode 100644 new mode 100755 diff --git a/src/Response/Distance.php b/src/Response/Distance.php old mode 100644 new mode 100755 diff --git a/src/Response/Duration.php b/src/Response/Duration.php old mode 100644 new mode 100755 diff --git a/src/Response/Element.php b/src/Response/Element.php old mode 100644 new mode 100755 diff --git a/src/Response/GoogleDistanceMatrixResponse.php b/src/Response/GoogleDistanceMatrixResponse.php new file mode 100755 index 0000000..f80df92 --- /dev/null +++ b/src/Response/GoogleDistanceMatrixResponse.php @@ -0,0 +1,123 @@ +responseObject = $responseObject; + $this->originAddresses = array(); + $this->destinationAddresses = array(); + $this->rows = array(); + $this->construct(); + } + + private function addOriginAddress(Address $originAddress) + { + $this->originAddresses[] = $originAddress; + } + + private function addDestinationAddress(Address $destinationAddress) + { + $this->destinationAddresses[] = $destinationAddress; + } + + private function addRow(Row $row) + { + $this->rows[] = $row; + } + + /** + * @return mixed + */ + public function getStatus() + { + return $this->status; + } + + /** + * @return stdClass + */ + public function getResponseObject() + { + return $this->responseObject; + } + + /** + * @return array + */ + public function getOriginAddresses() + { + return $this->originAddresses; + } + + /** + * @return array + */ + public function getDestinationAddresses() + { + return $this->destinationAddresses; + } + + /** + * @return array + */ + public function getRows() + { + return $this->rows; + } + + + private function construct() + { + $this->status = $this->responseObject->status; + + foreach ($this->responseObject->origin_addresses as $originAddress){ + $this->addOriginAddress(new Address($originAddress)); + } + + foreach ($this->responseObject->destination_addresses as $destinationAddress){ + $this->addDestinationAddress(new Address($destinationAddress)); + } + + foreach ($this->responseObject->rows as $row){ + + $elements = array(); + foreach($row->elements as $element){ + $duration = new Duration($element->duration->text,$element->duration->value); + $distance = new Distance($element->distance->text,$element->distance->value); + $elements[] = new Element($element->status,$duration,$distance); + } + $this->addRow(new Row($elements)); + } + + } +} \ No newline at end of file diff --git a/src/Response/Row.php b/src/Response/Row.php new file mode 100755 index 0000000..01a717b --- /dev/null +++ b/src/Response/Row.php @@ -0,0 +1,32 @@ +elements = $elements; + } + + /** + * @return array + */ + public function getElements() + { + return $this->elements; + } + +} \ No newline at end of file