@@ -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 |
@@ -25,56 +25,56 @@ |
||
25 | 25 | */ |
26 | 26 | class Geocoding extends Api { |
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 = GeocodingResultsCollection::class; |
|
33 | + /** |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + protected $result_collection = GeocodingResultsCollection::class; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @param string $literal_address |
|
40 | - * |
|
41 | - * @return GoogleMapsResultsCollection |
|
42 | - */ |
|
43 | - public function getByAddress(string $literal_address): GoogleMapsResultsCollection { |
|
38 | + /** |
|
39 | + * @param string $literal_address |
|
40 | + * |
|
41 | + * @return GoogleMapsResultsCollection |
|
42 | + */ |
|
43 | + public function getByAddress(string $literal_address): GoogleMapsResultsCollection { |
|
44 | 44 | |
45 | - $request = new GoogleMapsRequest([ |
|
46 | - GoogleMapsRequestFields::ADDRESS => $literal_address |
|
47 | - ]); |
|
45 | + $request = new GoogleMapsRequest([ |
|
46 | + GoogleMapsRequestFields::ADDRESS => $literal_address |
|
47 | + ]); |
|
48 | 48 | |
49 | - return $this->getResultsCollections($request); |
|
50 | - } |
|
49 | + return $this->getResultsCollections($request); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @param LatLng $latlng |
|
54 | - * |
|
55 | - * @return GoogleMapsResultsCollection |
|
56 | - */ |
|
57 | - public function getReverse(LatLng $latlng): GoogleMapsResultsCollection { |
|
52 | + /** |
|
53 | + * @param LatLng $latlng |
|
54 | + * |
|
55 | + * @return GoogleMapsResultsCollection |
|
56 | + */ |
|
57 | + public function getReverse(LatLng $latlng): GoogleMapsResultsCollection { |
|
58 | 58 | |
59 | - $request = $this->createRequest([ |
|
60 | - GoogleMapsRequestFields::LATLNG => $latlng |
|
61 | - ]); |
|
59 | + $request = $this->createRequest([ |
|
60 | + GoogleMapsRequestFields::LATLNG => $latlng |
|
61 | + ]); |
|
62 | 62 | |
63 | - return $this->getResultsCollections($request); |
|
64 | - } |
|
63 | + return $this->getResultsCollections($request); |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @param string $place_id |
|
68 | - * |
|
69 | - * @return GoogleMapsResultsCollection |
|
70 | - */ |
|
71 | - public function getByPlaceId(string $place_id): GoogleMapsResultsCollection { |
|
66 | + /** |
|
67 | + * @param string $place_id |
|
68 | + * |
|
69 | + * @return GoogleMapsResultsCollection |
|
70 | + */ |
|
71 | + public function getByPlaceId(string $place_id): GoogleMapsResultsCollection { |
|
72 | 72 | |
73 | - $request = $this->createRequest([ |
|
74 | - GoogleMapsRequestFields::PLACE_ID => $place_id |
|
75 | - ]); |
|
73 | + $request = $this->createRequest([ |
|
74 | + GoogleMapsRequestFields::PLACE_ID => $place_id |
|
75 | + ]); |
|
76 | 76 | |
77 | - return $this->getResultsCollections($request); |
|
78 | - } |
|
77 | + return $this->getResultsCollections($request); |
|
78 | + } |
|
79 | 79 | |
80 | 80 | } |
81 | 81 | \ No newline at end of file |
@@ -16,33 +16,33 @@ |
||
16 | 16 | */ |
17 | 17 | class GoogleMapsRequestFields { |
18 | 18 | |
19 | - /** |
|
20 | - * string: key |
|
21 | - */ |
|
22 | - const KEY = 'key'; |
|
23 | - |
|
24 | - /** |
|
25 | - * string: sensor |
|
26 | - */ |
|
27 | - const SENSOR = 'sensor'; |
|
28 | - |
|
29 | - /** |
|
30 | - * string: latlng |
|
31 | - */ |
|
32 | - const LATLNG = 'latlng'; |
|
33 | - |
|
34 | - /** |
|
35 | - * string: address |
|
36 | - */ |
|
37 | - const ADDRESS = 'address'; |
|
38 | - |
|
39 | - /** |
|
40 | - * string: place_id |
|
41 | - */ |
|
42 | - const PLACE_ID = 'place_id'; |
|
43 | - |
|
44 | - /** |
|
45 | - * string: locations |
|
46 | - */ |
|
47 | - const LOCATIONS = 'locations'; |
|
19 | + /** |
|
20 | + * string: key |
|
21 | + */ |
|
22 | + const KEY = 'key'; |
|
23 | + |
|
24 | + /** |
|
25 | + * string: sensor |
|
26 | + */ |
|
27 | + const SENSOR = 'sensor'; |
|
28 | + |
|
29 | + /** |
|
30 | + * string: latlng |
|
31 | + */ |
|
32 | + const LATLNG = 'latlng'; |
|
33 | + |
|
34 | + /** |
|
35 | + * string: address |
|
36 | + */ |
|
37 | + const ADDRESS = 'address'; |
|
38 | + |
|
39 | + /** |
|
40 | + * string: place_id |
|
41 | + */ |
|
42 | + const PLACE_ID = 'place_id'; |
|
43 | + |
|
44 | + /** |
|
45 | + * string: locations |
|
46 | + */ |
|
47 | + const LOCATIONS = 'locations'; |
|
48 | 48 | } |
49 | 49 | \ No newline at end of file |
@@ -16,54 +16,54 @@ |
||
16 | 16 | */ |
17 | 17 | class GoogleMapsResultFields { |
18 | 18 | |
19 | - /** |
|
20 | - * string address_components |
|
21 | - */ |
|
22 | - const ADDRESS_COMPONENTS = 'address_components'; |
|
19 | + /** |
|
20 | + * string address_components |
|
21 | + */ |
|
22 | + const ADDRESS_COMPONENTS = 'address_components'; |
|
23 | 23 | |
24 | - /** |
|
25 | - * string formatted_address |
|
26 | - */ |
|
27 | - const FORMATTED_ADDRESS = 'formatted_address'; |
|
24 | + /** |
|
25 | + * string formatted_address |
|
26 | + */ |
|
27 | + const FORMATTED_ADDRESS = 'formatted_address'; |
|
28 | 28 | |
29 | - /** |
|
30 | - * string geometry |
|
31 | - */ |
|
32 | - const GEOMETRY = 'geometry'; |
|
29 | + /** |
|
30 | + * string geometry |
|
31 | + */ |
|
32 | + const GEOMETRY = 'geometry'; |
|
33 | 33 | |
34 | - /** |
|
35 | - * string viewport |
|
36 | - */ |
|
37 | - const VIEWPORT = 'viewport'; |
|
34 | + /** |
|
35 | + * string viewport |
|
36 | + */ |
|
37 | + const VIEWPORT = 'viewport'; |
|
38 | 38 | |
39 | - /** |
|
40 | - * string place_id |
|
41 | - */ |
|
42 | - const PLACE_ID = 'place_id'; |
|
39 | + /** |
|
40 | + * string place_id |
|
41 | + */ |
|
42 | + const PLACE_ID = 'place_id'; |
|
43 | 43 | |
44 | - /** |
|
45 | - * string location_type |
|
46 | - */ |
|
47 | - const LOCATION_TYPE = 'location_type'; |
|
44 | + /** |
|
45 | + * string location_type |
|
46 | + */ |
|
47 | + const LOCATION_TYPE = 'location_type'; |
|
48 | 48 | |
49 | - /** |
|
50 | - * string types |
|
51 | - */ |
|
52 | - const TYPES = 'types'; |
|
49 | + /** |
|
50 | + * string types |
|
51 | + */ |
|
52 | + const TYPES = 'types'; |
|
53 | 53 | |
54 | - /** |
|
55 | - * string location |
|
56 | - */ |
|
57 | - const LOCATION = 'location'; |
|
54 | + /** |
|
55 | + * string location |
|
56 | + */ |
|
57 | + const LOCATION = 'location'; |
|
58 | 58 | |
59 | - /** |
|
60 | - * string elevation |
|
61 | - */ |
|
62 | - const ELEVATION = 'elevation'; |
|
59 | + /** |
|
60 | + * string elevation |
|
61 | + */ |
|
62 | + const ELEVATION = 'elevation'; |
|
63 | 63 | |
64 | - /** |
|
65 | - * string resolution |
|
66 | - */ |
|
67 | - const RESOLUTION = 'resolution'; |
|
64 | + /** |
|
65 | + * string resolution |
|
66 | + */ |
|
67 | + const RESOLUTION = 'resolution'; |
|
68 | 68 | |
69 | 69 | } |
70 | 70 | \ No newline at end of file |