@@ -16,19 +16,19 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class AddressComponentFields { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * string: long_name |
|
| 21 | - */ |
|
| 22 | - const LONG_NAME = 'long_name'; |
|
| 19 | + /** |
|
| 20 | + * string: long_name |
|
| 21 | + */ |
|
| 22 | + const LONG_NAME = 'long_name'; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * string: short_name |
|
| 26 | - */ |
|
| 27 | - const SHORT_NAME = 'short_name'; |
|
| 24 | + /** |
|
| 25 | + * string: short_name |
|
| 26 | + */ |
|
| 27 | + const SHORT_NAME = 'short_name'; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * string: types |
|
| 31 | - */ |
|
| 32 | - const TYPES = 'types'; |
|
| 29 | + /** |
|
| 30 | + * string: types |
|
| 31 | + */ |
|
| 32 | + const TYPES = 'types'; |
|
| 33 | 33 | |
| 34 | 34 | } |
| 35 | 35 | \ No newline at end of file |
@@ -16,19 +16,19 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class GoogleMapsResponseFields { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * string: results |
|
| 21 | - */ |
|
| 22 | - const RESULTS = 'results'; |
|
| 19 | + /** |
|
| 20 | + * string: results |
|
| 21 | + */ |
|
| 22 | + const RESULTS = 'results'; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * string: status |
|
| 26 | - */ |
|
| 27 | - const STATUS = 'status'; |
|
| 24 | + /** |
|
| 25 | + * string: status |
|
| 26 | + */ |
|
| 27 | + const STATUS = 'status'; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * string: error_message |
|
| 31 | - */ |
|
| 32 | - const ERROR_MESSAGE = 'error_message'; |
|
| 29 | + /** |
|
| 30 | + * string: error_message |
|
| 31 | + */ |
|
| 32 | + const ERROR_MESSAGE = 'error_message'; |
|
| 33 | 33 | |
| 34 | 34 | } |
| 35 | 35 | \ No newline at end of file |
@@ -16,13 +16,13 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class LatLngFields { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * string - latitude |
|
| 21 | - */ |
|
| 22 | - const LAT = 'lat'; |
|
| 19 | + /** |
|
| 20 | + * string - latitude |
|
| 21 | + */ |
|
| 22 | + const LAT = 'lat'; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * string - longitude |
|
| 26 | - */ |
|
| 27 | - const LNG = 'lng'; |
|
| 24 | + /** |
|
| 25 | + * string - longitude |
|
| 26 | + */ |
|
| 27 | + const LNG = 'lng'; |
|
| 28 | 28 | } |
| 29 | 29 | \ No newline at end of file |
@@ -21,93 +21,93 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | abstract class Api { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @var string |
|
| 26 | - */ |
|
| 27 | - const SERVICE_ENDPOINT = null; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @var GoogleMapsApi |
|
| 31 | - */ |
|
| 32 | - protected $google_maps_api = null; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @var string |
|
| 36 | - */ |
|
| 37 | - protected $result_collection = ''; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Api constructor. |
|
| 41 | - * |
|
| 42 | - * @param array $config |
|
| 43 | - */ |
|
| 44 | - public function __construct(array $config = []) { |
|
| 45 | - |
|
| 46 | - $service_config = $this->getServiceConfig($config); |
|
| 47 | - $this->setGoogleMapsApi(new GoogleMapsApi($service_config)); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @param array $config |
|
| 52 | - * |
|
| 53 | - * @return array |
|
| 54 | - */ |
|
| 55 | - protected function getServiceConfig(array $config = []): array { |
|
| 56 | - |
|
| 57 | - return array_merge($config, [ |
|
| 58 | - GoogleMapsApiConfigFields::SERVICE_ENDPOINT => $this->getServiceEndpoint() |
|
| 59 | - ]); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @return string |
|
| 64 | - */ |
|
| 65 | - public function getServiceEndpoint(): string { |
|
| 66 | - |
|
| 67 | - return static::SERVICE_ENDPOINT; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @return GoogleMapsApi |
|
| 72 | - */ |
|
| 73 | - public function getGoogleMapsApi(): GoogleMapsApi { |
|
| 74 | - |
|
| 75 | - return $this->google_maps_api; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @param GoogleMapsApi $google_maps_api |
|
| 80 | - * |
|
| 81 | - * @return Api |
|
| 82 | - */ |
|
| 83 | - public function setGoogleMapsApi(GoogleMapsApi $google_maps_api): Api { |
|
| 84 | - |
|
| 85 | - $this->google_maps_api = $google_maps_api; |
|
| 86 | - |
|
| 87 | - return $this; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @param array $params |
|
| 92 | - * |
|
| 93 | - * @return mixed |
|
| 94 | - */ |
|
| 95 | - public function createRequest(array $params): GoogleMapsRequest { |
|
| 96 | - |
|
| 97 | - return new GoogleMapsRequest($params); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * @param GoogleMapsRequest $request |
|
| 102 | - * |
|
| 103 | - * @return GoogleMapsResultsCollection |
|
| 104 | - */ |
|
| 105 | - public function getResultsCollections(GoogleMapsRequest $request): GoogleMapsResultsCollection { |
|
| 106 | - |
|
| 107 | - $results = $this->getGoogleMapsApi()->get($request)->getResults(); |
|
| 108 | - |
|
| 109 | - $result_collection_class = $this->result_collection; |
|
| 110 | - |
|
| 111 | - return new $result_collection_class($results); |
|
| 112 | - } |
|
| 24 | + /** |
|
| 25 | + * @var string |
|
| 26 | + */ |
|
| 27 | + const SERVICE_ENDPOINT = null; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @var GoogleMapsApi |
|
| 31 | + */ |
|
| 32 | + protected $google_maps_api = null; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @var string |
|
| 36 | + */ |
|
| 37 | + protected $result_collection = ''; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Api constructor. |
|
| 41 | + * |
|
| 42 | + * @param array $config |
|
| 43 | + */ |
|
| 44 | + public function __construct(array $config = []) { |
|
| 45 | + |
|
| 46 | + $service_config = $this->getServiceConfig($config); |
|
| 47 | + $this->setGoogleMapsApi(new GoogleMapsApi($service_config)); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @param array $config |
|
| 52 | + * |
|
| 53 | + * @return array |
|
| 54 | + */ |
|
| 55 | + protected function getServiceConfig(array $config = []): array { |
|
| 56 | + |
|
| 57 | + return array_merge($config, [ |
|
| 58 | + GoogleMapsApiConfigFields::SERVICE_ENDPOINT => $this->getServiceEndpoint() |
|
| 59 | + ]); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @return string |
|
| 64 | + */ |
|
| 65 | + public function getServiceEndpoint(): string { |
|
| 66 | + |
|
| 67 | + return static::SERVICE_ENDPOINT; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @return GoogleMapsApi |
|
| 72 | + */ |
|
| 73 | + public function getGoogleMapsApi(): GoogleMapsApi { |
|
| 74 | + |
|
| 75 | + return $this->google_maps_api; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @param GoogleMapsApi $google_maps_api |
|
| 80 | + * |
|
| 81 | + * @return Api |
|
| 82 | + */ |
|
| 83 | + public function setGoogleMapsApi(GoogleMapsApi $google_maps_api): Api { |
|
| 84 | + |
|
| 85 | + $this->google_maps_api = $google_maps_api; |
|
| 86 | + |
|
| 87 | + return $this; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @param array $params |
|
| 92 | + * |
|
| 93 | + * @return mixed |
|
| 94 | + */ |
|
| 95 | + public function createRequest(array $params): GoogleMapsRequest { |
|
| 96 | + |
|
| 97 | + return new GoogleMapsRequest($params); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * @param GoogleMapsRequest $request |
|
| 102 | + * |
|
| 103 | + * @return GoogleMapsResultsCollection |
|
| 104 | + */ |
|
| 105 | + public function getResultsCollections(GoogleMapsRequest $request): GoogleMapsResultsCollection { |
|
| 106 | + |
|
| 107 | + $results = $this->getGoogleMapsApi()->get($request)->getResults(); |
|
| 108 | + |
|
| 109 | + $result_collection_class = $this->result_collection; |
|
| 110 | + |
|
| 111 | + return new $result_collection_class($results); |
|
| 112 | + } |
|
| 113 | 113 | } |
| 114 | 114 | \ No newline at end of file |
@@ -18,20 +18,20 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class GoogleMapsResultsCollection extends AbstractCollection { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - protected $item_class = GoogleMapsResult::class; |
|
| 21 | + /** |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + protected $item_class = GoogleMapsResult::class; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @param $item |
|
| 28 | - * |
|
| 29 | - * @return GeocodingResult |
|
| 30 | - */ |
|
| 31 | - protected function parseItem($item) { |
|
| 26 | + /** |
|
| 27 | + * @param $item |
|
| 28 | + * |
|
| 29 | + * @return GeocodingResult |
|
| 30 | + */ |
|
| 31 | + protected function parseItem($item) { |
|
| 32 | 32 | |
| 33 | - $item_class = $this->item_class; |
|
| 33 | + $item_class = $this->item_class; |
|
| 34 | 34 | |
| 35 | - return new $item_class($item); |
|
| 36 | - } |
|
| 35 | + return new $item_class($item); |
|
| 36 | + } |
|
| 37 | 37 | } |
| 38 | 38 | \ No newline at end of file |
@@ -29,28 +29,28 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | class ElevationResult extends GoogleMapsResult { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @var float |
|
| 34 | - */ |
|
| 35 | - protected $elevation = null; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @var Location |
|
| 39 | - */ |
|
| 40 | - protected $location = null; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @var float |
|
| 44 | - */ |
|
| 45 | - protected $resolution = null; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @var array |
|
| 49 | - */ |
|
| 50 | - protected $typeCheck = [ |
|
| 51 | - GoogleMapsResultFields::LOCATION => Location::class, |
|
| 52 | - GoogleMapsResultFields::ELEVATION => 'float', |
|
| 53 | - GoogleMapsResultFields::RESOLUTION => 'float', |
|
| 54 | - ]; |
|
| 32 | + /** |
|
| 33 | + * @var float |
|
| 34 | + */ |
|
| 35 | + protected $elevation = null; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @var Location |
|
| 39 | + */ |
|
| 40 | + protected $location = null; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @var float |
|
| 44 | + */ |
|
| 45 | + protected $resolution = null; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @var array |
|
| 49 | + */ |
|
| 50 | + protected $typeCheck = [ |
|
| 51 | + GoogleMapsResultFields::LOCATION => Location::class, |
|
| 52 | + GoogleMapsResultFields::ELEVATION => 'float', |
|
| 53 | + GoogleMapsResultFields::RESOLUTION => 'float', |
|
| 54 | + ]; |
|
| 55 | 55 | |
| 56 | 56 | } |
| 57 | 57 | \ No newline at end of file |
@@ -20,8 +20,8 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class ElevationResultsCollection extends GoogleMapsResultsCollection { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @var string |
|
| 25 | - */ |
|
| 26 | - protected $item_class = ElevationResult::class; |
|
| 23 | + /** |
|
| 24 | + * @var string |
|
| 25 | + */ |
|
| 26 | + protected $item_class = ElevationResult::class; |
|
| 27 | 27 | } |
| 28 | 28 | \ No newline at end of file |
@@ -18,8 +18,8 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class GeocodingResultsCollection extends GoogleMapsResultsCollection { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - protected $item_class = GeocodingResult::class; |
|
| 21 | + /** |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + protected $item_class = GeocodingResult::class; |
|
| 25 | 25 | } |
| 26 | 26 | \ No newline at end of file |
@@ -25,54 +25,54 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | class Elevation extends Api { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var string |
|
| 30 | - */ |
|
| 31 | - const SERVICE_ENDPOINT = 'elevation'; |
|
| 28 | + /** |
|
| 29 | + * @var string |
|
| 30 | + */ |
|
| 31 | + const SERVICE_ENDPOINT = 'elevation'; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @var string |
|
| 35 | - */ |
|
| 36 | - protected $result_collection = ElevationResultsCollection::class; |
|
| 33 | + /** |
|
| 34 | + * @var string |
|
| 35 | + */ |
|
| 36 | + protected $result_collection = ElevationResultsCollection::class; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Positional Requests |
|
| 40 | - * |
|
| 41 | - * @param LatLng|string|array $locations |
|
| 42 | - * This parameter takes either a single location or multiple locations passed as an array or as an encoded polyline |
|
| 43 | - * |
|
| 44 | - * @since 0.3.0 |
|
| 45 | - * |
|
| 46 | - * @return GoogleMapsResultsCollection |
|
| 47 | - */ |
|
| 48 | - public function getByLocations($locations): GoogleMapsResultsCollection { |
|
| 38 | + /** |
|
| 39 | + * Positional Requests |
|
| 40 | + * |
|
| 41 | + * @param LatLng|string|array $locations |
|
| 42 | + * This parameter takes either a single location or multiple locations passed as an array or as an encoded polyline |
|
| 43 | + * |
|
| 44 | + * @since 0.3.0 |
|
| 45 | + * |
|
| 46 | + * @return GoogleMapsResultsCollection |
|
| 47 | + */ |
|
| 48 | + public function getByLocations($locations): GoogleMapsResultsCollection { |
|
| 49 | 49 | |
| 50 | - $locations = $this->parseLocations($locations); |
|
| 50 | + $locations = $this->parseLocations($locations); |
|
| 51 | 51 | |
| 52 | - $request = $this->createRequest([ |
|
| 53 | - GoogleMapsRequestFields::LOCATIONS => $locations |
|
| 54 | - ]); |
|
| 52 | + $request = $this->createRequest([ |
|
| 53 | + GoogleMapsRequestFields::LOCATIONS => $locations |
|
| 54 | + ]); |
|
| 55 | 55 | |
| 56 | - return $this->getResultsCollections($request); |
|
| 57 | - } |
|
| 56 | + return $this->getResultsCollections($request); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @param $locations |
|
| 61 | - * |
|
| 62 | - * @since 0.3.0 |
|
| 63 | - * |
|
| 64 | - * @return string |
|
| 65 | - */ |
|
| 66 | - public function parseLocations($locations): string { |
|
| 59 | + /** |
|
| 60 | + * @param $locations |
|
| 61 | + * |
|
| 62 | + * @since 0.3.0 |
|
| 63 | + * |
|
| 64 | + * @return string |
|
| 65 | + */ |
|
| 66 | + public function parseLocations($locations): string { |
|
| 67 | 67 | |
| 68 | - if (is_array($locations)) { |
|
| 69 | - $locations = implode('|', array_map(function ($item) { |
|
| 68 | + if (is_array($locations)) { |
|
| 69 | + $locations = implode('|', array_map(function ($item) { |
|
| 70 | 70 | |
| 71 | - return (string)$item; |
|
| 72 | - }, $locations)); |
|
| 73 | - } |
|
| 71 | + return (string)$item; |
|
| 72 | + }, $locations)); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - return (string)$locations; |
|
| 76 | - } |
|
| 75 | + return (string)$locations; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | 78 | } |
| 79 | 79 | \ No newline at end of file |
@@ -66,13 +66,13 @@ |
||
| 66 | 66 | public function parseLocations($locations): string { |
| 67 | 67 | |
| 68 | 68 | if (is_array($locations)) { |
| 69 | - $locations = implode('|', array_map(function ($item) { |
|
| 69 | + $locations = implode('|', array_map(function($item) { |
|
| 70 | 70 | |
| 71 | - return (string)$item; |
|
| 71 | + return (string) $item; |
|
| 72 | 72 | }, $locations)); |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - return (string)$locations; |
|
| 75 | + return (string) $locations; |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | } |
| 79 | 79 | \ No newline at end of file |