@@ -22,205 +22,205 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | class GoogleMapsResponse { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @var Response |
|
| 27 | - */ |
|
| 28 | - protected $response = null; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var array |
|
| 32 | - */ |
|
| 33 | - protected $results = null; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var string |
|
| 37 | - */ |
|
| 38 | - protected $status = null; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var string |
|
| 42 | - */ |
|
| 43 | - protected $error_message = null; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var array |
|
| 47 | - */ |
|
| 48 | - protected $array_response = null; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var int |
|
| 52 | - */ |
|
| 53 | - protected $http_status_code = null; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * GoogleMapsResponse constructor. |
|
| 57 | - * |
|
| 58 | - * @param Response $response |
|
| 59 | - */ |
|
| 60 | - public function __construct(Response $response) { |
|
| 61 | - |
|
| 62 | - $this->setResponse($response); |
|
| 63 | - |
|
| 64 | - $this->parseResponse(); |
|
| 65 | - |
|
| 66 | - $this->checkHttpStatusCode(); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @param Response $response |
|
| 71 | - * |
|
| 72 | - * @return GoogleMapsResponse |
|
| 73 | - */ |
|
| 74 | - public function setResponse(Response $response): GoogleMapsResponse { |
|
| 75 | - |
|
| 76 | - $this->response = $response; |
|
| 77 | - |
|
| 78 | - return $this; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @return GoogleMapsResponse |
|
| 83 | - * |
|
| 84 | - * @throws RequestException |
|
| 85 | - * @throws ResponseException |
|
| 86 | - */ |
|
| 87 | - protected function parseResponse(): GoogleMapsResponse { |
|
| 88 | - |
|
| 89 | - $json_response = $this->response->getBody()->getContents(); |
|
| 90 | - $array_response = $this->toArray($json_response); |
|
| 91 | - |
|
| 92 | - if (is_null($array_response[GoogleMapsResponseFields::RESULTS])) { |
|
| 93 | - throw new ResponseException('Missing "results" in GoogleMapsApi Response'); |
|
| 94 | - } |
|
| 95 | - $this->setResults($array_response[GoogleMapsResponseFields::RESULTS]); |
|
| 96 | - |
|
| 97 | - if (empty($array_response[GoogleMapsResponseFields::STATUS])) { |
|
| 98 | - throw new ResponseException('Missing "status" in GoogleMapsApi Response'); |
|
| 99 | - } |
|
| 100 | - $this->setStatus($array_response[GoogleMapsResponseFields::STATUS]); |
|
| 101 | - |
|
| 102 | - if ($this->getStatus() != GoogleMapsResponseStatusValues::OK) { |
|
| 103 | - $error_message = 'Something went wrong'; |
|
| 104 | - if (!empty($array_response[GoogleMapsResponseFields::ERROR_MESSAGE])) { |
|
| 105 | - $error_message = $array_response[GoogleMapsResponseFields::ERROR_MESSAGE]; |
|
| 106 | - $this->setErrorMessage($error_message); |
|
| 107 | - } |
|
| 108 | - throw new RequestException($error_message); |
|
| 109 | - |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - return $this; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Check HTTP status code (silent/No exceptions!) |
|
| 117 | - * @return int |
|
| 118 | - */ |
|
| 119 | - protected function checkHttpStatusCode(): int { |
|
| 120 | - |
|
| 121 | - $this->http_status_code = $this->response->getStatusCode(); |
|
| 122 | - |
|
| 123 | - return $this->http_status_code; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * @param string $json_response |
|
| 128 | - * |
|
| 129 | - * @return array |
|
| 130 | - */ |
|
| 131 | - public function toArray(string $json_response): array { |
|
| 132 | - |
|
| 133 | - $this->array_response = json_decode($json_response, true); |
|
| 134 | - |
|
| 135 | - return $this->array_response; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * @return array |
|
| 140 | - */ |
|
| 141 | - public function getResults() { |
|
| 142 | - |
|
| 143 | - return $this->results; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * @param array $results |
|
| 148 | - * |
|
| 149 | - * @return $this |
|
| 150 | - */ |
|
| 151 | - public function setResults(array $results) { |
|
| 152 | - |
|
| 153 | - $this->results = $results; |
|
| 25 | + /** |
|
| 26 | + * @var Response |
|
| 27 | + */ |
|
| 28 | + protected $response = null; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var array |
|
| 32 | + */ |
|
| 33 | + protected $results = null; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @var string |
|
| 37 | + */ |
|
| 38 | + protected $status = null; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var string |
|
| 42 | + */ |
|
| 43 | + protected $error_message = null; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var array |
|
| 47 | + */ |
|
| 48 | + protected $array_response = null; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @var int |
|
| 52 | + */ |
|
| 53 | + protected $http_status_code = null; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * GoogleMapsResponse constructor. |
|
| 57 | + * |
|
| 58 | + * @param Response $response |
|
| 59 | + */ |
|
| 60 | + public function __construct(Response $response) { |
|
| 61 | + |
|
| 62 | + $this->setResponse($response); |
|
| 63 | + |
|
| 64 | + $this->parseResponse(); |
|
| 65 | + |
|
| 66 | + $this->checkHttpStatusCode(); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @param Response $response |
|
| 71 | + * |
|
| 72 | + * @return GoogleMapsResponse |
|
| 73 | + */ |
|
| 74 | + public function setResponse(Response $response): GoogleMapsResponse { |
|
| 75 | + |
|
| 76 | + $this->response = $response; |
|
| 77 | + |
|
| 78 | + return $this; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @return GoogleMapsResponse |
|
| 83 | + * |
|
| 84 | + * @throws RequestException |
|
| 85 | + * @throws ResponseException |
|
| 86 | + */ |
|
| 87 | + protected function parseResponse(): GoogleMapsResponse { |
|
| 88 | + |
|
| 89 | + $json_response = $this->response->getBody()->getContents(); |
|
| 90 | + $array_response = $this->toArray($json_response); |
|
| 91 | + |
|
| 92 | + if (is_null($array_response[GoogleMapsResponseFields::RESULTS])) { |
|
| 93 | + throw new ResponseException('Missing "results" in GoogleMapsApi Response'); |
|
| 94 | + } |
|
| 95 | + $this->setResults($array_response[GoogleMapsResponseFields::RESULTS]); |
|
| 96 | + |
|
| 97 | + if (empty($array_response[GoogleMapsResponseFields::STATUS])) { |
|
| 98 | + throw new ResponseException('Missing "status" in GoogleMapsApi Response'); |
|
| 99 | + } |
|
| 100 | + $this->setStatus($array_response[GoogleMapsResponseFields::STATUS]); |
|
| 101 | + |
|
| 102 | + if ($this->getStatus() != GoogleMapsResponseStatusValues::OK) { |
|
| 103 | + $error_message = 'Something went wrong'; |
|
| 104 | + if (!empty($array_response[GoogleMapsResponseFields::ERROR_MESSAGE])) { |
|
| 105 | + $error_message = $array_response[GoogleMapsResponseFields::ERROR_MESSAGE]; |
|
| 106 | + $this->setErrorMessage($error_message); |
|
| 107 | + } |
|
| 108 | + throw new RequestException($error_message); |
|
| 109 | + |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + return $this; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Check HTTP status code (silent/No exceptions!) |
|
| 117 | + * @return int |
|
| 118 | + */ |
|
| 119 | + protected function checkHttpStatusCode(): int { |
|
| 120 | + |
|
| 121 | + $this->http_status_code = $this->response->getStatusCode(); |
|
| 122 | + |
|
| 123 | + return $this->http_status_code; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * @param string $json_response |
|
| 128 | + * |
|
| 129 | + * @return array |
|
| 130 | + */ |
|
| 131 | + public function toArray(string $json_response): array { |
|
| 132 | + |
|
| 133 | + $this->array_response = json_decode($json_response, true); |
|
| 134 | + |
|
| 135 | + return $this->array_response; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * @return array |
|
| 140 | + */ |
|
| 141 | + public function getResults() { |
|
| 142 | + |
|
| 143 | + return $this->results; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * @param array $results |
|
| 148 | + * |
|
| 149 | + * @return $this |
|
| 150 | + */ |
|
| 151 | + public function setResults(array $results) { |
|
| 152 | + |
|
| 153 | + $this->results = $results; |
|
| 154 | 154 | |
| 155 | - return $this; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * @return string |
|
| 160 | - */ |
|
| 161 | - public function getStatus(): string { |
|
| 155 | + return $this; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * @return string |
|
| 160 | + */ |
|
| 161 | + public function getStatus(): string { |
|
| 162 | 162 | |
| 163 | - return $this->status; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * @param string $status |
|
| 168 | - * |
|
| 169 | - * @return GoogleMapsResponse |
|
| 170 | - */ |
|
| 171 | - public function setStatus(string $status) { |
|
| 172 | - |
|
| 173 | - $this->status = $status; |
|
| 163 | + return $this->status; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * @param string $status |
|
| 168 | + * |
|
| 169 | + * @return GoogleMapsResponse |
|
| 170 | + */ |
|
| 171 | + public function setStatus(string $status) { |
|
| 172 | + |
|
| 173 | + $this->status = $status; |
|
| 174 | 174 | |
| 175 | - return $this; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * @return array |
|
| 180 | - */ |
|
| 181 | - public function getArrayResponse(): array { |
|
| 182 | - |
|
| 183 | - return $this->array_response; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * @param array $array_response |
|
| 188 | - * |
|
| 189 | - * @return GoogleMapsResponse |
|
| 190 | - */ |
|
| 191 | - public function setArrayResponse(array $array_response): GoogleMapsResponse { |
|
| 192 | - |
|
| 193 | - $this->array_response = $array_response; |
|
| 175 | + return $this; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * @return array |
|
| 180 | + */ |
|
| 181 | + public function getArrayResponse(): array { |
|
| 182 | + |
|
| 183 | + return $this->array_response; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * @param array $array_response |
|
| 188 | + * |
|
| 189 | + * @return GoogleMapsResponse |
|
| 190 | + */ |
|
| 191 | + public function setArrayResponse(array $array_response): GoogleMapsResponse { |
|
| 192 | + |
|
| 193 | + $this->array_response = $array_response; |
|
| 194 | 194 | |
| 195 | - return $this; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * @return mixed |
|
| 200 | - */ |
|
| 201 | - public function getErrorMessage() { |
|
| 195 | + return $this; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * @return mixed |
|
| 200 | + */ |
|
| 201 | + public function getErrorMessage() { |
|
| 202 | 202 | |
| 203 | - return $this->error_message; |
|
| 204 | - } |
|
| 203 | + return $this->error_message; |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | - /** |
|
| 207 | - * @param $error_message |
|
| 208 | - * |
|
| 209 | - * @return GoogleMapsResponse |
|
| 210 | - */ |
|
| 211 | - public function setErrorMessage($error_message): GoogleMapsResponse { |
|
| 206 | + /** |
|
| 207 | + * @param $error_message |
|
| 208 | + * |
|
| 209 | + * @return GoogleMapsResponse |
|
| 210 | + */ |
|
| 211 | + public function setErrorMessage($error_message): GoogleMapsResponse { |
|
| 212 | 212 | |
| 213 | - $this->error_message = $error_message; |
|
| 213 | + $this->error_message = $error_message; |
|
| 214 | 214 | |
| 215 | - return $this; |
|
| 216 | - } |
|
| 215 | + return $this; |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | - /** |
|
| 219 | - * @return int |
|
| 220 | - */ |
|
| 221 | - public function getHttpStatusCode(): int { |
|
| 218 | + /** |
|
| 219 | + * @return int |
|
| 220 | + */ |
|
| 221 | + public function getHttpStatusCode(): int { |
|
| 222 | 222 | |
| 223 | - return intval($this->http_status_code); |
|
| 224 | - } |
|
| 223 | + return intval($this->http_status_code); |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | 226 | } |
| 227 | 227 | \ No newline at end of file |
@@ -16,46 +16,46 @@ |
||
| 16 | 16 | |
| 17 | 17 | class GoogleMapsClient { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @var Client |
|
| 21 | - */ |
|
| 22 | - protected $client = null; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * GeocoderClient constructor. |
|
| 26 | - */ |
|
| 27 | - public function __construct() { |
|
| 28 | - |
|
| 29 | - $this->setClient(new Client()); |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @param null $client |
|
| 34 | - * |
|
| 35 | - * @return GoogleMapsClient |
|
| 36 | - */ |
|
| 37 | - public function setClient($client) { |
|
| 38 | - |
|
| 39 | - $this->client = $client; |
|
| 40 | - |
|
| 41 | - return $this; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @param string $url |
|
| 46 | - * @param null|string $query |
|
| 47 | - * |
|
| 48 | - * @return \Biscolab\GoogleMaps\Http\GoogleMapsResponse |
|
| 49 | - */ |
|
| 50 | - public function get(string $url, ?string $query = null): GoogleMapsResponse { |
|
| 51 | - |
|
| 52 | - $client_params = $query ? [ |
|
| 53 | - 'query' => $query |
|
| 54 | - ] : null; |
|
| 55 | - |
|
| 56 | - /** @var Response $res */ |
|
| 57 | - $res = $this->client->request(GoogleMapsRequestMethodValues::GET, $url, $client_params); |
|
| 58 | - |
|
| 59 | - return new GoogleMapsResponse($res); |
|
| 60 | - } |
|
| 19 | + /** |
|
| 20 | + * @var Client |
|
| 21 | + */ |
|
| 22 | + protected $client = null; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * GeocoderClient constructor. |
|
| 26 | + */ |
|
| 27 | + public function __construct() { |
|
| 28 | + |
|
| 29 | + $this->setClient(new Client()); |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @param null $client |
|
| 34 | + * |
|
| 35 | + * @return GoogleMapsClient |
|
| 36 | + */ |
|
| 37 | + public function setClient($client) { |
|
| 38 | + |
|
| 39 | + $this->client = $client; |
|
| 40 | + |
|
| 41 | + return $this; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @param string $url |
|
| 46 | + * @param null|string $query |
|
| 47 | + * |
|
| 48 | + * @return \Biscolab\GoogleMaps\Http\GoogleMapsResponse |
|
| 49 | + */ |
|
| 50 | + public function get(string $url, ?string $query = null): GoogleMapsResponse { |
|
| 51 | + |
|
| 52 | + $client_params = $query ? [ |
|
| 53 | + 'query' => $query |
|
| 54 | + ] : null; |
|
| 55 | + |
|
| 56 | + /** @var Response $res */ |
|
| 57 | + $res = $this->client->request(GoogleMapsRequestMethodValues::GET, $url, $client_params); |
|
| 58 | + |
|
| 59 | + return new GoogleMapsResponse($res); |
|
| 60 | + } |
|
| 61 | 61 | } |
| 62 | 62 | \ No newline at end of file |
@@ -18,13 +18,13 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class GeocodingResultsCollection extends GoogleMapsResultsCollection { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @param $item |
|
| 23 | - * |
|
| 24 | - * @return GeocodingResult |
|
| 25 | - */ |
|
| 26 | - protected function parseItem($item) { |
|
| 21 | + /** |
|
| 22 | + * @param $item |
|
| 23 | + * |
|
| 24 | + * @return GeocodingResult |
|
| 25 | + */ |
|
| 26 | + protected function parseItem($item) { |
|
| 27 | 27 | |
| 28 | - return new GeocodingResult($item); |
|
| 29 | - } |
|
| 28 | + return new GeocodingResult($item); |
|
| 29 | + } |
|
| 30 | 30 | } |
| 31 | 31 | \ No newline at end of file |
@@ -34,48 +34,48 @@ |
||
| 34 | 34 | */ |
| 35 | 35 | class GeocodingResult extends GoogleMapsResult { |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @var Address |
|
| 39 | - */ |
|
| 40 | - protected $address_components = null; |
|
| 37 | + /** |
|
| 38 | + * @var Address |
|
| 39 | + */ |
|
| 40 | + protected $address_components = null; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @var string |
|
| 44 | - */ |
|
| 45 | - protected $formatted_address = null; |
|
| 42 | + /** |
|
| 43 | + * @var string |
|
| 44 | + */ |
|
| 45 | + protected $formatted_address = null; |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @var Geometry |
|
| 49 | - */ |
|
| 50 | - protected $geometry = null; |
|
| 47 | + /** |
|
| 48 | + * @var Geometry |
|
| 49 | + */ |
|
| 50 | + protected $geometry = null; |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @var string |
|
| 54 | - */ |
|
| 55 | - protected $place_id = null; |
|
| 52 | + /** |
|
| 53 | + * @var string |
|
| 54 | + */ |
|
| 55 | + protected $place_id = null; |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * @var array |
|
| 59 | - */ |
|
| 60 | - protected $types = null; |
|
| 57 | + /** |
|
| 58 | + * @var array |
|
| 59 | + */ |
|
| 60 | + protected $types = null; |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * @var array |
|
| 64 | - */ |
|
| 65 | - protected $typeCheck = [ |
|
| 66 | - GoogleMapsResultFields::GEOMETRY => Geometry::class, |
|
| 67 | - GoogleMapsResultFields::ADDRESS_COMPONENTS => Address::class, |
|
| 68 | - GoogleMapsResultFields::FORMATTED_ADDRESS => 'string', |
|
| 69 | - GoogleMapsResultFields::PLACE_ID => 'string', |
|
| 70 | - GoogleMapsResultFields::TYPES => 'array' |
|
| 71 | - ]; |
|
| 62 | + /** |
|
| 63 | + * @var array |
|
| 64 | + */ |
|
| 65 | + protected $typeCheck = [ |
|
| 66 | + GoogleMapsResultFields::GEOMETRY => Geometry::class, |
|
| 67 | + GoogleMapsResultFields::ADDRESS_COMPONENTS => Address::class, |
|
| 68 | + GoogleMapsResultFields::FORMATTED_ADDRESS => 'string', |
|
| 69 | + GoogleMapsResultFields::PLACE_ID => 'string', |
|
| 70 | + GoogleMapsResultFields::TYPES => 'array' |
|
| 71 | + ]; |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * @return Address |
|
| 75 | - */ |
|
| 76 | - public function getAddress(): Address { |
|
| 73 | + /** |
|
| 74 | + * @return Address |
|
| 75 | + */ |
|
| 76 | + public function getAddress(): Address { |
|
| 77 | 77 | |
| 78 | - return $this->getAddressComponents(); |
|
| 79 | - } |
|
| 78 | + return $this->getAddressComponents(); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | 81 | } |
| 82 | 82 | \ No newline at end of file |
@@ -18,50 +18,50 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class GoogleMapsRequest { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @var array |
|
| 23 | - */ |
|
| 24 | - private $params = []; |
|
| 21 | + /** |
|
| 22 | + * @var array |
|
| 23 | + */ |
|
| 24 | + private $params = []; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * GoogleMapsRequest constructor. |
|
| 28 | - * |
|
| 29 | - * @param array $params |
|
| 30 | - */ |
|
| 31 | - public function __construct(array $params = []) { |
|
| 26 | + /** |
|
| 27 | + * GoogleMapsRequest constructor. |
|
| 28 | + * |
|
| 29 | + * @param array $params |
|
| 30 | + */ |
|
| 31 | + public function __construct(array $params = []) { |
|
| 32 | 32 | |
| 33 | - if ($params) { |
|
| 34 | - foreach ($params as $param_name => $param_value) { |
|
| 35 | - $this->addParam($param_name, $param_value); |
|
| 36 | - } |
|
| 37 | - } |
|
| 38 | - } |
|
| 33 | + if ($params) { |
|
| 34 | + foreach ($params as $param_name => $param_value) { |
|
| 35 | + $this->addParam($param_name, $param_value); |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @param string $param_name |
|
| 42 | - * @param AbstractObject $param_value |
|
| 43 | - * |
|
| 44 | - * @return GoogleMapsRequest |
|
| 45 | - */ |
|
| 46 | - public function addParam(string $param_name, $param_value): GoogleMapsRequest { |
|
| 40 | + /** |
|
| 41 | + * @param string $param_name |
|
| 42 | + * @param AbstractObject $param_value |
|
| 43 | + * |
|
| 44 | + * @return GoogleMapsRequest |
|
| 45 | + */ |
|
| 46 | + public function addParam(string $param_name, $param_value): GoogleMapsRequest { |
|
| 47 | 47 | |
| 48 | - $this->params[$param_name] = $param_value; |
|
| 48 | + $this->params[$param_name] = $param_value; |
|
| 49 | 49 | |
| 50 | - return $this; |
|
| 51 | - } |
|
| 50 | + return $this; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @return string |
|
| 55 | - */ |
|
| 56 | - public function getQuery(): string { |
|
| 53 | + /** |
|
| 54 | + * @return string |
|
| 55 | + */ |
|
| 56 | + public function getQuery(): string { |
|
| 57 | 57 | |
| 58 | - $params = []; |
|
| 58 | + $params = []; |
|
| 59 | 59 | |
| 60 | - foreach ($this->params as $param_name => $param_value) { |
|
| 61 | - $params[$param_name] = (string)$param_value; |
|
| 62 | - } |
|
| 60 | + foreach ($this->params as $param_name => $param_value) { |
|
| 61 | + $params[$param_name] = (string)$param_value; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - return http_build_query($params); |
|
| 65 | - } |
|
| 64 | + return http_build_query($params); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | 67 | } |
| 68 | 68 | \ No newline at end of file |
@@ -58,7 +58,7 @@ |
||
| 58 | 58 | $params = []; |
| 59 | 59 | |
| 60 | 60 | foreach ($this->params as $param_name => $param_value) { |
| 61 | - $params[$param_name] = (string)$param_value; |
|
| 61 | + $params[$param_name] = (string) $param_value; |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | return http_build_query($params); |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | function camel2Snake(string $camel): string { |
| 19 | 19 | |
| 20 | - return preg_replace('/^_/', '', strtolower(implode('_', preg_split('/(?=[A-Z])/', $camel)))); |
|
| 20 | + return preg_replace('/^_/', '', strtolower(implode('_', preg_split('/(?=[A-Z])/', $camel)))); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -27,5 +27,5 @@ discard block |
||
| 27 | 27 | */ |
| 28 | 28 | function snake2Camel(string $snake): string { |
| 29 | 29 | |
| 30 | - return lcfirst(preg_replace('/_/', '', ucwords($snake, '_'))); |
|
| 30 | + return lcfirst(preg_replace('/_/', '', ucwords($snake, '_'))); |
|
| 31 | 31 | } |
| 32 | 32 | \ No newline at end of file |
@@ -25,73 +25,73 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | class Geocoding extends Api { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var string |
|
| 30 | - */ |
|
| 31 | - const SERVICE_ENDPOINT = 'geocode'; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @param string $literal_address |
|
| 35 | - * |
|
| 36 | - * @return GoogleMapsResultsCollection |
|
| 37 | - */ |
|
| 38 | - public function getByAddress(string $literal_address): GoogleMapsResultsCollection { |
|
| 39 | - |
|
| 40 | - $request = new GoogleMapsRequest([ |
|
| 41 | - GoogleMapsRequestFields::ADDRESS => $literal_address |
|
| 42 | - ]); |
|
| 43 | - |
|
| 44 | - return $this->getResultsCollections($request); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @param LatLng $latlng |
|
| 49 | - * |
|
| 50 | - * @return GoogleMapsResultsCollection |
|
| 51 | - */ |
|
| 52 | - public function getReverse(LatLng $latlng): GoogleMapsResultsCollection { |
|
| 53 | - |
|
| 54 | - $request = $this->createRequest([ |
|
| 55 | - GoogleMapsRequestFields::LATLNG => $latlng |
|
| 56 | - ]); |
|
| 57 | - |
|
| 58 | - return $this->getResultsCollections($request); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @param string $place_id |
|
| 63 | - * |
|
| 64 | - * @return GoogleMapsResultsCollection |
|
| 65 | - */ |
|
| 66 | - public function getByPlaceId(string $place_id): GoogleMapsResultsCollection { |
|
| 67 | - |
|
| 68 | - $request = $this->createRequest([ |
|
| 69 | - GoogleMapsRequestFields::PLACE_ID => $place_id |
|
| 70 | - ]); |
|
| 71 | - |
|
| 72 | - return $this->getResultsCollections($request); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @param GoogleMapsRequest $request |
|
| 77 | - * |
|
| 78 | - * @return GoogleMapsResultsCollection |
|
| 79 | - */ |
|
| 80 | - public function getResultsCollections(GoogleMapsRequest $request): GoogleMapsResultsCollection { |
|
| 81 | - |
|
| 82 | - $results = $this->getGoogleMapsApi()->get($request)->getResults(); |
|
| 83 | - |
|
| 84 | - return new GeocodingResultsCollection($results); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @param array $params |
|
| 89 | - * |
|
| 90 | - * @return GoogleMapsRequest |
|
| 91 | - */ |
|
| 92 | - public function createRequest(array $params): GoogleMapsRequest { |
|
| 93 | - |
|
| 94 | - return new GoogleMapsRequest($params); |
|
| 95 | - } |
|
| 28 | + /** |
|
| 29 | + * @var string |
|
| 30 | + */ |
|
| 31 | + const SERVICE_ENDPOINT = 'geocode'; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @param string $literal_address |
|
| 35 | + * |
|
| 36 | + * @return GoogleMapsResultsCollection |
|
| 37 | + */ |
|
| 38 | + public function getByAddress(string $literal_address): GoogleMapsResultsCollection { |
|
| 39 | + |
|
| 40 | + $request = new GoogleMapsRequest([ |
|
| 41 | + GoogleMapsRequestFields::ADDRESS => $literal_address |
|
| 42 | + ]); |
|
| 43 | + |
|
| 44 | + return $this->getResultsCollections($request); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @param LatLng $latlng |
|
| 49 | + * |
|
| 50 | + * @return GoogleMapsResultsCollection |
|
| 51 | + */ |
|
| 52 | + public function getReverse(LatLng $latlng): GoogleMapsResultsCollection { |
|
| 53 | + |
|
| 54 | + $request = $this->createRequest([ |
|
| 55 | + GoogleMapsRequestFields::LATLNG => $latlng |
|
| 56 | + ]); |
|
| 57 | + |
|
| 58 | + return $this->getResultsCollections($request); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @param string $place_id |
|
| 63 | + * |
|
| 64 | + * @return GoogleMapsResultsCollection |
|
| 65 | + */ |
|
| 66 | + public function getByPlaceId(string $place_id): GoogleMapsResultsCollection { |
|
| 67 | + |
|
| 68 | + $request = $this->createRequest([ |
|
| 69 | + GoogleMapsRequestFields::PLACE_ID => $place_id |
|
| 70 | + ]); |
|
| 71 | + |
|
| 72 | + return $this->getResultsCollections($request); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @param GoogleMapsRequest $request |
|
| 77 | + * |
|
| 78 | + * @return GoogleMapsResultsCollection |
|
| 79 | + */ |
|
| 80 | + public function getResultsCollections(GoogleMapsRequest $request): GoogleMapsResultsCollection { |
|
| 81 | + |
|
| 82 | + $results = $this->getGoogleMapsApi()->get($request)->getResults(); |
|
| 83 | + |
|
| 84 | + return new GeocodingResultsCollection($results); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * @param array $params |
|
| 89 | + * |
|
| 90 | + * @return GoogleMapsRequest |
|
| 91 | + */ |
|
| 92 | + public function createRequest(array $params): GoogleMapsRequest { |
|
| 93 | + |
|
| 94 | + return new GoogleMapsRequest($params); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | 97 | } |
| 98 | 98 | \ No newline at end of file |
@@ -18,23 +18,23 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class GeometryLocationTypeValues { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * string: ROOFTOP |
|
| 23 | - */ |
|
| 24 | - const ROOFTOP = 'ROOFTOP'; |
|
| 21 | + /** |
|
| 22 | + * string: ROOFTOP |
|
| 23 | + */ |
|
| 24 | + const ROOFTOP = 'ROOFTOP'; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * string: RANGE_INTERPOLATED |
|
| 28 | - */ |
|
| 29 | - const RANGE_INTERPOLATED = 'RANGE_INTERPOLATED'; |
|
| 26 | + /** |
|
| 27 | + * string: RANGE_INTERPOLATED |
|
| 28 | + */ |
|
| 29 | + const RANGE_INTERPOLATED = 'RANGE_INTERPOLATED'; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * string: GEOMETRIC_CENTER |
|
| 33 | - */ |
|
| 34 | - const GEOMETRIC_CENTER = 'GEOMETRIC_CENTER'; |
|
| 31 | + /** |
|
| 32 | + * string: GEOMETRIC_CENTER |
|
| 33 | + */ |
|
| 34 | + const GEOMETRIC_CENTER = 'GEOMETRIC_CENTER'; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * string: APPROXIMATE |
|
| 38 | - */ |
|
| 39 | - const APPROXIMATE = 'APPROXIMATE'; |
|
| 36 | + /** |
|
| 37 | + * string: APPROXIMATE |
|
| 38 | + */ |
|
| 39 | + const APPROXIMATE = 'APPROXIMATE'; |
|
| 40 | 40 | } |
| 41 | 41 | \ No newline at end of file |
@@ -18,39 +18,39 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class GoogleMapsResponseStatusValues { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * string: OK |
|
| 23 | - */ |
|
| 24 | - const OK = 'OK'; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * string: REQUEST_DENIED |
|
| 28 | - */ |
|
| 29 | - const REQUEST_DENIED = 'REQUEST_DENIED'; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * string: ZERO_RESULTS |
|
| 33 | - */ |
|
| 34 | - const ZERO_RESULTS = 'ZERO_RESULTS'; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * string: OVER_DAILY_LIMIT |
|
| 38 | - */ |
|
| 39 | - const OVER_DAILY_LIMIT = 'OVER_DAILY_LIMIT'; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * string: OVER_QUERY_LIMIT |
|
| 43 | - */ |
|
| 44 | - const OVER_QUERY_LIMIT = 'OVER_QUERY_LIMIT'; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * string: INVALID_REQUEST |
|
| 48 | - */ |
|
| 49 | - const INVALID_REQUEST = 'INVALID_REQUEST'; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * string: UNKNOWN_ERROR |
|
| 53 | - */ |
|
| 54 | - const UNKNOWN_ERROR = 'UNKNOWN_ERROR'; |
|
| 21 | + /** |
|
| 22 | + * string: OK |
|
| 23 | + */ |
|
| 24 | + const OK = 'OK'; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * string: REQUEST_DENIED |
|
| 28 | + */ |
|
| 29 | + const REQUEST_DENIED = 'REQUEST_DENIED'; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * string: ZERO_RESULTS |
|
| 33 | + */ |
|
| 34 | + const ZERO_RESULTS = 'ZERO_RESULTS'; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * string: OVER_DAILY_LIMIT |
|
| 38 | + */ |
|
| 39 | + const OVER_DAILY_LIMIT = 'OVER_DAILY_LIMIT'; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * string: OVER_QUERY_LIMIT |
|
| 43 | + */ |
|
| 44 | + const OVER_QUERY_LIMIT = 'OVER_QUERY_LIMIT'; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * string: INVALID_REQUEST |
|
| 48 | + */ |
|
| 49 | + const INVALID_REQUEST = 'INVALID_REQUEST'; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * string: UNKNOWN_ERROR |
|
| 53 | + */ |
|
| 54 | + const UNKNOWN_ERROR = 'UNKNOWN_ERROR'; |
|
| 55 | 55 | |
| 56 | 56 | } |
| 57 | 57 | \ No newline at end of file |