@@ -25,182 +25,182 @@ |
||
| 25 | 25 | abstract class Api |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var string |
|
| 30 | - */ |
|
| 31 | - const SERVICE_ENDPOINT = null; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var GoogleMapsApi |
|
| 35 | - */ |
|
| 36 | - protected $google_maps_api = null; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @var string |
|
| 40 | - */ |
|
| 41 | - protected $result_type = ''; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @var string |
|
| 45 | - */ |
|
| 46 | - protected $result_collection_type = ''; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @var GoogleMapsResponse |
|
| 50 | - */ |
|
| 51 | - protected $response; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @var GoogleMapsRequest |
|
| 55 | - */ |
|
| 56 | - protected $request; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Api constructor. |
|
| 60 | - * |
|
| 61 | - * @param array $config |
|
| 62 | - */ |
|
| 63 | - public function __construct(array $config = []) |
|
| 64 | - { |
|
| 65 | - |
|
| 66 | - $service_config = $this->getServiceConfig($config); |
|
| 67 | - $this->setGoogleMapsApi(new GoogleMapsApi($service_config)); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @param array $config |
|
| 72 | - * |
|
| 73 | - * @return array |
|
| 74 | - */ |
|
| 75 | - protected function getServiceConfig(array $config = []): array |
|
| 76 | - { |
|
| 77 | - |
|
| 78 | - return array_merge($config, [ |
|
| 79 | - GoogleMapsApiConfigFields::SERVICE_ENDPOINT => $this->getServiceEndpoint() |
|
| 80 | - ]); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @return string |
|
| 85 | - */ |
|
| 86 | - public function getServiceEndpoint(): string |
|
| 87 | - { |
|
| 88 | - |
|
| 89 | - return static::SERVICE_ENDPOINT ?? ''; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @param array $params |
|
| 94 | - * @param null|string $endpoint |
|
| 95 | - * |
|
| 96 | - * @return GoogleMapsResult|GoogleMapsResultsCollection |
|
| 97 | - */ |
|
| 98 | - public function callApi(array $params, ?string $endpoint = null) |
|
| 99 | - { |
|
| 100 | - |
|
| 101 | - $this->createRequest($params, $endpoint); |
|
| 102 | - |
|
| 103 | - return $this->getResponseResult(); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * @param array $params |
|
| 108 | - * @param null|string $endpoint since 0.5.0 |
|
| 109 | - * |
|
| 110 | - * @return GoogleMapsRequest |
|
| 111 | - */ |
|
| 112 | - public function createRequest(array $params, ?string $endpoint = null): GoogleMapsRequest |
|
| 113 | - { |
|
| 114 | - |
|
| 115 | - $this->request = new GoogleMapsRequest($params, $endpoint);; |
|
| 116 | - |
|
| 117 | - return $this->request; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * @return GoogleMapsResult|GoogleMapsResultsCollection |
|
| 122 | - */ |
|
| 123 | - public function getResponseResult() |
|
| 124 | - { |
|
| 125 | - |
|
| 126 | - $result = $this->getResponse()->getResult(); |
|
| 127 | - if ($result) { |
|
| 128 | - $result_type = $this->result_type; |
|
| 129 | - |
|
| 130 | - return new $result_type($result); |
|
| 131 | - } |
|
| 132 | - $results = $this->getResponse()->getResults(); |
|
| 133 | - |
|
| 134 | - $result_collection_type_class = $this->result_collection_type; |
|
| 135 | - |
|
| 136 | - return new $result_collection_type_class($results); |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @return GoogleMapsResponse |
|
| 141 | - */ |
|
| 142 | - public function getResponse(): GoogleMapsResponse |
|
| 143 | - { |
|
| 144 | - |
|
| 145 | - $this->response = $this->getGoogleMapsApi()->get($this->request); |
|
| 146 | - |
|
| 147 | - return $this->response; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * @return GoogleMapsApi |
|
| 152 | - */ |
|
| 153 | - public function getGoogleMapsApi(): GoogleMapsApi |
|
| 154 | - { |
|
| 155 | - |
|
| 156 | - return $this->google_maps_api; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * @param GoogleMapsApi $google_maps_api |
|
| 161 | - * |
|
| 162 | - * @return Api |
|
| 163 | - */ |
|
| 164 | - public function setGoogleMapsApi(GoogleMapsApi $google_maps_api): Api |
|
| 165 | - { |
|
| 166 | - |
|
| 167 | - $this->google_maps_api = $google_maps_api; |
|
| 168 | - |
|
| 169 | - return $this; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * @return GoogleMapsResultsCollection |
|
| 174 | - */ |
|
| 175 | - public function getSingleResult(): GoogleMapsResultsCollection |
|
| 176 | - { |
|
| 177 | - |
|
| 178 | - $results = $this->getResponse()->getResults(); |
|
| 179 | - |
|
| 180 | - $result_collection_type_class = $this->result_collection_type; |
|
| 181 | - |
|
| 182 | - return new $result_collection_type_class($results); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * @return GoogleMapsResultsCollection |
|
| 187 | - */ |
|
| 188 | - public function getNextPage(): GoogleMapsResultsCollection |
|
| 189 | - { |
|
| 190 | - |
|
| 191 | - if ($this->responseHasNewPage()) { |
|
| 192 | - $this->request->setParam(GoogleMapsRequestFields::NEXT_PAGE_TOKEN, $this->response->getNextPageToken()); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - return $this->getResponseResult(); |
|
| 196 | - } |
|
| 28 | + /** |
|
| 29 | + * @var string |
|
| 30 | + */ |
|
| 31 | + const SERVICE_ENDPOINT = null; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var GoogleMapsApi |
|
| 35 | + */ |
|
| 36 | + protected $google_maps_api = null; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @var string |
|
| 40 | + */ |
|
| 41 | + protected $result_type = ''; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @var string |
|
| 45 | + */ |
|
| 46 | + protected $result_collection_type = ''; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @var GoogleMapsResponse |
|
| 50 | + */ |
|
| 51 | + protected $response; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @var GoogleMapsRequest |
|
| 55 | + */ |
|
| 56 | + protected $request; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Api constructor. |
|
| 60 | + * |
|
| 61 | + * @param array $config |
|
| 62 | + */ |
|
| 63 | + public function __construct(array $config = []) |
|
| 64 | + { |
|
| 65 | + |
|
| 66 | + $service_config = $this->getServiceConfig($config); |
|
| 67 | + $this->setGoogleMapsApi(new GoogleMapsApi($service_config)); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @param array $config |
|
| 72 | + * |
|
| 73 | + * @return array |
|
| 74 | + */ |
|
| 75 | + protected function getServiceConfig(array $config = []): array |
|
| 76 | + { |
|
| 77 | + |
|
| 78 | + return array_merge($config, [ |
|
| 79 | + GoogleMapsApiConfigFields::SERVICE_ENDPOINT => $this->getServiceEndpoint() |
|
| 80 | + ]); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @return string |
|
| 85 | + */ |
|
| 86 | + public function getServiceEndpoint(): string |
|
| 87 | + { |
|
| 88 | + |
|
| 89 | + return static::SERVICE_ENDPOINT ?? ''; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @param array $params |
|
| 94 | + * @param null|string $endpoint |
|
| 95 | + * |
|
| 96 | + * @return GoogleMapsResult|GoogleMapsResultsCollection |
|
| 97 | + */ |
|
| 98 | + public function callApi(array $params, ?string $endpoint = null) |
|
| 99 | + { |
|
| 100 | + |
|
| 101 | + $this->createRequest($params, $endpoint); |
|
| 102 | + |
|
| 103 | + return $this->getResponseResult(); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * @param array $params |
|
| 108 | + * @param null|string $endpoint since 0.5.0 |
|
| 109 | + * |
|
| 110 | + * @return GoogleMapsRequest |
|
| 111 | + */ |
|
| 112 | + public function createRequest(array $params, ?string $endpoint = null): GoogleMapsRequest |
|
| 113 | + { |
|
| 114 | + |
|
| 115 | + $this->request = new GoogleMapsRequest($params, $endpoint);; |
|
| 116 | + |
|
| 117 | + return $this->request; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * @return GoogleMapsResult|GoogleMapsResultsCollection |
|
| 122 | + */ |
|
| 123 | + public function getResponseResult() |
|
| 124 | + { |
|
| 125 | + |
|
| 126 | + $result = $this->getResponse()->getResult(); |
|
| 127 | + if ($result) { |
|
| 128 | + $result_type = $this->result_type; |
|
| 129 | + |
|
| 130 | + return new $result_type($result); |
|
| 131 | + } |
|
| 132 | + $results = $this->getResponse()->getResults(); |
|
| 133 | + |
|
| 134 | + $result_collection_type_class = $this->result_collection_type; |
|
| 135 | + |
|
| 136 | + return new $result_collection_type_class($results); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @return GoogleMapsResponse |
|
| 141 | + */ |
|
| 142 | + public function getResponse(): GoogleMapsResponse |
|
| 143 | + { |
|
| 144 | + |
|
| 145 | + $this->response = $this->getGoogleMapsApi()->get($this->request); |
|
| 146 | + |
|
| 147 | + return $this->response; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * @return GoogleMapsApi |
|
| 152 | + */ |
|
| 153 | + public function getGoogleMapsApi(): GoogleMapsApi |
|
| 154 | + { |
|
| 155 | + |
|
| 156 | + return $this->google_maps_api; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * @param GoogleMapsApi $google_maps_api |
|
| 161 | + * |
|
| 162 | + * @return Api |
|
| 163 | + */ |
|
| 164 | + public function setGoogleMapsApi(GoogleMapsApi $google_maps_api): Api |
|
| 165 | + { |
|
| 166 | + |
|
| 167 | + $this->google_maps_api = $google_maps_api; |
|
| 168 | + |
|
| 169 | + return $this; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * @return GoogleMapsResultsCollection |
|
| 174 | + */ |
|
| 175 | + public function getSingleResult(): GoogleMapsResultsCollection |
|
| 176 | + { |
|
| 177 | + |
|
| 178 | + $results = $this->getResponse()->getResults(); |
|
| 179 | + |
|
| 180 | + $result_collection_type_class = $this->result_collection_type; |
|
| 181 | + |
|
| 182 | + return new $result_collection_type_class($results); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * @return GoogleMapsResultsCollection |
|
| 187 | + */ |
|
| 188 | + public function getNextPage(): GoogleMapsResultsCollection |
|
| 189 | + { |
|
| 190 | + |
|
| 191 | + if ($this->responseHasNewPage()) { |
|
| 192 | + $this->request->setParam(GoogleMapsRequestFields::NEXT_PAGE_TOKEN, $this->response->getNextPageToken()); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + return $this->getResponseResult(); |
|
| 196 | + } |
|
| 197 | 197 | |
| 198 | - /** |
|
| 199 | - * @return bool |
|
| 200 | - */ |
|
| 201 | - public function responseHasNewPage(): bool |
|
| 202 | - { |
|
| 198 | + /** |
|
| 199 | + * @return bool |
|
| 200 | + */ |
|
| 201 | + public function responseHasNewPage(): bool |
|
| 202 | + { |
|
| 203 | 203 | |
| 204 | - return ($this->response instanceof GoogleMapsResponse) ? $this->response->getNextPageToken() : false; |
|
| 205 | - } |
|
| 204 | + return ($this->response instanceof GoogleMapsResponse) ? $this->response->getNextPageToken() : false; |
|
| 205 | + } |
|
| 206 | 206 | } |
| 207 | 207 | \ No newline at end of file |
@@ -21,37 +21,37 @@ |
||
| 21 | 21 | class Review extends AbstractObject |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @var null|int |
|
| 26 | - */ |
|
| 27 | - protected $height = null; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @var null|int |
|
| 31 | - */ |
|
| 32 | - protected $width = null; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @var null|string |
|
| 36 | - */ |
|
| 37 | - protected $photo_reference = null; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @var null|string |
|
| 41 | - */ |
|
| 42 | - protected $html_attributions = null; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @var array |
|
| 46 | - */ |
|
| 47 | - protected $typeCheck = [ |
|
| 48 | - ReviewFields::AUTHOR_NAME => 'string', |
|
| 49 | - ReviewFields::AUTHOR_URL => 'string', |
|
| 50 | - ReviewFields::LANGUAGE => 'string', |
|
| 51 | - ReviewFields::PROFILE_PHOTO_URL => 'string', |
|
| 52 | - ReviewFields::RATING => 'int', |
|
| 53 | - ReviewFields::RELATIVE_TIME_DESCRIPTION => 'string', |
|
| 54 | - ReviewFields::TEXT => 'string', |
|
| 55 | - ReviewFields::TIME => 'int', |
|
| 56 | - ]; |
|
| 24 | + /** |
|
| 25 | + * @var null|int |
|
| 26 | + */ |
|
| 27 | + protected $height = null; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @var null|int |
|
| 31 | + */ |
|
| 32 | + protected $width = null; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @var null|string |
|
| 36 | + */ |
|
| 37 | + protected $photo_reference = null; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @var null|string |
|
| 41 | + */ |
|
| 42 | + protected $html_attributions = null; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @var array |
|
| 46 | + */ |
|
| 47 | + protected $typeCheck = [ |
|
| 48 | + ReviewFields::AUTHOR_NAME => 'string', |
|
| 49 | + ReviewFields::AUTHOR_URL => 'string', |
|
| 50 | + ReviewFields::LANGUAGE => 'string', |
|
| 51 | + ReviewFields::PROFILE_PHOTO_URL => 'string', |
|
| 52 | + ReviewFields::RATING => 'int', |
|
| 53 | + ReviewFields::RELATIVE_TIME_DESCRIPTION => 'string', |
|
| 54 | + ReviewFields::TEXT => 'string', |
|
| 55 | + ReviewFields::TIME => 'int', |
|
| 56 | + ]; |
|
| 57 | 57 | } |
| 58 | 58 | \ No newline at end of file |
@@ -20,19 +20,19 @@ |
||
| 20 | 20 | class ReviewCollection extends AbstractCollection |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @var string |
|
| 25 | - */ |
|
| 26 | - protected $item_class = Review::class; |
|
| 23 | + /** |
|
| 24 | + * @var string |
|
| 25 | + */ |
|
| 26 | + protected $item_class = Review::class; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @param $item |
|
| 30 | - * |
|
| 31 | - * @return Review |
|
| 32 | - */ |
|
| 33 | - protected function parseItem($item): Review |
|
| 34 | - { |
|
| 28 | + /** |
|
| 29 | + * @param $item |
|
| 30 | + * |
|
| 31 | + * @return Review |
|
| 32 | + */ |
|
| 33 | + protected function parseItem($item): Review |
|
| 34 | + { |
|
| 35 | 35 | |
| 36 | - return ($item instanceof $this->item_class) ? $item : new $this->item_class($item); |
|
| 37 | - } |
|
| 36 | + return ($item instanceof $this->item_class) ? $item : new $this->item_class($item); |
|
| 37 | + } |
|
| 38 | 38 | } |
| 39 | 39 | \ No newline at end of file |
@@ -28,92 +28,92 @@ |
||
| 28 | 28 | class Elevation extends Api |
| 29 | 29 | { |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @var string |
|
| 33 | - */ |
|
| 34 | - const SERVICE_ENDPOINT = 'elevation'; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var string |
|
| 38 | - */ |
|
| 39 | - protected $result_collection_type = ElevationResultsCollection::class; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Positional Requests |
|
| 43 | - * |
|
| 44 | - * @param LatLng|string|array $locations |
|
| 45 | - * This parameter takes either a single location or multiple locations passed as an array or as an encoded polyline |
|
| 46 | - * |
|
| 47 | - * @return GoogleMapsResultsCollection |
|
| 48 | - * |
|
| 49 | - * @since 0.3.0 |
|
| 50 | - */ |
|
| 51 | - public function getByLocations($locations): GoogleMapsResultsCollection |
|
| 52 | - { |
|
| 53 | - |
|
| 54 | - $locations = $this->parseLocations($locations); |
|
| 55 | - |
|
| 56 | - return $this->callApi([ |
|
| 57 | - GoogleMapsRequestFields::LOCATIONS => $locations |
|
| 58 | - ]); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @param array|string $locations |
|
| 63 | - * |
|
| 64 | - * @return string |
|
| 65 | - * |
|
| 66 | - * @since 0.3.0 |
|
| 67 | - */ |
|
| 68 | - public function parseLocations($locations): string |
|
| 69 | - { |
|
| 70 | - |
|
| 71 | - if ($locations instanceof Path) { |
|
| 72 | - $locations = $locations->toArray(); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - if (is_array($locations)) { |
|
| 76 | - $locations = implode('|', array_map(function ($item) { |
|
| 77 | - |
|
| 78 | - return (string)$item; |
|
| 79 | - }, $locations)); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - return (string)$locations; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Sampled Path Requests |
|
| 87 | - * |
|
| 88 | - * @param array|string $path |
|
| 89 | - * This parameter takes either a multiple locations passed as an array or as an encoded polyline |
|
| 90 | - * |
|
| 91 | - * @param int $samples |
|
| 92 | - * This will be the number of results as well |
|
| 93 | - * |
|
| 94 | - * @throws InvalidArgumentException |
|
| 95 | - * @return GoogleMapsResultsCollection |
|
| 96 | - * |
|
| 97 | - * @since 0.4.0 |
|
| 98 | - */ |
|
| 99 | - public function getBySampledPath($path, int $samples): GoogleMapsResultsCollection |
|
| 100 | - { |
|
| 101 | - |
|
| 102 | - if ((is_array($path) && count($path) < 2) || |
|
| 103 | - $path instanceof Path && $path->count() < 2) { |
|
| 104 | - throw new InvalidArgumentException('The number of items provided in the path must be greater than 1 (One)'); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - if ($samples <= 0) { |
|
| 108 | - throw new InvalidArgumentException('The number of samples must be greater than 0 (Zero)'); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - $path = $this->parseLocations($path); |
|
| 112 | - |
|
| 113 | - return $this->callApi([ |
|
| 114 | - GoogleMapsRequestFields::PATH => $path, |
|
| 115 | - GoogleMapsRequestFields::SAMPLES => $samples, |
|
| 116 | - ]); |
|
| 117 | - } |
|
| 31 | + /** |
|
| 32 | + * @var string |
|
| 33 | + */ |
|
| 34 | + const SERVICE_ENDPOINT = 'elevation'; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var string |
|
| 38 | + */ |
|
| 39 | + protected $result_collection_type = ElevationResultsCollection::class; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Positional Requests |
|
| 43 | + * |
|
| 44 | + * @param LatLng|string|array $locations |
|
| 45 | + * This parameter takes either a single location or multiple locations passed as an array or as an encoded polyline |
|
| 46 | + * |
|
| 47 | + * @return GoogleMapsResultsCollection |
|
| 48 | + * |
|
| 49 | + * @since 0.3.0 |
|
| 50 | + */ |
|
| 51 | + public function getByLocations($locations): GoogleMapsResultsCollection |
|
| 52 | + { |
|
| 53 | + |
|
| 54 | + $locations = $this->parseLocations($locations); |
|
| 55 | + |
|
| 56 | + return $this->callApi([ |
|
| 57 | + GoogleMapsRequestFields::LOCATIONS => $locations |
|
| 58 | + ]); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @param array|string $locations |
|
| 63 | + * |
|
| 64 | + * @return string |
|
| 65 | + * |
|
| 66 | + * @since 0.3.0 |
|
| 67 | + */ |
|
| 68 | + public function parseLocations($locations): string |
|
| 69 | + { |
|
| 70 | + |
|
| 71 | + if ($locations instanceof Path) { |
|
| 72 | + $locations = $locations->toArray(); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + if (is_array($locations)) { |
|
| 76 | + $locations = implode('|', array_map(function ($item) { |
|
| 77 | + |
|
| 78 | + return (string)$item; |
|
| 79 | + }, $locations)); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + return (string)$locations; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Sampled Path Requests |
|
| 87 | + * |
|
| 88 | + * @param array|string $path |
|
| 89 | + * This parameter takes either a multiple locations passed as an array or as an encoded polyline |
|
| 90 | + * |
|
| 91 | + * @param int $samples |
|
| 92 | + * This will be the number of results as well |
|
| 93 | + * |
|
| 94 | + * @throws InvalidArgumentException |
|
| 95 | + * @return GoogleMapsResultsCollection |
|
| 96 | + * |
|
| 97 | + * @since 0.4.0 |
|
| 98 | + */ |
|
| 99 | + public function getBySampledPath($path, int $samples): GoogleMapsResultsCollection |
|
| 100 | + { |
|
| 101 | + |
|
| 102 | + if ((is_array($path) && count($path) < 2) || |
|
| 103 | + $path instanceof Path && $path->count() < 2) { |
|
| 104 | + throw new InvalidArgumentException('The number of items provided in the path must be greater than 1 (One)'); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + if ($samples <= 0) { |
|
| 108 | + throw new InvalidArgumentException('The number of samples must be greater than 0 (Zero)'); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + $path = $this->parseLocations($path); |
|
| 112 | + |
|
| 113 | + return $this->callApi([ |
|
| 114 | + GoogleMapsRequestFields::PATH => $path, |
|
| 115 | + GoogleMapsRequestFields::SAMPLES => $samples, |
|
| 116 | + ]); |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | 119 | } |
| 120 | 120 | \ No newline at end of file |
@@ -34,233 +34,233 @@ |
||
| 34 | 34 | class Places extends Api |
| 35 | 35 | { |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @var string |
|
| 39 | - */ |
|
| 40 | - const SERVICE_ENDPOINT = 'place'; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @var string |
|
| 44 | - */ |
|
| 45 | - protected $result_type = PlacesResult::class; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @var string |
|
| 49 | - */ |
|
| 50 | - protected $result_collection_type = PlaceResultsCollection::class; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @param string $query |
|
| 54 | - * @param array|null $params |
|
| 55 | - * @param array|null $fields |
|
| 56 | - * |
|
| 57 | - * @return GoogleMapsResultsCollection |
|
| 58 | - * @see https://developers.google.com/places/web-service/search#FindPlaceRequests |
|
| 59 | - */ |
|
| 60 | - public function findPlaceByText( |
|
| 61 | - string $query, |
|
| 62 | - ?array $params = [], |
|
| 63 | - ?array $fields = [] |
|
| 64 | - ): GoogleMapsResultsCollection { |
|
| 65 | - |
|
| 66 | - $params = array_merge($params, [ |
|
| 67 | - GoogleMapsRequestFields::INPUT => $query, |
|
| 68 | - GoogleMapsRequestFields::FIELDS => implode(',', $fields) |
|
| 69 | - ]); |
|
| 70 | - |
|
| 71 | - return $this->findPlace($params); |
|
| 72 | - |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Find Places requests |
|
| 77 | - * |
|
| 78 | - * @param array $params |
|
| 79 | - * GoogleMapsRequestFields::INPUT required |
|
| 80 | - * |
|
| 81 | - * @see https://developers.google.com/places/web-service/search#FindPlaceRequests |
|
| 82 | - * @return GoogleMapsResultsCollection |
|
| 83 | - * @throws InvalidArgumentException |
|
| 84 | - * @since 0.5.0 |
|
| 85 | - */ |
|
| 86 | - public function findPlace(array $params): GoogleMapsResultsCollection |
|
| 87 | - { |
|
| 88 | - |
|
| 89 | - // see \Biscolab\GoogleMaps\Values\PlaceInputTypeValues |
|
| 90 | - if (empty($params[GoogleMapsRequestFields::INPUTTYPE])) { |
|
| 91 | - $params[GoogleMapsRequestFields::INPUTTYPE] = PlaceInputTypeValues::TEXTQUERY; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - if (empty($params[GoogleMapsRequestFields::INPUT])) { |
|
| 95 | - throw new InvalidArgumentException(GoogleMapsRequestFields::INPUT . " field is required"); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - return $this->makeApiCall($params, PlaceServicesEndpoints::FINDPLACEFROMTEXT); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @param array $params |
|
| 103 | - * @param string $endpoint |
|
| 104 | - * |
|
| 105 | - * @return GoogleMapsResult|GoogleMapsResultsCollection |
|
| 106 | - * @since 0.5.0 |
|
| 107 | - */ |
|
| 108 | - public function makeApiCall(array $params, string $endpoint) |
|
| 109 | - { |
|
| 110 | - |
|
| 111 | - return $this->callApi($params, $endpoint); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * @param string $number |
|
| 116 | - * @param array|null $params |
|
| 117 | - * @param array|null $fields |
|
| 118 | - * |
|
| 119 | - * @return GoogleMapsResultsCollection |
|
| 120 | - */ |
|
| 121 | - public function findPlaceByPhoneNumber( |
|
| 122 | - string $number, |
|
| 123 | - ?array $params = [], |
|
| 124 | - ?array $fields = [] |
|
| 125 | - ): GoogleMapsResultsCollection { |
|
| 126 | - |
|
| 127 | - $params = array_merge($params, [ |
|
| 128 | - GoogleMapsRequestFields::INPUT => $number, |
|
| 129 | - GoogleMapsRequestFields::INPUTTYPE => PlaceInputTypeValues::PHONENUMBER, |
|
| 130 | - GoogleMapsRequestFields::FIELDS => implode(',', $fields) |
|
| 131 | - ]); |
|
| 132 | - |
|
| 133 | - return $this->findPlace($params); |
|
| 134 | - |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * @param Location $location |
|
| 139 | - * @param int $radius |
|
| 140 | - * @param array|null $params |
|
| 141 | - * |
|
| 142 | - * @return GoogleMapsResultsCollection |
|
| 143 | - */ |
|
| 144 | - public function findNearbyPlaceByRadius( |
|
| 145 | - Location $location, |
|
| 146 | - int $radius, |
|
| 147 | - ?array $params = [] |
|
| 148 | - ): GoogleMapsResultsCollection { |
|
| 149 | - |
|
| 150 | - $params = array_merge($params, [ |
|
| 151 | - GoogleMapsRequestFields::LOCATION => $location, |
|
| 152 | - GoogleMapsRequestFields::RADIUS => $radius |
|
| 153 | - ]); |
|
| 154 | - |
|
| 155 | - return $this->findNearbyPlace($params); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Nearby Search requests |
|
| 160 | - * |
|
| 161 | - * @param array $params |
|
| 162 | - * |
|
| 163 | - * @return GoogleMapsResultsCollection |
|
| 164 | - * |
|
| 165 | - * @throws InvalidArgumentException |
|
| 166 | - * @see https://developers.google.com/places/web-service/search#PlaceSearchRequests |
|
| 167 | - * @since 0.5.0 |
|
| 168 | - */ |
|
| 169 | - public function findNearbyPlace(array $params): GoogleMapsResultsCollection |
|
| 170 | - { |
|
| 171 | - |
|
| 172 | - if (!empty($params[GoogleMapsRequestFields::LOCATION])) {//-33.8670522,151.1957362 |
|
| 173 | - $location = $params[GoogleMapsRequestFields::LOCATION]; |
|
| 174 | - if (!$location instanceof Location) { |
|
| 175 | - throw new InvalidArgumentException(GoogleMapsRequestFields::LOCATION . ' field must be instance of ' . Location::class . ' class'); |
|
| 176 | - } |
|
| 177 | - $params[GoogleMapsRequestFields::LOCATION] = (string)$params[GoogleMapsRequestFields::LOCATION]; |
|
| 178 | - } else { |
|
| 179 | - throw new InvalidArgumentException(GoogleMapsResultFields::LOCATION . ' field is required'); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - if (!empty($params[GoogleMapsRequestFields::RANKBY]) && |
|
| 183 | - $params[GoogleMapsRequestFields::RANKBY] === RankByValues::DISTANCE |
|
| 184 | - ) { |
|
| 185 | - if (empty($params[GoogleMapsRequestFields::KEYWORD]) && |
|
| 186 | - empty($params[GoogleMapsRequestFields::NAME]) && |
|
| 187 | - empty($params[GoogleMapsRequestFields::TYPE])) { |
|
| 37 | + /** |
|
| 38 | + * @var string |
|
| 39 | + */ |
|
| 40 | + const SERVICE_ENDPOINT = 'place'; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @var string |
|
| 44 | + */ |
|
| 45 | + protected $result_type = PlacesResult::class; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @var string |
|
| 49 | + */ |
|
| 50 | + protected $result_collection_type = PlaceResultsCollection::class; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @param string $query |
|
| 54 | + * @param array|null $params |
|
| 55 | + * @param array|null $fields |
|
| 56 | + * |
|
| 57 | + * @return GoogleMapsResultsCollection |
|
| 58 | + * @see https://developers.google.com/places/web-service/search#FindPlaceRequests |
|
| 59 | + */ |
|
| 60 | + public function findPlaceByText( |
|
| 61 | + string $query, |
|
| 62 | + ?array $params = [], |
|
| 63 | + ?array $fields = [] |
|
| 64 | + ): GoogleMapsResultsCollection { |
|
| 65 | + |
|
| 66 | + $params = array_merge($params, [ |
|
| 67 | + GoogleMapsRequestFields::INPUT => $query, |
|
| 68 | + GoogleMapsRequestFields::FIELDS => implode(',', $fields) |
|
| 69 | + ]); |
|
| 70 | + |
|
| 71 | + return $this->findPlace($params); |
|
| 72 | + |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Find Places requests |
|
| 77 | + * |
|
| 78 | + * @param array $params |
|
| 79 | + * GoogleMapsRequestFields::INPUT required |
|
| 80 | + * |
|
| 81 | + * @see https://developers.google.com/places/web-service/search#FindPlaceRequests |
|
| 82 | + * @return GoogleMapsResultsCollection |
|
| 83 | + * @throws InvalidArgumentException |
|
| 84 | + * @since 0.5.0 |
|
| 85 | + */ |
|
| 86 | + public function findPlace(array $params): GoogleMapsResultsCollection |
|
| 87 | + { |
|
| 88 | + |
|
| 89 | + // see \Biscolab\GoogleMaps\Values\PlaceInputTypeValues |
|
| 90 | + if (empty($params[GoogleMapsRequestFields::INPUTTYPE])) { |
|
| 91 | + $params[GoogleMapsRequestFields::INPUTTYPE] = PlaceInputTypeValues::TEXTQUERY; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + if (empty($params[GoogleMapsRequestFields::INPUT])) { |
|
| 95 | + throw new InvalidArgumentException(GoogleMapsRequestFields::INPUT . " field is required"); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + return $this->makeApiCall($params, PlaceServicesEndpoints::FINDPLACEFROMTEXT); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @param array $params |
|
| 103 | + * @param string $endpoint |
|
| 104 | + * |
|
| 105 | + * @return GoogleMapsResult|GoogleMapsResultsCollection |
|
| 106 | + * @since 0.5.0 |
|
| 107 | + */ |
|
| 108 | + public function makeApiCall(array $params, string $endpoint) |
|
| 109 | + { |
|
| 110 | + |
|
| 111 | + return $this->callApi($params, $endpoint); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * @param string $number |
|
| 116 | + * @param array|null $params |
|
| 117 | + * @param array|null $fields |
|
| 118 | + * |
|
| 119 | + * @return GoogleMapsResultsCollection |
|
| 120 | + */ |
|
| 121 | + public function findPlaceByPhoneNumber( |
|
| 122 | + string $number, |
|
| 123 | + ?array $params = [], |
|
| 124 | + ?array $fields = [] |
|
| 125 | + ): GoogleMapsResultsCollection { |
|
| 126 | + |
|
| 127 | + $params = array_merge($params, [ |
|
| 128 | + GoogleMapsRequestFields::INPUT => $number, |
|
| 129 | + GoogleMapsRequestFields::INPUTTYPE => PlaceInputTypeValues::PHONENUMBER, |
|
| 130 | + GoogleMapsRequestFields::FIELDS => implode(',', $fields) |
|
| 131 | + ]); |
|
| 132 | + |
|
| 133 | + return $this->findPlace($params); |
|
| 134 | + |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * @param Location $location |
|
| 139 | + * @param int $radius |
|
| 140 | + * @param array|null $params |
|
| 141 | + * |
|
| 142 | + * @return GoogleMapsResultsCollection |
|
| 143 | + */ |
|
| 144 | + public function findNearbyPlaceByRadius( |
|
| 145 | + Location $location, |
|
| 146 | + int $radius, |
|
| 147 | + ?array $params = [] |
|
| 148 | + ): GoogleMapsResultsCollection { |
|
| 149 | + |
|
| 150 | + $params = array_merge($params, [ |
|
| 151 | + GoogleMapsRequestFields::LOCATION => $location, |
|
| 152 | + GoogleMapsRequestFields::RADIUS => $radius |
|
| 153 | + ]); |
|
| 154 | + |
|
| 155 | + return $this->findNearbyPlace($params); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Nearby Search requests |
|
| 160 | + * |
|
| 161 | + * @param array $params |
|
| 162 | + * |
|
| 163 | + * @return GoogleMapsResultsCollection |
|
| 164 | + * |
|
| 165 | + * @throws InvalidArgumentException |
|
| 166 | + * @see https://developers.google.com/places/web-service/search#PlaceSearchRequests |
|
| 167 | + * @since 0.5.0 |
|
| 168 | + */ |
|
| 169 | + public function findNearbyPlace(array $params): GoogleMapsResultsCollection |
|
| 170 | + { |
|
| 171 | + |
|
| 172 | + if (!empty($params[GoogleMapsRequestFields::LOCATION])) {//-33.8670522,151.1957362 |
|
| 173 | + $location = $params[GoogleMapsRequestFields::LOCATION]; |
|
| 174 | + if (!$location instanceof Location) { |
|
| 175 | + throw new InvalidArgumentException(GoogleMapsRequestFields::LOCATION . ' field must be instance of ' . Location::class . ' class'); |
|
| 176 | + } |
|
| 177 | + $params[GoogleMapsRequestFields::LOCATION] = (string)$params[GoogleMapsRequestFields::LOCATION]; |
|
| 178 | + } else { |
|
| 179 | + throw new InvalidArgumentException(GoogleMapsResultFields::LOCATION . ' field is required'); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + if (!empty($params[GoogleMapsRequestFields::RANKBY]) && |
|
| 183 | + $params[GoogleMapsRequestFields::RANKBY] === RankByValues::DISTANCE |
|
| 184 | + ) { |
|
| 185 | + if (empty($params[GoogleMapsRequestFields::KEYWORD]) && |
|
| 186 | + empty($params[GoogleMapsRequestFields::NAME]) && |
|
| 187 | + empty($params[GoogleMapsRequestFields::TYPE])) { |
|
| 188 | 188 | // If rankby=distance (described under Optional parameters below) is specified, |
| 189 | 189 | // then one or more of keyword, name, or type is required. |
| 190 | - throw new InvalidArgumentException('If ' . GoogleMapsRequestFields::RANKBY . ' is set as "' . RankByValues::DISTANCE . '" one or more of ' . GoogleMapsRequestFields::KEYWORD . ', ' . GoogleMapsRequestFields::NAME . ', ' . GoogleMapsRequestFields::TYPE . ' fields are required'); |
|
| 191 | - } |
|
| 192 | - if (!empty($params[GoogleMapsRequestFields::RADIUS])) { |
|
| 190 | + throw new InvalidArgumentException('If ' . GoogleMapsRequestFields::RANKBY . ' is set as "' . RankByValues::DISTANCE . '" one or more of ' . GoogleMapsRequestFields::KEYWORD . ', ' . GoogleMapsRequestFields::NAME . ', ' . GoogleMapsRequestFields::TYPE . ' fields are required'); |
|
| 191 | + } |
|
| 192 | + if (!empty($params[GoogleMapsRequestFields::RADIUS])) { |
|
| 193 | 193 | // Note that radius must not be included if rankby=distance (described under Optional parameters below) is specified. |
| 194 | - throw new InvalidArgumentException(GoogleMapsRequestFields::RADIUS . ' must not be included if ' . GoogleMapsRequestFields::RANKBY . ' = ' . RankByValues::DISTANCE); |
|
| 195 | - } |
|
| 196 | - } elseif (empty($params[GoogleMapsRequestFields::RADIUS])) { |
|
| 194 | + throw new InvalidArgumentException(GoogleMapsRequestFields::RADIUS . ' must not be included if ' . GoogleMapsRequestFields::RANKBY . ' = ' . RankByValues::DISTANCE); |
|
| 195 | + } |
|
| 196 | + } elseif (empty($params[GoogleMapsRequestFields::RADIUS])) { |
|
| 197 | 197 | // radius — Defines the distance (in meters) within which to return place results. |
| 198 | - throw new InvalidArgumentException(GoogleMapsRequestFields::RADIUS . ' field is required'); |
|
| 199 | - } |
|
| 198 | + throw new InvalidArgumentException(GoogleMapsRequestFields::RADIUS . ' field is required'); |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - if (!empty($params[GoogleMapsRequestFields::RADIUS]) && floatval($params[GoogleMapsRequestFields::RADIUS]) > Config::MAX_PLACE_RADIUS_VALUE) { |
|
| 201 | + if (!empty($params[GoogleMapsRequestFields::RADIUS]) && floatval($params[GoogleMapsRequestFields::RADIUS]) > Config::MAX_PLACE_RADIUS_VALUE) { |
|
| 202 | 202 | // The maximum allowed radius is 50 000 meters. |
| 203 | - throw new InvalidArgumentException(GoogleMapsRequestFields::RADIUS . ' must be lower than ' . Config::MAX_PLACE_RADIUS_VALUE); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - return $this->makeApiCall($params, PlaceServicesEndpoints::NEARBYSEARCH); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * @param Location $location |
|
| 211 | - * @param array $params |
|
| 212 | - * |
|
| 213 | - * @return GoogleMapsResultsCollection |
|
| 214 | - */ |
|
| 215 | - public function findNearbyPlaceByDistance(Location $location, array $params): GoogleMapsResultsCollection |
|
| 216 | - { |
|
| 217 | - |
|
| 218 | - $params = array_merge($params, [ |
|
| 219 | - GoogleMapsRequestFields::LOCATION => $location, |
|
| 220 | - GoogleMapsRequestFields::RANKBY => RankByValues::DISTANCE |
|
| 221 | - ]); |
|
| 222 | - |
|
| 223 | - return $this->findNearbyPlace($params); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * Nearby Search requests |
|
| 228 | - * |
|
| 229 | - * @param string $query |
|
| 230 | - * @param array|null $params |
|
| 231 | - * |
|
| 232 | - * @see https://developers.google.com/places/web-service/search#TextSearchRequests |
|
| 233 | - * @return GoogleMapsResultsCollection |
|
| 234 | - * @throws InvalidArgumentException |
|
| 235 | - * @since 0.5.0 |
|
| 236 | - */ |
|
| 237 | - public function textSearch(string $query, ?array $params = []): GoogleMapsResultsCollection |
|
| 238 | - { |
|
| 239 | - |
|
| 240 | - $params = array_merge($params, [ |
|
| 241 | - GoogleMapsRequestFields::QUERY => $query |
|
| 242 | - ]); |
|
| 243 | - |
|
| 244 | - return $this->makeApiCall($params, PlaceServicesEndpoints::TEXTSEARCH); |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * @param string $place_id |
|
| 249 | - * @param array|null $params |
|
| 250 | - * |
|
| 251 | - * @return GoogleMapsResult |
|
| 252 | - * @see https://developers.google.com/places/web-service/details |
|
| 253 | - * @since v0.6.0 |
|
| 254 | - */ |
|
| 255 | - public function details(string $place_id, ?array $params = []): GoogleMapsResult |
|
| 256 | - { |
|
| 257 | - |
|
| 258 | - $params = array_merge($params, [ |
|
| 259 | - GoogleMapsRequestFields::PLACE_ID => $place_id |
|
| 260 | - ]); |
|
| 261 | - |
|
| 262 | - return $this->makeApiCall($params, PlaceServicesEndpoints::DETAILS); |
|
| 263 | - |
|
| 264 | - } |
|
| 203 | + throw new InvalidArgumentException(GoogleMapsRequestFields::RADIUS . ' must be lower than ' . Config::MAX_PLACE_RADIUS_VALUE); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + return $this->makeApiCall($params, PlaceServicesEndpoints::NEARBYSEARCH); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * @param Location $location |
|
| 211 | + * @param array $params |
|
| 212 | + * |
|
| 213 | + * @return GoogleMapsResultsCollection |
|
| 214 | + */ |
|
| 215 | + public function findNearbyPlaceByDistance(Location $location, array $params): GoogleMapsResultsCollection |
|
| 216 | + { |
|
| 217 | + |
|
| 218 | + $params = array_merge($params, [ |
|
| 219 | + GoogleMapsRequestFields::LOCATION => $location, |
|
| 220 | + GoogleMapsRequestFields::RANKBY => RankByValues::DISTANCE |
|
| 221 | + ]); |
|
| 222 | + |
|
| 223 | + return $this->findNearbyPlace($params); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * Nearby Search requests |
|
| 228 | + * |
|
| 229 | + * @param string $query |
|
| 230 | + * @param array|null $params |
|
| 231 | + * |
|
| 232 | + * @see https://developers.google.com/places/web-service/search#TextSearchRequests |
|
| 233 | + * @return GoogleMapsResultsCollection |
|
| 234 | + * @throws InvalidArgumentException |
|
| 235 | + * @since 0.5.0 |
|
| 236 | + */ |
|
| 237 | + public function textSearch(string $query, ?array $params = []): GoogleMapsResultsCollection |
|
| 238 | + { |
|
| 239 | + |
|
| 240 | + $params = array_merge($params, [ |
|
| 241 | + GoogleMapsRequestFields::QUERY => $query |
|
| 242 | + ]); |
|
| 243 | + |
|
| 244 | + return $this->makeApiCall($params, PlaceServicesEndpoints::TEXTSEARCH); |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * @param string $place_id |
|
| 249 | + * @param array|null $params |
|
| 250 | + * |
|
| 251 | + * @return GoogleMapsResult |
|
| 252 | + * @see https://developers.google.com/places/web-service/details |
|
| 253 | + * @since v0.6.0 |
|
| 254 | + */ |
|
| 255 | + public function details(string $place_id, ?array $params = []): GoogleMapsResult |
|
| 256 | + { |
|
| 257 | + |
|
| 258 | + $params = array_merge($params, [ |
|
| 259 | + GoogleMapsRequestFields::PLACE_ID => $place_id |
|
| 260 | + ]); |
|
| 261 | + |
|
| 262 | + return $this->makeApiCall($params, PlaceServicesEndpoints::DETAILS); |
|
| 263 | + |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | 266 | } |
| 267 | 267 | \ No newline at end of file |
@@ -25,53 +25,53 @@ |
||
| 25 | 25 | class Geocoding extends Api |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var string |
|
| 30 | - */ |
|
| 31 | - const SERVICE_ENDPOINT = 'geocode'; |
|
| 28 | + /** |
|
| 29 | + * @var string |
|
| 30 | + */ |
|
| 31 | + const SERVICE_ENDPOINT = 'geocode'; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @var string |
|
| 35 | - */ |
|
| 36 | - protected $result_collection_type = GeocodingResultsCollection::class; |
|
| 33 | + /** |
|
| 34 | + * @var string |
|
| 35 | + */ |
|
| 36 | + protected $result_collection_type = GeocodingResultsCollection::class; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @param string $literal_address |
|
| 40 | - * |
|
| 41 | - * @return GoogleMapsResultsCollection |
|
| 42 | - */ |
|
| 43 | - public function getByAddress(string $literal_address): GoogleMapsResultsCollection |
|
| 44 | - { |
|
| 38 | + /** |
|
| 39 | + * @param string $literal_address |
|
| 40 | + * |
|
| 41 | + * @return GoogleMapsResultsCollection |
|
| 42 | + */ |
|
| 43 | + public function getByAddress(string $literal_address): GoogleMapsResultsCollection |
|
| 44 | + { |
|
| 45 | 45 | |
| 46 | - return $this->callApi([ |
|
| 47 | - GoogleMapsRequestFields::ADDRESS => $literal_address |
|
| 48 | - ]); |
|
| 49 | - } |
|
| 46 | + return $this->callApi([ |
|
| 47 | + GoogleMapsRequestFields::ADDRESS => $literal_address |
|
| 48 | + ]); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @param LatLng $latlng |
|
| 53 | - * |
|
| 54 | - * @return GoogleMapsResultsCollection |
|
| 55 | - */ |
|
| 56 | - public function getReverse(LatLng $latlng): GoogleMapsResultsCollection |
|
| 57 | - { |
|
| 51 | + /** |
|
| 52 | + * @param LatLng $latlng |
|
| 53 | + * |
|
| 54 | + * @return GoogleMapsResultsCollection |
|
| 55 | + */ |
|
| 56 | + public function getReverse(LatLng $latlng): GoogleMapsResultsCollection |
|
| 57 | + { |
|
| 58 | 58 | |
| 59 | - return $this->callApi([ |
|
| 60 | - GoogleMapsRequestFields::LATLNG => $latlng |
|
| 61 | - ]); |
|
| 62 | - } |
|
| 59 | + return $this->callApi([ |
|
| 60 | + GoogleMapsRequestFields::LATLNG => $latlng |
|
| 61 | + ]); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @param string $place_id |
|
| 66 | - * |
|
| 67 | - * @return GoogleMapsResultsCollection |
|
| 68 | - */ |
|
| 69 | - public function getByPlaceId(string $place_id): GoogleMapsResultsCollection |
|
| 70 | - { |
|
| 64 | + /** |
|
| 65 | + * @param string $place_id |
|
| 66 | + * |
|
| 67 | + * @return GoogleMapsResultsCollection |
|
| 68 | + */ |
|
| 69 | + public function getByPlaceId(string $place_id): GoogleMapsResultsCollection |
|
| 70 | + { |
|
| 71 | 71 | |
| 72 | - return $this->callApi([ |
|
| 73 | - GoogleMapsRequestFields::PLACE_ID => $place_id |
|
| 74 | - ]); |
|
| 75 | - } |
|
| 72 | + return $this->callApi([ |
|
| 73 | + GoogleMapsRequestFields::PLACE_ID => $place_id |
|
| 74 | + ]); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | 77 | } |
| 78 | 78 | \ No newline at end of file |
@@ -23,341 +23,341 @@ |
||
| 23 | 23 | class GoogleMapsResponse |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var Response |
|
| 28 | - */ |
|
| 29 | - protected $response = null; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Single result |
|
| 33 | - * When the Places service returns results from a details request, it places them within a single result |
|
| 34 | - * |
|
| 35 | - * @var array |
|
| 36 | - * @see https://developers.google.com/places/web-service/details#PlaceDetailsResults |
|
| 37 | - */ |
|
| 38 | - protected $result = null; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * contains an array of places, with information about each. |
|
| 42 | - * The Places API returns up to 20 establishment results per query. |
|
| 43 | - * Additionally, political results may be returned which serve to identify the area of the request. |
|
| 44 | - * |
|
| 45 | - * @var array |
|
| 46 | - * @see https://developers.google.com/places/web-service/search#PlaceSearchResults |
|
| 47 | - */ |
|
| 48 | - protected $results = null; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * contains metadata on the request. |
|
| 52 | - * |
|
| 53 | - * @var string |
|
| 54 | - * @see https://developers.google.com/places/web-service/search#PlaceSearchStatusCodes |
|
| 55 | - */ |
|
| 56 | - protected $status = null; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @var string |
|
| 60 | - */ |
|
| 61 | - protected $error_message = null; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @var array |
|
| 65 | - */ |
|
| 66 | - protected $array_response = null; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @var null|array |
|
| 70 | - */ |
|
| 71 | - protected $http_status_code = null; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * may contain a set of attributions about this listing which must be displayed to the user (some listings may not have attribution). |
|
| 75 | - * |
|
| 76 | - * @var null|array |
|
| 77 | - * @since 0.5.0 |
|
| 78 | - */ |
|
| 79 | - protected $html_attributions = null; |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @var null|string |
|
| 83 | - * @since 0.5.0 |
|
| 84 | - */ |
|
| 85 | - protected $next_page_token = null; |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * GoogleMapsResponse constructor. |
|
| 89 | - * |
|
| 90 | - * @param Response $response |
|
| 91 | - */ |
|
| 92 | - public function __construct(Response $response) |
|
| 93 | - { |
|
| 94 | - |
|
| 95 | - $this->setResponse($response); |
|
| 96 | - |
|
| 97 | - $this->parseResponse(); |
|
| 98 | - |
|
| 99 | - $this->checkHttpStatusCode(); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @param Response $response |
|
| 104 | - * |
|
| 105 | - * @return GoogleMapsResponse |
|
| 106 | - */ |
|
| 107 | - public function setResponse(Response $response): GoogleMapsResponse |
|
| 108 | - { |
|
| 109 | - |
|
| 110 | - $this->response = $response; |
|
| 111 | - |
|
| 112 | - return $this; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @return GoogleMapsResponse |
|
| 117 | - * |
|
| 118 | - * @throws RequestException |
|
| 119 | - * @throws ResponseException |
|
| 120 | - */ |
|
| 121 | - protected function parseResponse(): GoogleMapsResponse |
|
| 122 | - { |
|
| 123 | - |
|
| 124 | - $json_response = $this->response->getBody()->getContents(); |
|
| 125 | - $array_response = $this->toArray($json_response); |
|
| 126 | - $result = null; |
|
| 127 | - $results = null; |
|
| 128 | - |
|
| 129 | - if (empty($array_response[GoogleMapsResponseFields::STATUS])) { |
|
| 130 | - throw new ResponseException('Missing "status" in GoogleMapsApi Response'); |
|
| 131 | - } |
|
| 132 | - $this->setStatus($array_response[GoogleMapsResponseFields::STATUS]); |
|
| 133 | - |
|
| 134 | - if ($this->getStatus() != GoogleMapsResponseStatusValues::OK) { |
|
| 135 | - $error_message = 'Something went wrong'; |
|
| 136 | - if (!empty($array_response[GoogleMapsResponseFields::ERROR_MESSAGE])) { |
|
| 137 | - $error_message = $array_response[GoogleMapsResponseFields::ERROR_MESSAGE]; |
|
| 138 | - $this->setErrorMessage($error_message); |
|
| 139 | - } elseif (!empty($array_response[GoogleMapsResponseFields::STATUS])) { |
|
| 140 | - $error_message .= ': ' . $array_response[GoogleMapsResponseFields::STATUS]; |
|
| 141 | - $this->setErrorMessage($error_message); |
|
| 142 | - } |
|
| 143 | - throw new RequestException($error_message); |
|
| 144 | - |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - if (!empty($array_response[GoogleMapsResponseFields::RESULTS])) { |
|
| 148 | - $results = $array_response[GoogleMapsResponseFields::RESULTS]; |
|
| 149 | - |
|
| 150 | - } elseif (!empty($array_response[GoogleMapsResponseFields::CANDIDATES])) { |
|
| 151 | - $results = $array_response[GoogleMapsResponseFields::CANDIDATES]; |
|
| 152 | - |
|
| 153 | - }elseif (!empty($array_response[GoogleMapsResponseFields::RESULT])) { |
|
| 154 | - $result = $array_response[GoogleMapsResponseFields::RESULT]; |
|
| 155 | - |
|
| 156 | - } else { |
|
| 157 | - throw new ResponseException('Missing "results" in GoogleMapsApi Response'); |
|
| 158 | - } |
|
| 159 | - $this->setResult($result); |
|
| 160 | - $this->setResults($results); |
|
| 161 | - |
|
| 162 | - if (!empty($array_response[GoogleMapsResponseFields::HTML_ATTRIBUTIONS])) { |
|
| 163 | - $this->setHtmlAttributions($array_response[GoogleMapsResponseFields::HTML_ATTRIBUTIONS]); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - if (!empty($array_response[GoogleMapsResponseFields::NEXT_PAGE_TOKEN])) { |
|
| 167 | - $this->setNextPageToken($array_response[GoogleMapsResponseFields::NEXT_PAGE_TOKEN]); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - return $this; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * @param string $json_response |
|
| 175 | - * |
|
| 176 | - * @return array |
|
| 177 | - */ |
|
| 178 | - public function toArray(string $json_response): array |
|
| 179 | - { |
|
| 180 | - |
|
| 181 | - $this->array_response = json_decode($json_response, true); |
|
| 182 | - |
|
| 183 | - return $this->array_response; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * @return string |
|
| 188 | - */ |
|
| 189 | - public function getStatus(): string |
|
| 190 | - { |
|
| 191 | - |
|
| 192 | - return $this->status; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * @param string $status |
|
| 197 | - * |
|
| 198 | - * @return GoogleMapsResponse |
|
| 199 | - */ |
|
| 200 | - public function setStatus(string $status) |
|
| 201 | - { |
|
| 202 | - |
|
| 203 | - $this->status = $status; |
|
| 204 | - |
|
| 205 | - return $this; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * Check HTTP status code (silent/No exceptions!) |
|
| 210 | - * @return int |
|
| 211 | - */ |
|
| 212 | - protected function checkHttpStatusCode(): int |
|
| 213 | - { |
|
| 214 | - |
|
| 215 | - $this->http_status_code = $this->response->getStatusCode(); |
|
| 216 | - |
|
| 217 | - return $this->http_status_code; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * @return array |
|
| 222 | - */ |
|
| 223 | - public function getResults() |
|
| 224 | - { |
|
| 225 | - |
|
| 226 | - return $this->results; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * @param array $results |
|
| 231 | - * |
|
| 232 | - * @return $this |
|
| 233 | - */ |
|
| 234 | - public function setResults(?array $results) |
|
| 235 | - { |
|
| 236 | - |
|
| 237 | - $this->results = $results; |
|
| 238 | - |
|
| 239 | - return $this; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * @return array |
|
| 244 | - * @since v0.6.0 |
|
| 245 | - */ |
|
| 246 | - public function getResult() |
|
| 247 | - { |
|
| 248 | - |
|
| 249 | - return $this->result; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * @param array $result |
|
| 254 | - * |
|
| 255 | - * @return $this |
|
| 256 | - * @since v0.6.0 |
|
| 257 | - */ |
|
| 258 | - public function setResult(?array $result) |
|
| 259 | - { |
|
| 260 | - |
|
| 261 | - $this->result = $result; |
|
| 262 | - |
|
| 263 | - return $this; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * @return array |
|
| 268 | - */ |
|
| 269 | - public function getArrayResponse(): array |
|
| 270 | - { |
|
| 271 | - |
|
| 272 | - return $this->array_response; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * @param array $array_response |
|
| 277 | - * |
|
| 278 | - * @return GoogleMapsResponse |
|
| 279 | - */ |
|
| 280 | - public function setArrayResponse(array $array_response): GoogleMapsResponse |
|
| 281 | - { |
|
| 282 | - |
|
| 283 | - $this->array_response = $array_response; |
|
| 284 | - |
|
| 285 | - return $this; |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * @return mixed |
|
| 290 | - */ |
|
| 291 | - public function getErrorMessage() |
|
| 292 | - { |
|
| 293 | - |
|
| 294 | - return $this->error_message; |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - /** |
|
| 298 | - * @param $error_message |
|
| 299 | - * |
|
| 300 | - * @return GoogleMapsResponse |
|
| 301 | - */ |
|
| 302 | - public function setErrorMessage($error_message): GoogleMapsResponse |
|
| 303 | - { |
|
| 304 | - |
|
| 305 | - $this->error_message = $error_message; |
|
| 306 | - |
|
| 307 | - return $this; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * @return int |
|
| 312 | - */ |
|
| 313 | - public function getHttpStatusCode(): int |
|
| 314 | - { |
|
| 315 | - |
|
| 316 | - return intval($this->http_status_code); |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * @return array|null |
|
| 321 | - */ |
|
| 322 | - public function getHtmlAttributions(): ?array |
|
| 323 | - { |
|
| 324 | - |
|
| 325 | - return $this->html_attributions; |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * @param array|null $html_attributions |
|
| 330 | - * |
|
| 331 | - * @return GoogleMapsResponse |
|
| 332 | - */ |
|
| 333 | - public function setHtmlAttributions(?array $html_attributions): GoogleMapsResponse |
|
| 334 | - { |
|
| 335 | - |
|
| 336 | - $this->html_attributions = $html_attributions; |
|
| 337 | - |
|
| 338 | - return $this; |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * @return string |
|
| 343 | - */ |
|
| 344 | - public function getNextPageToken(): string |
|
| 345 | - { |
|
| 346 | - |
|
| 347 | - return $this->next_page_token ?? ''; |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * @param $next_page_token |
|
| 352 | - * |
|
| 353 | - * @return GoogleMapsResponse |
|
| 354 | - */ |
|
| 355 | - public function setNextPageToken($next_page_token): GoogleMapsResponse |
|
| 356 | - { |
|
| 357 | - |
|
| 358 | - $this->next_page_token = $next_page_token; |
|
| 359 | - |
|
| 360 | - return $this; |
|
| 361 | - } |
|
| 26 | + /** |
|
| 27 | + * @var Response |
|
| 28 | + */ |
|
| 29 | + protected $response = null; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Single result |
|
| 33 | + * When the Places service returns results from a details request, it places them within a single result |
|
| 34 | + * |
|
| 35 | + * @var array |
|
| 36 | + * @see https://developers.google.com/places/web-service/details#PlaceDetailsResults |
|
| 37 | + */ |
|
| 38 | + protected $result = null; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * contains an array of places, with information about each. |
|
| 42 | + * The Places API returns up to 20 establishment results per query. |
|
| 43 | + * Additionally, political results may be returned which serve to identify the area of the request. |
|
| 44 | + * |
|
| 45 | + * @var array |
|
| 46 | + * @see https://developers.google.com/places/web-service/search#PlaceSearchResults |
|
| 47 | + */ |
|
| 48 | + protected $results = null; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * contains metadata on the request. |
|
| 52 | + * |
|
| 53 | + * @var string |
|
| 54 | + * @see https://developers.google.com/places/web-service/search#PlaceSearchStatusCodes |
|
| 55 | + */ |
|
| 56 | + protected $status = null; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @var string |
|
| 60 | + */ |
|
| 61 | + protected $error_message = null; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @var array |
|
| 65 | + */ |
|
| 66 | + protected $array_response = null; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @var null|array |
|
| 70 | + */ |
|
| 71 | + protected $http_status_code = null; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * may contain a set of attributions about this listing which must be displayed to the user (some listings may not have attribution). |
|
| 75 | + * |
|
| 76 | + * @var null|array |
|
| 77 | + * @since 0.5.0 |
|
| 78 | + */ |
|
| 79 | + protected $html_attributions = null; |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @var null|string |
|
| 83 | + * @since 0.5.0 |
|
| 84 | + */ |
|
| 85 | + protected $next_page_token = null; |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * GoogleMapsResponse constructor. |
|
| 89 | + * |
|
| 90 | + * @param Response $response |
|
| 91 | + */ |
|
| 92 | + public function __construct(Response $response) |
|
| 93 | + { |
|
| 94 | + |
|
| 95 | + $this->setResponse($response); |
|
| 96 | + |
|
| 97 | + $this->parseResponse(); |
|
| 98 | + |
|
| 99 | + $this->checkHttpStatusCode(); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @param Response $response |
|
| 104 | + * |
|
| 105 | + * @return GoogleMapsResponse |
|
| 106 | + */ |
|
| 107 | + public function setResponse(Response $response): GoogleMapsResponse |
|
| 108 | + { |
|
| 109 | + |
|
| 110 | + $this->response = $response; |
|
| 111 | + |
|
| 112 | + return $this; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @return GoogleMapsResponse |
|
| 117 | + * |
|
| 118 | + * @throws RequestException |
|
| 119 | + * @throws ResponseException |
|
| 120 | + */ |
|
| 121 | + protected function parseResponse(): GoogleMapsResponse |
|
| 122 | + { |
|
| 123 | + |
|
| 124 | + $json_response = $this->response->getBody()->getContents(); |
|
| 125 | + $array_response = $this->toArray($json_response); |
|
| 126 | + $result = null; |
|
| 127 | + $results = null; |
|
| 128 | + |
|
| 129 | + if (empty($array_response[GoogleMapsResponseFields::STATUS])) { |
|
| 130 | + throw new ResponseException('Missing "status" in GoogleMapsApi Response'); |
|
| 131 | + } |
|
| 132 | + $this->setStatus($array_response[GoogleMapsResponseFields::STATUS]); |
|
| 133 | + |
|
| 134 | + if ($this->getStatus() != GoogleMapsResponseStatusValues::OK) { |
|
| 135 | + $error_message = 'Something went wrong'; |
|
| 136 | + if (!empty($array_response[GoogleMapsResponseFields::ERROR_MESSAGE])) { |
|
| 137 | + $error_message = $array_response[GoogleMapsResponseFields::ERROR_MESSAGE]; |
|
| 138 | + $this->setErrorMessage($error_message); |
|
| 139 | + } elseif (!empty($array_response[GoogleMapsResponseFields::STATUS])) { |
|
| 140 | + $error_message .= ': ' . $array_response[GoogleMapsResponseFields::STATUS]; |
|
| 141 | + $this->setErrorMessage($error_message); |
|
| 142 | + } |
|
| 143 | + throw new RequestException($error_message); |
|
| 144 | + |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + if (!empty($array_response[GoogleMapsResponseFields::RESULTS])) { |
|
| 148 | + $results = $array_response[GoogleMapsResponseFields::RESULTS]; |
|
| 149 | + |
|
| 150 | + } elseif (!empty($array_response[GoogleMapsResponseFields::CANDIDATES])) { |
|
| 151 | + $results = $array_response[GoogleMapsResponseFields::CANDIDATES]; |
|
| 152 | + |
|
| 153 | + }elseif (!empty($array_response[GoogleMapsResponseFields::RESULT])) { |
|
| 154 | + $result = $array_response[GoogleMapsResponseFields::RESULT]; |
|
| 155 | + |
|
| 156 | + } else { |
|
| 157 | + throw new ResponseException('Missing "results" in GoogleMapsApi Response'); |
|
| 158 | + } |
|
| 159 | + $this->setResult($result); |
|
| 160 | + $this->setResults($results); |
|
| 161 | + |
|
| 162 | + if (!empty($array_response[GoogleMapsResponseFields::HTML_ATTRIBUTIONS])) { |
|
| 163 | + $this->setHtmlAttributions($array_response[GoogleMapsResponseFields::HTML_ATTRIBUTIONS]); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + if (!empty($array_response[GoogleMapsResponseFields::NEXT_PAGE_TOKEN])) { |
|
| 167 | + $this->setNextPageToken($array_response[GoogleMapsResponseFields::NEXT_PAGE_TOKEN]); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + return $this; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * @param string $json_response |
|
| 175 | + * |
|
| 176 | + * @return array |
|
| 177 | + */ |
|
| 178 | + public function toArray(string $json_response): array |
|
| 179 | + { |
|
| 180 | + |
|
| 181 | + $this->array_response = json_decode($json_response, true); |
|
| 182 | + |
|
| 183 | + return $this->array_response; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * @return string |
|
| 188 | + */ |
|
| 189 | + public function getStatus(): string |
|
| 190 | + { |
|
| 191 | + |
|
| 192 | + return $this->status; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * @param string $status |
|
| 197 | + * |
|
| 198 | + * @return GoogleMapsResponse |
|
| 199 | + */ |
|
| 200 | + public function setStatus(string $status) |
|
| 201 | + { |
|
| 202 | + |
|
| 203 | + $this->status = $status; |
|
| 204 | + |
|
| 205 | + return $this; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * Check HTTP status code (silent/No exceptions!) |
|
| 210 | + * @return int |
|
| 211 | + */ |
|
| 212 | + protected function checkHttpStatusCode(): int |
|
| 213 | + { |
|
| 214 | + |
|
| 215 | + $this->http_status_code = $this->response->getStatusCode(); |
|
| 216 | + |
|
| 217 | + return $this->http_status_code; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * @return array |
|
| 222 | + */ |
|
| 223 | + public function getResults() |
|
| 224 | + { |
|
| 225 | + |
|
| 226 | + return $this->results; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * @param array $results |
|
| 231 | + * |
|
| 232 | + * @return $this |
|
| 233 | + */ |
|
| 234 | + public function setResults(?array $results) |
|
| 235 | + { |
|
| 236 | + |
|
| 237 | + $this->results = $results; |
|
| 238 | + |
|
| 239 | + return $this; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * @return array |
|
| 244 | + * @since v0.6.0 |
|
| 245 | + */ |
|
| 246 | + public function getResult() |
|
| 247 | + { |
|
| 248 | + |
|
| 249 | + return $this->result; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * @param array $result |
|
| 254 | + * |
|
| 255 | + * @return $this |
|
| 256 | + * @since v0.6.0 |
|
| 257 | + */ |
|
| 258 | + public function setResult(?array $result) |
|
| 259 | + { |
|
| 260 | + |
|
| 261 | + $this->result = $result; |
|
| 262 | + |
|
| 263 | + return $this; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * @return array |
|
| 268 | + */ |
|
| 269 | + public function getArrayResponse(): array |
|
| 270 | + { |
|
| 271 | + |
|
| 272 | + return $this->array_response; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * @param array $array_response |
|
| 277 | + * |
|
| 278 | + * @return GoogleMapsResponse |
|
| 279 | + */ |
|
| 280 | + public function setArrayResponse(array $array_response): GoogleMapsResponse |
|
| 281 | + { |
|
| 282 | + |
|
| 283 | + $this->array_response = $array_response; |
|
| 284 | + |
|
| 285 | + return $this; |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * @return mixed |
|
| 290 | + */ |
|
| 291 | + public function getErrorMessage() |
|
| 292 | + { |
|
| 293 | + |
|
| 294 | + return $this->error_message; |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + /** |
|
| 298 | + * @param $error_message |
|
| 299 | + * |
|
| 300 | + * @return GoogleMapsResponse |
|
| 301 | + */ |
|
| 302 | + public function setErrorMessage($error_message): GoogleMapsResponse |
|
| 303 | + { |
|
| 304 | + |
|
| 305 | + $this->error_message = $error_message; |
|
| 306 | + |
|
| 307 | + return $this; |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * @return int |
|
| 312 | + */ |
|
| 313 | + public function getHttpStatusCode(): int |
|
| 314 | + { |
|
| 315 | + |
|
| 316 | + return intval($this->http_status_code); |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * @return array|null |
|
| 321 | + */ |
|
| 322 | + public function getHtmlAttributions(): ?array |
|
| 323 | + { |
|
| 324 | + |
|
| 325 | + return $this->html_attributions; |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * @param array|null $html_attributions |
|
| 330 | + * |
|
| 331 | + * @return GoogleMapsResponse |
|
| 332 | + */ |
|
| 333 | + public function setHtmlAttributions(?array $html_attributions): GoogleMapsResponse |
|
| 334 | + { |
|
| 335 | + |
|
| 336 | + $this->html_attributions = $html_attributions; |
|
| 337 | + |
|
| 338 | + return $this; |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * @return string |
|
| 343 | + */ |
|
| 344 | + public function getNextPageToken(): string |
|
| 345 | + { |
|
| 346 | + |
|
| 347 | + return $this->next_page_token ?? ''; |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * @param $next_page_token |
|
| 352 | + * |
|
| 353 | + * @return GoogleMapsResponse |
|
| 354 | + */ |
|
| 355 | + public function setNextPageToken($next_page_token): GoogleMapsResponse |
|
| 356 | + { |
|
| 357 | + |
|
| 358 | + $this->next_page_token = $next_page_token; |
|
| 359 | + |
|
| 360 | + return $this; |
|
| 361 | + } |
|
| 362 | 362 | |
| 363 | 363 | } |
| 364 | 364 | \ No newline at end of file |
@@ -150,7 +150,7 @@ |
||
| 150 | 150 | } elseif (!empty($array_response[GoogleMapsResponseFields::CANDIDATES])) { |
| 151 | 151 | $results = $array_response[GoogleMapsResponseFields::CANDIDATES]; |
| 152 | 152 | |
| 153 | - }elseif (!empty($array_response[GoogleMapsResponseFields::RESULT])) { |
|
| 153 | + } elseif (!empty($array_response[GoogleMapsResponseFields::RESULT])) { |
|
| 154 | 154 | $result = $array_response[GoogleMapsResponseFields::RESULT]; |
| 155 | 155 | |
| 156 | 156 | } else { |
@@ -38,135 +38,135 @@ |
||
| 38 | 38 | class PlacesResult extends GoogleMapsResult |
| 39 | 39 | { |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @var null|string |
|
| 43 | - */ |
|
| 44 | - protected $formatted_address = null; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var string |
|
| 48 | - */ |
|
| 49 | - protected $name = ''; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @var Geometry |
|
| 53 | - */ |
|
| 54 | - protected $geometry = null; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @var string |
|
| 58 | - */ |
|
| 59 | - protected $icon = ''; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @var string |
|
| 63 | - */ |
|
| 64 | - protected $id = ''; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @var PhotoCollection |
|
| 68 | - */ |
|
| 69 | - protected $photos = null; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @var string |
|
| 73 | - */ |
|
| 74 | - protected $place_id = ''; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @var string |
|
| 78 | - */ |
|
| 79 | - protected $reference = ''; |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @var string |
|
| 83 | - */ |
|
| 84 | - protected $vicinity = ''; |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * @var array |
|
| 88 | - */ |
|
| 89 | - protected $types = []; |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @var array |
|
| 93 | - */ |
|
| 94 | - protected $opening_hours = []; |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * @var int |
|
| 98 | - */ |
|
| 99 | - protected $price_level = 0; |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @var bool |
|
| 103 | - */ |
|
| 104 | - protected $permanently_closed = false; |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * @var ReviewCollection |
|
| 108 | - */ |
|
| 109 | - protected $reviews = null; |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * @var int |
|
| 113 | - */ |
|
| 114 | - protected $utc_offset = 0; |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * @var string |
|
| 118 | - */ |
|
| 119 | - protected $website = ''; |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * @var string |
|
| 123 | - */ |
|
| 124 | - protected $international_phone_number = ''; |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * @var string |
|
| 128 | - */ |
|
| 129 | - protected $formatted_phone_number = ''; |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * @var string |
|
| 133 | - */ |
|
| 134 | - protected $adr_address = ''; |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * @var array |
|
| 138 | - */ |
|
| 139 | - protected $typeCheck = [ |
|
| 140 | - GoogleMapsResultFields::FORMATTED_ADDRESS => 'string', |
|
| 141 | - GoogleMapsResultFields::NAME => 'string', |
|
| 142 | - GoogleMapsResultFields::GEOMETRY => Geometry::class, |
|
| 143 | - GoogleMapsResultFields::ICON => 'string', |
|
| 144 | - GoogleMapsResultFields::ID => 'string', |
|
| 145 | - GoogleMapsResultFields::PHOTOS => PhotoCollection::class, |
|
| 146 | - GoogleMapsResultFields::PLACE_ID => 'string', |
|
| 147 | - GoogleMapsResultFields::REFERENCE => 'string', |
|
| 148 | - GoogleMapsResultFields::VICINITY => 'string', |
|
| 149 | - GoogleMapsResultFields::TYPES => 'array', |
|
| 150 | - GoogleMapsResultFields::OPENING_HOURS => 'json', |
|
| 151 | - GoogleMapsResultFields::PRICE_LEVEL => 'int', |
|
| 152 | - GoogleMapsResultFields::RATING => 'float', |
|
| 153 | - GoogleMapsResultFields::PERMANENTLY_CLOSED => 'bool', |
|
| 154 | - GoogleMapsResultFields::PLUS_CODE => 'array', |
|
| 155 | - GoogleMapsResultFields::REVIEWS => ReviewCollection::class, |
|
| 156 | - GoogleMapsResultFields::UTC_OFFSET => 'int', |
|
| 157 | - GoogleMapsResultFields::WEBSITE => 'string', |
|
| 158 | - GoogleMapsResultFields::INTERNATIONAL_PHONE_NUMBER => 'string', |
|
| 159 | - GoogleMapsResultFields::FORMATTED_PHONE_NUMBER => 'string', |
|
| 160 | - GoogleMapsResultFields::ADR_ADDRESS => 'string', |
|
| 161 | - ]; |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * @return bool|null |
|
| 165 | - */ |
|
| 166 | - public function getPermanentlyClose(): bool |
|
| 167 | - { |
|
| 168 | - |
|
| 169 | - return $this->permanently_closed ?? false; |
|
| 170 | - } |
|
| 41 | + /** |
|
| 42 | + * @var null|string |
|
| 43 | + */ |
|
| 44 | + protected $formatted_address = null; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var string |
|
| 48 | + */ |
|
| 49 | + protected $name = ''; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @var Geometry |
|
| 53 | + */ |
|
| 54 | + protected $geometry = null; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @var string |
|
| 58 | + */ |
|
| 59 | + protected $icon = ''; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @var string |
|
| 63 | + */ |
|
| 64 | + protected $id = ''; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @var PhotoCollection |
|
| 68 | + */ |
|
| 69 | + protected $photos = null; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @var string |
|
| 73 | + */ |
|
| 74 | + protected $place_id = ''; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @var string |
|
| 78 | + */ |
|
| 79 | + protected $reference = ''; |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @var string |
|
| 83 | + */ |
|
| 84 | + protected $vicinity = ''; |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @var array |
|
| 88 | + */ |
|
| 89 | + protected $types = []; |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @var array |
|
| 93 | + */ |
|
| 94 | + protected $opening_hours = []; |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @var int |
|
| 98 | + */ |
|
| 99 | + protected $price_level = 0; |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @var bool |
|
| 103 | + */ |
|
| 104 | + protected $permanently_closed = false; |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * @var ReviewCollection |
|
| 108 | + */ |
|
| 109 | + protected $reviews = null; |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * @var int |
|
| 113 | + */ |
|
| 114 | + protected $utc_offset = 0; |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * @var string |
|
| 118 | + */ |
|
| 119 | + protected $website = ''; |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * @var string |
|
| 123 | + */ |
|
| 124 | + protected $international_phone_number = ''; |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * @var string |
|
| 128 | + */ |
|
| 129 | + protected $formatted_phone_number = ''; |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * @var string |
|
| 133 | + */ |
|
| 134 | + protected $adr_address = ''; |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * @var array |
|
| 138 | + */ |
|
| 139 | + protected $typeCheck = [ |
|
| 140 | + GoogleMapsResultFields::FORMATTED_ADDRESS => 'string', |
|
| 141 | + GoogleMapsResultFields::NAME => 'string', |
|
| 142 | + GoogleMapsResultFields::GEOMETRY => Geometry::class, |
|
| 143 | + GoogleMapsResultFields::ICON => 'string', |
|
| 144 | + GoogleMapsResultFields::ID => 'string', |
|
| 145 | + GoogleMapsResultFields::PHOTOS => PhotoCollection::class, |
|
| 146 | + GoogleMapsResultFields::PLACE_ID => 'string', |
|
| 147 | + GoogleMapsResultFields::REFERENCE => 'string', |
|
| 148 | + GoogleMapsResultFields::VICINITY => 'string', |
|
| 149 | + GoogleMapsResultFields::TYPES => 'array', |
|
| 150 | + GoogleMapsResultFields::OPENING_HOURS => 'json', |
|
| 151 | + GoogleMapsResultFields::PRICE_LEVEL => 'int', |
|
| 152 | + GoogleMapsResultFields::RATING => 'float', |
|
| 153 | + GoogleMapsResultFields::PERMANENTLY_CLOSED => 'bool', |
|
| 154 | + GoogleMapsResultFields::PLUS_CODE => 'array', |
|
| 155 | + GoogleMapsResultFields::REVIEWS => ReviewCollection::class, |
|
| 156 | + GoogleMapsResultFields::UTC_OFFSET => 'int', |
|
| 157 | + GoogleMapsResultFields::WEBSITE => 'string', |
|
| 158 | + GoogleMapsResultFields::INTERNATIONAL_PHONE_NUMBER => 'string', |
|
| 159 | + GoogleMapsResultFields::FORMATTED_PHONE_NUMBER => 'string', |
|
| 160 | + GoogleMapsResultFields::ADR_ADDRESS => 'string', |
|
| 161 | + ]; |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * @return bool|null |
|
| 165 | + */ |
|
| 166 | + public function getPermanentlyClose(): bool |
|
| 167 | + { |
|
| 168 | + |
|
| 169 | + return $this->permanently_closed ?? false; |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | 172 | } |
| 173 | 173 | \ No newline at end of file |
@@ -17,43 +17,43 @@ |
||
| 17 | 17 | class GoogleMapsResponseFields |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @var string results |
|
| 22 | - */ |
|
| 23 | - const RESULTS = 'results'; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @var string result |
|
| 27 | - * @since v0.6.0 |
|
| 28 | - */ |
|
| 29 | - const RESULT = 'result'; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var string status |
|
| 33 | - */ |
|
| 34 | - const STATUS = 'status'; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var string error_message |
|
| 38 | - */ |
|
| 39 | - const ERROR_MESSAGE = 'error_message'; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @var string candidates |
|
| 43 | - * @since 0.5.0 |
|
| 44 | - */ |
|
| 45 | - const CANDIDATES = 'candidates'; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @var string html_attributions |
|
| 49 | - * @since 0.5.0 |
|
| 50 | - */ |
|
| 51 | - const HTML_ATTRIBUTIONS = 'html_attributions'; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @var string next_page_token |
|
| 55 | - * @since 0.5.0 |
|
| 56 | - */ |
|
| 57 | - const NEXT_PAGE_TOKEN = 'next_page_token'; |
|
| 20 | + /** |
|
| 21 | + * @var string results |
|
| 22 | + */ |
|
| 23 | + const RESULTS = 'results'; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @var string result |
|
| 27 | + * @since v0.6.0 |
|
| 28 | + */ |
|
| 29 | + const RESULT = 'result'; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var string status |
|
| 33 | + */ |
|
| 34 | + const STATUS = 'status'; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var string error_message |
|
| 38 | + */ |
|
| 39 | + const ERROR_MESSAGE = 'error_message'; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @var string candidates |
|
| 43 | + * @since 0.5.0 |
|
| 44 | + */ |
|
| 45 | + const CANDIDATES = 'candidates'; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @var string html_attributions |
|
| 49 | + * @since 0.5.0 |
|
| 50 | + */ |
|
| 51 | + const HTML_ATTRIBUTIONS = 'html_attributions'; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @var string next_page_token |
|
| 55 | + * @since 0.5.0 |
|
| 56 | + */ |
|
| 57 | + const NEXT_PAGE_TOKEN = 'next_page_token'; |
|
| 58 | 58 | |
| 59 | 59 | } |
| 60 | 60 | \ No newline at end of file |