@@ -15,238 +15,238 @@ |
||
15 | 15 | */ |
16 | 16 | class Query implements QueryInterface |
17 | 17 | { |
18 | - /** |
|
19 | - * Contain the path of the request |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - protected $path; |
|
23 | - |
|
24 | - /** |
|
25 | - * Contain the query for request |
|
26 | - * @var array |
|
27 | - */ |
|
28 | - protected $query = []; |
|
29 | - |
|
30 | - /** |
|
31 | - * Contain the format for decode data returning by the request |
|
32 | - * @var string |
|
33 | - */ |
|
34 | - protected $format; |
|
35 | - |
|
36 | - /** |
|
37 | - * Output format accepted |
|
38 | - * @var array |
|
39 | - */ |
|
40 | - protected $accepteFormat = ['xml', 'json']; |
|
41 | - |
|
42 | - /** |
|
43 | - * Output polygon format accepted |
|
44 | - * @var array |
|
45 | - */ |
|
46 | - protected $polygon = ['geojson', 'kml', 'svg', 'text']; |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * Constuctor |
|
51 | - * @param array $query Default value for this query |
|
52 | - */ |
|
53 | - public function __construct(array $query = []) |
|
54 | - { |
|
55 | - if (!isset($query['format'])) |
|
56 | - { |
|
57 | - //Default format |
|
58 | - $query['format'] = 'json'; |
|
59 | - } |
|
60 | - |
|
61 | - $this->setQuery($query); |
|
62 | - $this->setFormat($query['format']); |
|
63 | - |
|
64 | - } |
|
65 | - |
|
66 | - // -- Builder methods ------------------------------------------------------ |
|
67 | - |
|
68 | - /** |
|
69 | - * Format returning by the request. |
|
70 | - * |
|
71 | - * @param string $format The output format for the request |
|
72 | - * |
|
73 | - * @return maxh\Nominatim\Query |
|
74 | - * @throws maxh\Nominatim\Exceptions\InvalidParameterException if format is not supported |
|
75 | - */ |
|
76 | - public function format($format) |
|
77 | - { |
|
78 | - $format = strtolower($format); |
|
79 | - |
|
80 | - if (in_array($format, $this->accepteFormat)) |
|
81 | - { |
|
82 | - $this->setFormat($format); |
|
83 | - |
|
84 | - return $this; |
|
85 | - } |
|
86 | - |
|
87 | - throw new InvalidParameterException("Format is not supported"); |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Preferred language order for showing search results, overrides the value |
|
92 | - * specified in the "Accept-Language" HTTP header. Either uses standard |
|
93 | - * rfc2616 accept-language string or a simple comma separated list of |
|
94 | - * language codes. |
|
95 | - * |
|
96 | - * @param string $language Preferred language order for showing search results, overrides the value specified in the "Accept-Language" HTTP header. |
|
97 | - * Either uses standard rfc2616 accept-language string or a simple comma separated list of language codes. |
|
98 | - * |
|
99 | - * @return maxh\Nominatim\Query |
|
100 | - */ |
|
101 | - public function language($language) |
|
102 | - { |
|
103 | - $this->query['accept-language'] = $language; |
|
104 | - |
|
105 | - return $this; |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Include a breakdown of the address into elements. |
|
110 | - * |
|
111 | - * @param boolean $details |
|
112 | - * |
|
113 | - * @return maxh\Nominatim\Query |
|
114 | - */ |
|
115 | - public function addressDetails($details = true) |
|
116 | - { |
|
117 | - $this->query['addressdetails'] = $details ? "1" : "0"; |
|
118 | - |
|
119 | - return $this; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * If you are making large numbers of request please include a valid email address or alternatively include your email address as part of the User-Agent string. |
|
124 | - * This information will be kept confidential and only used to contact you in the event of a problem, see Usage Policy for more details. |
|
125 | - * |
|
126 | - * @param string $email Address mail |
|
127 | - * |
|
128 | - * @return maxh\Nominatim\Query |
|
129 | - */ |
|
130 | - public function email($email) |
|
131 | - { |
|
132 | - $this->query['email'] = $email; |
|
133 | - |
|
134 | - return $this; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Output format for the geometry of results |
|
139 | - * |
|
140 | - * @param string $polygon |
|
141 | - * |
|
142 | - * @return maxh\Nominatim\Query |
|
143 | - * @throws maxh\Nominatim\Exceptions\InvalidParameterException if polygon format is not supported |
|
144 | - */ |
|
145 | - public function polygon($polygon) |
|
146 | - { |
|
147 | - if (in_array($polygon, $this->polygon)) |
|
148 | - { |
|
149 | - $this->query['polygon_' . $polygon] = "1"; |
|
150 | - |
|
151 | - return $this; |
|
152 | - } |
|
153 | - |
|
154 | - throw new InvalidParameterException("This polygon format is not supported"); |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * Include additional information in the result if available |
|
159 | - * |
|
160 | - * @param boolean $tags |
|
161 | - * |
|
162 | - * @return maxh\Nominatim\Query |
|
163 | - */ |
|
164 | - public function extraTags($tags = true) |
|
165 | - { |
|
166 | - $this->query['extratags'] = $tags ? "1" : "0"; |
|
167 | - |
|
168 | - return $this; |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * Include a list of alternative names in the results. |
|
173 | - * These may include language variants, references, operator and brand. |
|
174 | - * |
|
175 | - * @param boolean $details |
|
176 | - * |
|
177 | - * @return maxh\Nominatim\Query |
|
178 | - */ |
|
179 | - public function nameDetails($details = true) |
|
180 | - { |
|
181 | - $this->query['namedetails'] = $details ? "1" : "0"; |
|
182 | - |
|
183 | - return $this; |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Returns the URL-encoded query. |
|
188 | - * |
|
189 | - * @return string |
|
190 | - */ |
|
191 | - public function getQueryString() |
|
192 | - { |
|
193 | - return http_build_query($this->query); |
|
194 | - } |
|
195 | - |
|
196 | - // -- Getters & Setters ---------------------------------------------------- |
|
197 | - |
|
198 | - /** |
|
199 | - * Get path |
|
200 | - * @return string |
|
201 | - */ |
|
202 | - public function getPath() |
|
203 | - { |
|
204 | - return $this->path; |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Get query |
|
209 | - * @return array |
|
210 | - */ |
|
211 | - public function getQuery() |
|
212 | - { |
|
213 | - return $this->query; |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * Get format |
|
218 | - * @return string |
|
219 | - */ |
|
220 | - public function getFormat() |
|
221 | - { |
|
222 | - return $this->format; |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * Set path |
|
227 | - * @param string $path Name's path of the service |
|
228 | - */ |
|
229 | - protected function setPath($path) |
|
230 | - { |
|
231 | - $this->path = $path; |
|
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * Set query |
|
236 | - * @param array $query Parameter of the query |
|
237 | - */ |
|
238 | - protected function setQuery($query = array()) |
|
239 | - { |
|
240 | - $this->query = $query; |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * Set format |
|
245 | - * @param string $format Format returning by the response |
|
246 | - */ |
|
247 | - protected function setFormat($format) |
|
248 | - { |
|
249 | - $this->format = $this->query['format'] = $format; |
|
250 | - } |
|
18 | + /** |
|
19 | + * Contain the path of the request |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + protected $path; |
|
23 | + |
|
24 | + /** |
|
25 | + * Contain the query for request |
|
26 | + * @var array |
|
27 | + */ |
|
28 | + protected $query = []; |
|
29 | + |
|
30 | + /** |
|
31 | + * Contain the format for decode data returning by the request |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + protected $format; |
|
35 | + |
|
36 | + /** |
|
37 | + * Output format accepted |
|
38 | + * @var array |
|
39 | + */ |
|
40 | + protected $accepteFormat = ['xml', 'json']; |
|
41 | + |
|
42 | + /** |
|
43 | + * Output polygon format accepted |
|
44 | + * @var array |
|
45 | + */ |
|
46 | + protected $polygon = ['geojson', 'kml', 'svg', 'text']; |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * Constuctor |
|
51 | + * @param array $query Default value for this query |
|
52 | + */ |
|
53 | + public function __construct(array $query = []) |
|
54 | + { |
|
55 | + if (!isset($query['format'])) |
|
56 | + { |
|
57 | + //Default format |
|
58 | + $query['format'] = 'json'; |
|
59 | + } |
|
60 | + |
|
61 | + $this->setQuery($query); |
|
62 | + $this->setFormat($query['format']); |
|
63 | + |
|
64 | + } |
|
65 | + |
|
66 | + // -- Builder methods ------------------------------------------------------ |
|
67 | + |
|
68 | + /** |
|
69 | + * Format returning by the request. |
|
70 | + * |
|
71 | + * @param string $format The output format for the request |
|
72 | + * |
|
73 | + * @return maxh\Nominatim\Query |
|
74 | + * @throws maxh\Nominatim\Exceptions\InvalidParameterException if format is not supported |
|
75 | + */ |
|
76 | + public function format($format) |
|
77 | + { |
|
78 | + $format = strtolower($format); |
|
79 | + |
|
80 | + if (in_array($format, $this->accepteFormat)) |
|
81 | + { |
|
82 | + $this->setFormat($format); |
|
83 | + |
|
84 | + return $this; |
|
85 | + } |
|
86 | + |
|
87 | + throw new InvalidParameterException("Format is not supported"); |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Preferred language order for showing search results, overrides the value |
|
92 | + * specified in the "Accept-Language" HTTP header. Either uses standard |
|
93 | + * rfc2616 accept-language string or a simple comma separated list of |
|
94 | + * language codes. |
|
95 | + * |
|
96 | + * @param string $language Preferred language order for showing search results, overrides the value specified in the "Accept-Language" HTTP header. |
|
97 | + * Either uses standard rfc2616 accept-language string or a simple comma separated list of language codes. |
|
98 | + * |
|
99 | + * @return maxh\Nominatim\Query |
|
100 | + */ |
|
101 | + public function language($language) |
|
102 | + { |
|
103 | + $this->query['accept-language'] = $language; |
|
104 | + |
|
105 | + return $this; |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Include a breakdown of the address into elements. |
|
110 | + * |
|
111 | + * @param boolean $details |
|
112 | + * |
|
113 | + * @return maxh\Nominatim\Query |
|
114 | + */ |
|
115 | + public function addressDetails($details = true) |
|
116 | + { |
|
117 | + $this->query['addressdetails'] = $details ? "1" : "0"; |
|
118 | + |
|
119 | + return $this; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * If you are making large numbers of request please include a valid email address or alternatively include your email address as part of the User-Agent string. |
|
124 | + * This information will be kept confidential and only used to contact you in the event of a problem, see Usage Policy for more details. |
|
125 | + * |
|
126 | + * @param string $email Address mail |
|
127 | + * |
|
128 | + * @return maxh\Nominatim\Query |
|
129 | + */ |
|
130 | + public function email($email) |
|
131 | + { |
|
132 | + $this->query['email'] = $email; |
|
133 | + |
|
134 | + return $this; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Output format for the geometry of results |
|
139 | + * |
|
140 | + * @param string $polygon |
|
141 | + * |
|
142 | + * @return maxh\Nominatim\Query |
|
143 | + * @throws maxh\Nominatim\Exceptions\InvalidParameterException if polygon format is not supported |
|
144 | + */ |
|
145 | + public function polygon($polygon) |
|
146 | + { |
|
147 | + if (in_array($polygon, $this->polygon)) |
|
148 | + { |
|
149 | + $this->query['polygon_' . $polygon] = "1"; |
|
150 | + |
|
151 | + return $this; |
|
152 | + } |
|
153 | + |
|
154 | + throw new InvalidParameterException("This polygon format is not supported"); |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * Include additional information in the result if available |
|
159 | + * |
|
160 | + * @param boolean $tags |
|
161 | + * |
|
162 | + * @return maxh\Nominatim\Query |
|
163 | + */ |
|
164 | + public function extraTags($tags = true) |
|
165 | + { |
|
166 | + $this->query['extratags'] = $tags ? "1" : "0"; |
|
167 | + |
|
168 | + return $this; |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * Include a list of alternative names in the results. |
|
173 | + * These may include language variants, references, operator and brand. |
|
174 | + * |
|
175 | + * @param boolean $details |
|
176 | + * |
|
177 | + * @return maxh\Nominatim\Query |
|
178 | + */ |
|
179 | + public function nameDetails($details = true) |
|
180 | + { |
|
181 | + $this->query['namedetails'] = $details ? "1" : "0"; |
|
182 | + |
|
183 | + return $this; |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Returns the URL-encoded query. |
|
188 | + * |
|
189 | + * @return string |
|
190 | + */ |
|
191 | + public function getQueryString() |
|
192 | + { |
|
193 | + return http_build_query($this->query); |
|
194 | + } |
|
195 | + |
|
196 | + // -- Getters & Setters ---------------------------------------------------- |
|
197 | + |
|
198 | + /** |
|
199 | + * Get path |
|
200 | + * @return string |
|
201 | + */ |
|
202 | + public function getPath() |
|
203 | + { |
|
204 | + return $this->path; |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Get query |
|
209 | + * @return array |
|
210 | + */ |
|
211 | + public function getQuery() |
|
212 | + { |
|
213 | + return $this->query; |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * Get format |
|
218 | + * @return string |
|
219 | + */ |
|
220 | + public function getFormat() |
|
221 | + { |
|
222 | + return $this->format; |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * Set path |
|
227 | + * @param string $path Name's path of the service |
|
228 | + */ |
|
229 | + protected function setPath($path) |
|
230 | + { |
|
231 | + $this->path = $path; |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * Set query |
|
236 | + * @param array $query Parameter of the query |
|
237 | + */ |
|
238 | + protected function setQuery($query = array()) |
|
239 | + { |
|
240 | + $this->query = $query; |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * Set format |
|
245 | + * @param string $format Format returning by the response |
|
246 | + */ |
|
247 | + protected function setFormat($format) |
|
248 | + { |
|
249 | + $this->format = $this->query['format'] = $format; |
|
250 | + } |
|
251 | 251 | |
252 | 252 | } |
@@ -22,174 +22,174 @@ |
||
22 | 22 | class Nominatim |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * Contain url of the current application |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - private $application_url = null; |
|
30 | - |
|
31 | - /** |
|
32 | - * Contain http client connection |
|
33 | - * @var Client |
|
34 | - */ |
|
35 | - private $http_client = null; |
|
36 | - |
|
37 | - /** |
|
38 | - * The search object which serves as a template for new ones created |
|
39 | - * by 'newSearch()' method. |
|
40 | - * |
|
41 | - * @var Search |
|
42 | - */ |
|
43 | - private $baseSearch; |
|
44 | - |
|
45 | - /** |
|
46 | - * Template for new ones created by 'newReverser()' method. |
|
47 | - * @var Reverse |
|
48 | - */ |
|
49 | - private $baseReverse; |
|
50 | - |
|
51 | - /** |
|
52 | - * Template for new ones created by 'newLookup()' method. |
|
53 | - * @var Lookup |
|
54 | - */ |
|
55 | - private $baseLookup; |
|
56 | - |
|
57 | - /** |
|
58 | - * Constructor |
|
59 | - * @param string $application_url Contain url of the current application |
|
60 | - * @param Guzzle\Client|null $http_client Client object from Guzzle |
|
61 | - */ |
|
62 | - public function __construct( |
|
63 | - $application_url, |
|
64 | - Client $http_client = null |
|
65 | - ) { |
|
66 | - |
|
67 | - if (!isset($application_url)) |
|
68 | - { |
|
69 | - throw new InvalidParameterException("Application url parameter is empty"); |
|
70 | - } |
|
71 | - |
|
72 | - if (!isset($http_client)) |
|
73 | - { |
|
74 | - $http_client = new Client([ |
|
75 | - 'base_uri' => $application_url, |
|
76 | - 'timeout' => 30, |
|
77 | - 'connection_timeout' => 5, |
|
78 | - ]); |
|
79 | - } else if ($http_client instanceof Client) |
|
80 | - { |
|
81 | - $application_url_client = $http_client->getConfig('base_uri'); |
|
82 | - |
|
83 | - if (!isset($application_url_client)) |
|
84 | - { |
|
85 | - $http_client->setDefaultOption('base_uri', $application_url); |
|
86 | - } else if ($application_url_client != $application_url) |
|
87 | - { |
|
88 | - throw new InvalidParameterException("http_client parameter has a differente url to application_url parameter"); |
|
89 | - } |
|
90 | - } else |
|
91 | - { |
|
92 | - throw new InvalidParameterException("http_client parameter must be a GuzzleHttp\Client object or empty"); |
|
93 | - } |
|
94 | - |
|
95 | - $this->application_url = $application_url; |
|
96 | - $this->http_client = $http_client; |
|
97 | - |
|
98 | - //Create base |
|
99 | - $this->baseSearch = new Search(); |
|
100 | - $this->baseReverse = new Reverse(); |
|
101 | - $this->baseLookup = new Lookup(); |
|
102 | - |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * Returns a new search object based on the base search. |
|
107 | - * |
|
108 | - * @return Search |
|
109 | - */ |
|
110 | - public function newSearch() |
|
111 | - { |
|
112 | - return clone $this->baseSearch; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Returns a new search object based on the base reverse. |
|
117 | - * |
|
118 | - * @return Reverse |
|
119 | - */ |
|
120 | - public function newReverse() |
|
121 | - { |
|
122 | - return clone $this->baseReverse; |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Returns a new search object based on the base lookup. |
|
127 | - * |
|
128 | - * @return Lookup |
|
129 | - */ |
|
130 | - public function newLookup() |
|
131 | - { |
|
132 | - return clone $this->baseLookup; |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Decode the data returned from the request |
|
137 | - * |
|
138 | - * @param string $format json or xml |
|
139 | - * @param Request $request Request object from Guzzle |
|
140 | - * @param ResponseInterface $response Interface response object from Guzzle |
|
141 | - * |
|
142 | - * @return array|\SimpleXMLElement |
|
143 | - * @throws maxh\Nominatim\Exceptions\NominatimException if no format for decode |
|
144 | - */ |
|
145 | - private function decodeResponse($format, Request $request, ResponseInterface $response) |
|
146 | - { |
|
147 | - |
|
148 | - if ($format == 'json') |
|
149 | - { |
|
150 | - return json_decode($response->getBody(), true); |
|
151 | - } |
|
152 | - |
|
153 | - if ($format == 'xml') |
|
154 | - { |
|
155 | - return new \SimpleXMLElement($response->getBody()); |
|
156 | - } |
|
157 | - |
|
158 | - throw new NominatimException("Format is undefined or not supported for decode response", $request, $response); |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * Runs the query and returns the result set from Nominatim. |
|
163 | - * @param QueryInterface $nRequest The object request to send |
|
164 | - * |
|
165 | - * @return array The decoded data returned from Nominatim |
|
166 | - * @throws \GuzzleHttp\Exception\ClientException if http request is an error |
|
167 | - */ |
|
168 | - public function find(QueryInterface $nRequest) |
|
169 | - { |
|
170 | - $url = $this->application_url . '/' . $nRequest->getPath() . '?'; |
|
171 | - $request = new Request('GET', $url); |
|
172 | - |
|
173 | - //Convert the query array to string with space replace to + |
|
174 | - $query = \GuzzleHttp\Psr7\build_query($nRequest->getQuery(), PHP_QUERY_RFC1738); |
|
175 | - |
|
176 | - $url = $request->getUri()->withQuery($query); |
|
177 | - $request = $request->withUri($url); |
|
178 | - |
|
179 | - return $this->decodeResponse( |
|
180 | - $nRequest->getFormat(), |
|
181 | - $request, |
|
182 | - $this->http_client->send($request) |
|
183 | - ); |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Return the client using by instance |
|
188 | - * @return GuzzleHttp\Client |
|
189 | - */ |
|
190 | - public function getClient() |
|
191 | - { |
|
192 | - return $this->http_client; |
|
193 | - } |
|
25 | + /** |
|
26 | + * Contain url of the current application |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + private $application_url = null; |
|
30 | + |
|
31 | + /** |
|
32 | + * Contain http client connection |
|
33 | + * @var Client |
|
34 | + */ |
|
35 | + private $http_client = null; |
|
36 | + |
|
37 | + /** |
|
38 | + * The search object which serves as a template for new ones created |
|
39 | + * by 'newSearch()' method. |
|
40 | + * |
|
41 | + * @var Search |
|
42 | + */ |
|
43 | + private $baseSearch; |
|
44 | + |
|
45 | + /** |
|
46 | + * Template for new ones created by 'newReverser()' method. |
|
47 | + * @var Reverse |
|
48 | + */ |
|
49 | + private $baseReverse; |
|
50 | + |
|
51 | + /** |
|
52 | + * Template for new ones created by 'newLookup()' method. |
|
53 | + * @var Lookup |
|
54 | + */ |
|
55 | + private $baseLookup; |
|
56 | + |
|
57 | + /** |
|
58 | + * Constructor |
|
59 | + * @param string $application_url Contain url of the current application |
|
60 | + * @param Guzzle\Client|null $http_client Client object from Guzzle |
|
61 | + */ |
|
62 | + public function __construct( |
|
63 | + $application_url, |
|
64 | + Client $http_client = null |
|
65 | + ) { |
|
66 | + |
|
67 | + if (!isset($application_url)) |
|
68 | + { |
|
69 | + throw new InvalidParameterException("Application url parameter is empty"); |
|
70 | + } |
|
71 | + |
|
72 | + if (!isset($http_client)) |
|
73 | + { |
|
74 | + $http_client = new Client([ |
|
75 | + 'base_uri' => $application_url, |
|
76 | + 'timeout' => 30, |
|
77 | + 'connection_timeout' => 5, |
|
78 | + ]); |
|
79 | + } else if ($http_client instanceof Client) |
|
80 | + { |
|
81 | + $application_url_client = $http_client->getConfig('base_uri'); |
|
82 | + |
|
83 | + if (!isset($application_url_client)) |
|
84 | + { |
|
85 | + $http_client->setDefaultOption('base_uri', $application_url); |
|
86 | + } else if ($application_url_client != $application_url) |
|
87 | + { |
|
88 | + throw new InvalidParameterException("http_client parameter has a differente url to application_url parameter"); |
|
89 | + } |
|
90 | + } else |
|
91 | + { |
|
92 | + throw new InvalidParameterException("http_client parameter must be a GuzzleHttp\Client object or empty"); |
|
93 | + } |
|
94 | + |
|
95 | + $this->application_url = $application_url; |
|
96 | + $this->http_client = $http_client; |
|
97 | + |
|
98 | + //Create base |
|
99 | + $this->baseSearch = new Search(); |
|
100 | + $this->baseReverse = new Reverse(); |
|
101 | + $this->baseLookup = new Lookup(); |
|
102 | + |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * Returns a new search object based on the base search. |
|
107 | + * |
|
108 | + * @return Search |
|
109 | + */ |
|
110 | + public function newSearch() |
|
111 | + { |
|
112 | + return clone $this->baseSearch; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Returns a new search object based on the base reverse. |
|
117 | + * |
|
118 | + * @return Reverse |
|
119 | + */ |
|
120 | + public function newReverse() |
|
121 | + { |
|
122 | + return clone $this->baseReverse; |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Returns a new search object based on the base lookup. |
|
127 | + * |
|
128 | + * @return Lookup |
|
129 | + */ |
|
130 | + public function newLookup() |
|
131 | + { |
|
132 | + return clone $this->baseLookup; |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Decode the data returned from the request |
|
137 | + * |
|
138 | + * @param string $format json or xml |
|
139 | + * @param Request $request Request object from Guzzle |
|
140 | + * @param ResponseInterface $response Interface response object from Guzzle |
|
141 | + * |
|
142 | + * @return array|\SimpleXMLElement |
|
143 | + * @throws maxh\Nominatim\Exceptions\NominatimException if no format for decode |
|
144 | + */ |
|
145 | + private function decodeResponse($format, Request $request, ResponseInterface $response) |
|
146 | + { |
|
147 | + |
|
148 | + if ($format == 'json') |
|
149 | + { |
|
150 | + return json_decode($response->getBody(), true); |
|
151 | + } |
|
152 | + |
|
153 | + if ($format == 'xml') |
|
154 | + { |
|
155 | + return new \SimpleXMLElement($response->getBody()); |
|
156 | + } |
|
157 | + |
|
158 | + throw new NominatimException("Format is undefined or not supported for decode response", $request, $response); |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * Runs the query and returns the result set from Nominatim. |
|
163 | + * @param QueryInterface $nRequest The object request to send |
|
164 | + * |
|
165 | + * @return array The decoded data returned from Nominatim |
|
166 | + * @throws \GuzzleHttp\Exception\ClientException if http request is an error |
|
167 | + */ |
|
168 | + public function find(QueryInterface $nRequest) |
|
169 | + { |
|
170 | + $url = $this->application_url . '/' . $nRequest->getPath() . '?'; |
|
171 | + $request = new Request('GET', $url); |
|
172 | + |
|
173 | + //Convert the query array to string with space replace to + |
|
174 | + $query = \GuzzleHttp\Psr7\build_query($nRequest->getQuery(), PHP_QUERY_RFC1738); |
|
175 | + |
|
176 | + $url = $request->getUri()->withQuery($query); |
|
177 | + $request = $request->withUri($url); |
|
178 | + |
|
179 | + return $this->decodeResponse( |
|
180 | + $nRequest->getFormat(), |
|
181 | + $request, |
|
182 | + $this->http_client->send($request) |
|
183 | + ); |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Return the client using by instance |
|
188 | + * @return GuzzleHttp\Client |
|
189 | + */ |
|
190 | + public function getClient() |
|
191 | + { |
|
192 | + return $this->http_client; |
|
193 | + } |
|
194 | 194 | |
195 | 195 | } |
@@ -18,208 +18,208 @@ |
||
18 | 18 | class Search extends Query |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * Constuctor |
|
23 | - * @param array $query Default value for this query |
|
24 | - */ |
|
25 | - public function __construct(array $query = []) |
|
26 | - { |
|
27 | - parent::__construct(); |
|
28 | - |
|
29 | - $this->setPath('search'); |
|
30 | - |
|
31 | - $this->accepteFormat[] = 'html'; |
|
32 | - $this->accepteFormat[] = 'jsonv2'; |
|
33 | - } |
|
34 | - |
|
35 | - // -- Builder methods ------------------------------------------------------ |
|
36 | - |
|
37 | - /** |
|
38 | - * Query string to search for. |
|
39 | - * |
|
40 | - * @param string $query The query |
|
41 | - * |
|
42 | - * @return maxh\Nominatim\Search |
|
43 | - */ |
|
44 | - public function query($query) |
|
45 | - { |
|
46 | - $this->query['q'] = $query; |
|
47 | - |
|
48 | - return $this; |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * Street to search for. |
|
53 | - * |
|
54 | - * Do not combine with query(). |
|
55 | - * |
|
56 | - * @param string $street The street |
|
57 | - * |
|
58 | - * @return maxh\Nominatim\Search |
|
59 | - */ |
|
60 | - public function street($street) |
|
61 | - { |
|
62 | - $this->query['street'] = $street; |
|
63 | - |
|
64 | - return $this; |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * City to search for (experimental). |
|
69 | - * |
|
70 | - * Do not combine with query(). |
|
71 | - * |
|
72 | - * @param string $city The city |
|
73 | - * |
|
74 | - * @return maxh\Nominatim\Search |
|
75 | - */ |
|
76 | - public function city($city) |
|
77 | - { |
|
78 | - $this->query['city'] = $city; |
|
79 | - |
|
80 | - return $this; |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * County to search for. |
|
85 | - * |
|
86 | - * Do not combine with query(). |
|
87 | - * |
|
88 | - * @param string $county The county |
|
89 | - * |
|
90 | - * @return maxh\Nominatim\Search |
|
91 | - */ |
|
92 | - public function county($county) |
|
93 | - { |
|
94 | - $this->query['county'] = $county; |
|
95 | - |
|
96 | - return $this; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * State to search for. |
|
101 | - * |
|
102 | - * Do not combine with query(). |
|
103 | - * |
|
104 | - * @param string $state The state |
|
105 | - * |
|
106 | - * @return maxh\Nominatim\Search |
|
107 | - */ |
|
108 | - public function state($state) |
|
109 | - { |
|
110 | - $this->query['state'] = $state; |
|
111 | - |
|
112 | - return $this; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Country to search for. |
|
117 | - * |
|
118 | - * Do not combine with query(). |
|
119 | - * |
|
120 | - * @param string $country The country |
|
121 | - * |
|
122 | - * @return maxh\Nominatim\Search |
|
123 | - */ |
|
124 | - public function country($country) |
|
125 | - { |
|
126 | - $this->query['country'] = $country; |
|
127 | - |
|
128 | - return $this; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Postal code to search for (experimental). |
|
133 | - * |
|
134 | - * Do not combine with query(). |
|
135 | - * |
|
136 | - * @param integer $postalCode The postal code |
|
137 | - * |
|
138 | - * @return maxh\Nominatim\Search |
|
139 | - */ |
|
140 | - public function postalCode($postalCode) |
|
141 | - { |
|
142 | - $this->query['postalcode'] = $postalCode; |
|
143 | - |
|
144 | - return $this; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Limit search results to a specific country (or a list of countries). |
|
149 | - * |
|
150 | - * <countrycode> should be the ISO 3166-1alpha2 code, e.g. gb for the United |
|
151 | - * Kingdom, de for Germany, etc. |
|
152 | - * |
|
153 | - * @param string $countrycode The country code |
|
154 | - * |
|
155 | - * @return maxh\Nominatim\Search |
|
156 | - * @throws maxh\Nominatim\Exceptions\InvalidParameterException if country code is invalid |
|
157 | - */ |
|
158 | - public function countryCode($countrycode) |
|
159 | - { |
|
160 | - if (!preg_match('/^[a-z]{2}$/i', $countrycode)) { |
|
161 | - throw new InvalidParameterException("Invalid country code: \"$countrycode\""); |
|
162 | - } |
|
163 | - |
|
164 | - if (!isset($this->query['countrycode'])) { |
|
165 | - $this->query['countrycode'] = $countrycode; |
|
166 | - } else { |
|
167 | - $this->query['countrycode'] .= "," . $countrycode; |
|
168 | - } |
|
169 | - |
|
170 | - return $this; |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * The preferred area to find search results |
|
175 | - * |
|
176 | - * @param string $left Left of the area |
|
177 | - * @param string $top Top of the area |
|
178 | - * @param string $right Right of the area |
|
179 | - * @param string $bottom Bottom of the area |
|
180 | - * |
|
181 | - * @return maxh\Nominatim\Search |
|
182 | - */ |
|
183 | - public function viewBox($left, $top, $right, $bottom) |
|
184 | - { |
|
185 | - $this->query['viewbox'] = $left . ',' . $top . ',' . $right . ',' . $bottom; |
|
186 | - |
|
187 | - return $this; |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * If you do not want certain openstreetmap objects to appear in the search results. |
|
192 | - * |
|
193 | - * @return maxh\Nominatim\Search |
|
194 | - * @throws maxh\Nominatim\Exceptions\InvalidParameterException if no place id |
|
195 | - */ |
|
196 | - public function exludePlaceIds() |
|
197 | - { |
|
198 | - $args = func_get_args(); |
|
199 | - |
|
200 | - if (count($args) > 0) |
|
201 | - { |
|
202 | - $this->query['exclude_place_ids'] = implode(', ', $args); |
|
203 | - |
|
204 | - return $this; |
|
205 | - } |
|
206 | - |
|
207 | - throw new InvalidParameterException("No place id in parameter"); |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * Limit the number of returned results |
|
212 | - * |
|
213 | - * @param integer $limit |
|
214 | - * |
|
215 | - * @return maxh\Nominatim\Search |
|
216 | - */ |
|
217 | - public function limit($limit) |
|
218 | - { |
|
219 | - $this->query['limit'] = strval($limit); |
|
220 | - |
|
221 | - return $this; |
|
222 | - } |
|
21 | + /** |
|
22 | + * Constuctor |
|
23 | + * @param array $query Default value for this query |
|
24 | + */ |
|
25 | + public function __construct(array $query = []) |
|
26 | + { |
|
27 | + parent::__construct(); |
|
28 | + |
|
29 | + $this->setPath('search'); |
|
30 | + |
|
31 | + $this->accepteFormat[] = 'html'; |
|
32 | + $this->accepteFormat[] = 'jsonv2'; |
|
33 | + } |
|
34 | + |
|
35 | + // -- Builder methods ------------------------------------------------------ |
|
36 | + |
|
37 | + /** |
|
38 | + * Query string to search for. |
|
39 | + * |
|
40 | + * @param string $query The query |
|
41 | + * |
|
42 | + * @return maxh\Nominatim\Search |
|
43 | + */ |
|
44 | + public function query($query) |
|
45 | + { |
|
46 | + $this->query['q'] = $query; |
|
47 | + |
|
48 | + return $this; |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * Street to search for. |
|
53 | + * |
|
54 | + * Do not combine with query(). |
|
55 | + * |
|
56 | + * @param string $street The street |
|
57 | + * |
|
58 | + * @return maxh\Nominatim\Search |
|
59 | + */ |
|
60 | + public function street($street) |
|
61 | + { |
|
62 | + $this->query['street'] = $street; |
|
63 | + |
|
64 | + return $this; |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * City to search for (experimental). |
|
69 | + * |
|
70 | + * Do not combine with query(). |
|
71 | + * |
|
72 | + * @param string $city The city |
|
73 | + * |
|
74 | + * @return maxh\Nominatim\Search |
|
75 | + */ |
|
76 | + public function city($city) |
|
77 | + { |
|
78 | + $this->query['city'] = $city; |
|
79 | + |
|
80 | + return $this; |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * County to search for. |
|
85 | + * |
|
86 | + * Do not combine with query(). |
|
87 | + * |
|
88 | + * @param string $county The county |
|
89 | + * |
|
90 | + * @return maxh\Nominatim\Search |
|
91 | + */ |
|
92 | + public function county($county) |
|
93 | + { |
|
94 | + $this->query['county'] = $county; |
|
95 | + |
|
96 | + return $this; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * State to search for. |
|
101 | + * |
|
102 | + * Do not combine with query(). |
|
103 | + * |
|
104 | + * @param string $state The state |
|
105 | + * |
|
106 | + * @return maxh\Nominatim\Search |
|
107 | + */ |
|
108 | + public function state($state) |
|
109 | + { |
|
110 | + $this->query['state'] = $state; |
|
111 | + |
|
112 | + return $this; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Country to search for. |
|
117 | + * |
|
118 | + * Do not combine with query(). |
|
119 | + * |
|
120 | + * @param string $country The country |
|
121 | + * |
|
122 | + * @return maxh\Nominatim\Search |
|
123 | + */ |
|
124 | + public function country($country) |
|
125 | + { |
|
126 | + $this->query['country'] = $country; |
|
127 | + |
|
128 | + return $this; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Postal code to search for (experimental). |
|
133 | + * |
|
134 | + * Do not combine with query(). |
|
135 | + * |
|
136 | + * @param integer $postalCode The postal code |
|
137 | + * |
|
138 | + * @return maxh\Nominatim\Search |
|
139 | + */ |
|
140 | + public function postalCode($postalCode) |
|
141 | + { |
|
142 | + $this->query['postalcode'] = $postalCode; |
|
143 | + |
|
144 | + return $this; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Limit search results to a specific country (or a list of countries). |
|
149 | + * |
|
150 | + * <countrycode> should be the ISO 3166-1alpha2 code, e.g. gb for the United |
|
151 | + * Kingdom, de for Germany, etc. |
|
152 | + * |
|
153 | + * @param string $countrycode The country code |
|
154 | + * |
|
155 | + * @return maxh\Nominatim\Search |
|
156 | + * @throws maxh\Nominatim\Exceptions\InvalidParameterException if country code is invalid |
|
157 | + */ |
|
158 | + public function countryCode($countrycode) |
|
159 | + { |
|
160 | + if (!preg_match('/^[a-z]{2}$/i', $countrycode)) { |
|
161 | + throw new InvalidParameterException("Invalid country code: \"$countrycode\""); |
|
162 | + } |
|
163 | + |
|
164 | + if (!isset($this->query['countrycode'])) { |
|
165 | + $this->query['countrycode'] = $countrycode; |
|
166 | + } else { |
|
167 | + $this->query['countrycode'] .= "," . $countrycode; |
|
168 | + } |
|
169 | + |
|
170 | + return $this; |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * The preferred area to find search results |
|
175 | + * |
|
176 | + * @param string $left Left of the area |
|
177 | + * @param string $top Top of the area |
|
178 | + * @param string $right Right of the area |
|
179 | + * @param string $bottom Bottom of the area |
|
180 | + * |
|
181 | + * @return maxh\Nominatim\Search |
|
182 | + */ |
|
183 | + public function viewBox($left, $top, $right, $bottom) |
|
184 | + { |
|
185 | + $this->query['viewbox'] = $left . ',' . $top . ',' . $right . ',' . $bottom; |
|
186 | + |
|
187 | + return $this; |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * If you do not want certain openstreetmap objects to appear in the search results. |
|
192 | + * |
|
193 | + * @return maxh\Nominatim\Search |
|
194 | + * @throws maxh\Nominatim\Exceptions\InvalidParameterException if no place id |
|
195 | + */ |
|
196 | + public function exludePlaceIds() |
|
197 | + { |
|
198 | + $args = func_get_args(); |
|
199 | + |
|
200 | + if (count($args) > 0) |
|
201 | + { |
|
202 | + $this->query['exclude_place_ids'] = implode(', ', $args); |
|
203 | + |
|
204 | + return $this; |
|
205 | + } |
|
206 | + |
|
207 | + throw new InvalidParameterException("No place id in parameter"); |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * Limit the number of returned results |
|
212 | + * |
|
213 | + * @param integer $limit |
|
214 | + * |
|
215 | + * @return maxh\Nominatim\Search |
|
216 | + */ |
|
217 | + public function limit($limit) |
|
218 | + { |
|
219 | + $this->query['limit'] = strval($limit); |
|
220 | + |
|
221 | + return $this; |
|
222 | + } |
|
223 | 223 | |
224 | 224 | |
225 | 225 | } |
@@ -14,31 +14,31 @@ |
||
14 | 14 | interface QueryInterface |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * Get path of the request |
|
19 | - * |
|
20 | - * Example request : |
|
21 | - * - Search = search |
|
22 | - * - Reverse Geocoding = reverse |
|
23 | - * |
|
24 | - * @return string |
|
25 | - */ |
|
26 | - public function getPath(); |
|
17 | + /** |
|
18 | + * Get path of the request |
|
19 | + * |
|
20 | + * Example request : |
|
21 | + * - Search = search |
|
22 | + * - Reverse Geocoding = reverse |
|
23 | + * |
|
24 | + * @return string |
|
25 | + */ |
|
26 | + public function getPath(); |
|
27 | 27 | |
28 | - /** |
|
29 | - * Get the query to send |
|
30 | - * |
|
31 | - * @return array |
|
32 | - */ |
|
33 | - public function getQuery(); |
|
28 | + /** |
|
29 | + * Get the query to send |
|
30 | + * |
|
31 | + * @return array |
|
32 | + */ |
|
33 | + public function getQuery(); |
|
34 | 34 | |
35 | - /** |
|
36 | - * Get the format of the request |
|
37 | - * |
|
38 | - * Example : json or xml |
|
39 | - * |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - public function getFormat(); |
|
35 | + /** |
|
36 | + * Get the format of the request |
|
37 | + * |
|
38 | + * Example : json or xml |
|
39 | + * |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + public function getFormat(); |
|
43 | 43 | |
44 | 44 | } |
@@ -23,56 +23,56 @@ |
||
23 | 23 | class NominatimException extends Exception |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * Contain the request |
|
28 | - * @var RequestInterface |
|
29 | - */ |
|
30 | - private $request; |
|
26 | + /** |
|
27 | + * Contain the request |
|
28 | + * @var RequestInterface |
|
29 | + */ |
|
30 | + private $request; |
|
31 | 31 | |
32 | - /** |
|
33 | - * Contain the response |
|
34 | - * @var ResponseInterface |
|
35 | - */ |
|
36 | - private $response; |
|
32 | + /** |
|
33 | + * Contain the response |
|
34 | + * @var ResponseInterface |
|
35 | + */ |
|
36 | + private $response; |
|
37 | 37 | |
38 | - /** |
|
39 | - * Constructor |
|
40 | - * @param string $message Message of this exception |
|
41 | - * @param RequestInterface $request The request instance |
|
42 | - * @param ResponseInterface|null $response The response of the request |
|
43 | - * @param Exception|null $previous Exception object |
|
44 | - */ |
|
45 | - public function __construct( |
|
46 | - $message, |
|
47 | - RequestInterface $request, |
|
48 | - ResponseInterface $response = null, |
|
49 | - Exception $previous = null |
|
50 | - ) { |
|
51 | - // Set the code of the exception if the response is set and not future. |
|
52 | - $code = $response && !($response instanceof PromiseInterface) ? $response->getStatusCode() : 0; |
|
38 | + /** |
|
39 | + * Constructor |
|
40 | + * @param string $message Message of this exception |
|
41 | + * @param RequestInterface $request The request instance |
|
42 | + * @param ResponseInterface|null $response The response of the request |
|
43 | + * @param Exception|null $previous Exception object |
|
44 | + */ |
|
45 | + public function __construct( |
|
46 | + $message, |
|
47 | + RequestInterface $request, |
|
48 | + ResponseInterface $response = null, |
|
49 | + Exception $previous = null |
|
50 | + ) { |
|
51 | + // Set the code of the exception if the response is set and not future. |
|
52 | + $code = $response && !($response instanceof PromiseInterface) ? $response->getStatusCode() : 0; |
|
53 | 53 | |
54 | - parent::__construct($message, $code, $previous); |
|
54 | + parent::__construct($message, $code, $previous); |
|
55 | 55 | |
56 | - $this->request = $request; |
|
57 | - $this->response = $response; |
|
56 | + $this->request = $request; |
|
57 | + $this->response = $response; |
|
58 | 58 | |
59 | - } |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Return the Request |
|
63 | - * @return GuzzleHttp\Psr7\Request |
|
64 | - */ |
|
65 | - public function getRequest() |
|
66 | - { |
|
67 | - return $this->request; |
|
68 | - } |
|
61 | + /** |
|
62 | + * Return the Request |
|
63 | + * @return GuzzleHttp\Psr7\Request |
|
64 | + */ |
|
65 | + public function getRequest() |
|
66 | + { |
|
67 | + return $this->request; |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Return the Response |
|
72 | - * @return GuzzleHttp\Psr7\Response [description] |
|
73 | - */ |
|
74 | - public function getResponse() |
|
75 | - { |
|
76 | - return $this->response; |
|
77 | - } |
|
70 | + /** |
|
71 | + * Return the Response |
|
72 | + * @return GuzzleHttp\Psr7\Response [description] |
|
73 | + */ |
|
74 | + public function getResponse() |
|
75 | + { |
|
76 | + return $this->response; |
|
77 | + } |
|
78 | 78 | } |
@@ -18,91 +18,91 @@ |
||
18 | 18 | class Reverse extends Query |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * OSM Type accepted (Node/Way/Relation) |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - public $osmType = ['N', 'W', 'R']; |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * Constructo |
|
30 | - * @param array $query Default value for this query |
|
31 | - */ |
|
32 | - public function __construct(array $query = []) |
|
33 | - { |
|
34 | - parent::__construct(); |
|
35 | - |
|
36 | - $this->setPath('reverse'); |
|
37 | - } |
|
38 | - |
|
39 | - // -- Builder methods ------------------------------------------------------ |
|
40 | - |
|
41 | - /** |
|
42 | - * [osmType description] |
|
43 | - * |
|
44 | - * @param string $type |
|
45 | - * |
|
46 | - * @return maxh\Nominatim\Reverse |
|
47 | - * @throws maxh\Nominatim\Exceptions\InvalidParameterException if osm type is not supported |
|
48 | - */ |
|
49 | - public function osmType($type) |
|
50 | - { |
|
51 | - if (in_array($type, $this->osmType)) |
|
52 | - { |
|
53 | - $this->query['osm_type'] = $type; |
|
54 | - |
|
55 | - return $this; |
|
56 | - } |
|
57 | - |
|
58 | - throw new InvalidParameterException("OSM Type is not supported"); |
|
59 | - |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * A specific osm node / way / relation to return an address for. |
|
64 | - * |
|
65 | - * @param integer $id |
|
66 | - * |
|
67 | - * @return maxh\Nominatim\Reverse |
|
68 | - */ |
|
69 | - public function osmId($id) |
|
70 | - { |
|
71 | - $this->query['osm_id'] = $id; |
|
72 | - |
|
73 | - return $this; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * The location to generate an address for |
|
78 | - * |
|
79 | - * @param float $lat The latitude |
|
80 | - * @param float $lon The longitude |
|
81 | - * |
|
82 | - * @return maxh\Nominatim\Reverse |
|
83 | - */ |
|
84 | - public function latlon($lat, $lon) |
|
85 | - { |
|
86 | - $this->query['lat'] = $lat; |
|
87 | - |
|
88 | - $this->query['lon'] = $lon; |
|
89 | - |
|
90 | - return $this; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Level of detail required where 0 is country and 18 is house/building |
|
95 | - * |
|
96 | - * @param integer $zoom |
|
97 | - * |
|
98 | - * @return maxh\Nominatim\Reverse |
|
99 | - */ |
|
100 | - public function zoom($zoom) |
|
101 | - { |
|
102 | - $this->query['zoom'] = strval($zoom); |
|
103 | - |
|
104 | - return $this; |
|
105 | - } |
|
21 | + /** |
|
22 | + * OSM Type accepted (Node/Way/Relation) |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + public $osmType = ['N', 'W', 'R']; |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * Constructo |
|
30 | + * @param array $query Default value for this query |
|
31 | + */ |
|
32 | + public function __construct(array $query = []) |
|
33 | + { |
|
34 | + parent::__construct(); |
|
35 | + |
|
36 | + $this->setPath('reverse'); |
|
37 | + } |
|
38 | + |
|
39 | + // -- Builder methods ------------------------------------------------------ |
|
40 | + |
|
41 | + /** |
|
42 | + * [osmType description] |
|
43 | + * |
|
44 | + * @param string $type |
|
45 | + * |
|
46 | + * @return maxh\Nominatim\Reverse |
|
47 | + * @throws maxh\Nominatim\Exceptions\InvalidParameterException if osm type is not supported |
|
48 | + */ |
|
49 | + public function osmType($type) |
|
50 | + { |
|
51 | + if (in_array($type, $this->osmType)) |
|
52 | + { |
|
53 | + $this->query['osm_type'] = $type; |
|
54 | + |
|
55 | + return $this; |
|
56 | + } |
|
57 | + |
|
58 | + throw new InvalidParameterException("OSM Type is not supported"); |
|
59 | + |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * A specific osm node / way / relation to return an address for. |
|
64 | + * |
|
65 | + * @param integer $id |
|
66 | + * |
|
67 | + * @return maxh\Nominatim\Reverse |
|
68 | + */ |
|
69 | + public function osmId($id) |
|
70 | + { |
|
71 | + $this->query['osm_id'] = $id; |
|
72 | + |
|
73 | + return $this; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * The location to generate an address for |
|
78 | + * |
|
79 | + * @param float $lat The latitude |
|
80 | + * @param float $lon The longitude |
|
81 | + * |
|
82 | + * @return maxh\Nominatim\Reverse |
|
83 | + */ |
|
84 | + public function latlon($lat, $lon) |
|
85 | + { |
|
86 | + $this->query['lat'] = $lat; |
|
87 | + |
|
88 | + $this->query['lon'] = $lon; |
|
89 | + |
|
90 | + return $this; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Level of detail required where 0 is country and 18 is house/building |
|
95 | + * |
|
96 | + * @param integer $zoom |
|
97 | + * |
|
98 | + * @return maxh\Nominatim\Reverse |
|
99 | + */ |
|
100 | + public function zoom($zoom) |
|
101 | + { |
|
102 | + $this->query['zoom'] = strval($zoom); |
|
103 | + |
|
104 | + return $this; |
|
105 | + } |
|
106 | 106 | |
107 | 107 | |
108 | 108 | } |
@@ -18,44 +18,44 @@ |
||
18 | 18 | class Lookup extends Query |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * Constuctor |
|
23 | - * @param array $query Default value for this query |
|
24 | - */ |
|
25 | - public function __construct(array $query = []) |
|
26 | - { |
|
27 | - parent::__construct(); |
|
28 | - |
|
29 | - $this->setPath('lookup'); |
|
30 | - } |
|
31 | - |
|
32 | - // -- Builder methods ------------------------------------------------------ |
|
33 | - |
|
34 | - /** |
|
35 | - * A list of up to 50 specific osm node, way or relations ids to return the addresses for |
|
36 | - * |
|
37 | - * @param string $id |
|
38 | - * |
|
39 | - * @return maxh\Nominatim\Lookup |
|
40 | - */ |
|
41 | - public function osmIds($id) |
|
42 | - { |
|
43 | - $this->query['osm_ids'] = $id; |
|
44 | - |
|
45 | - return $this; |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Output format for the geometry of results |
|
50 | - * |
|
51 | - * @param string $polygon |
|
52 | - * |
|
53 | - * @throws maxh\Nominatim\Exceptions\InvalidParameterException Polygon is not supported with lookup |
|
54 | - */ |
|
55 | - public function polygon($polygon) |
|
56 | - { |
|
57 | - throw new InvalidParameterException("The polygon is not supported with lookup"); |
|
58 | - } |
|
21 | + /** |
|
22 | + * Constuctor |
|
23 | + * @param array $query Default value for this query |
|
24 | + */ |
|
25 | + public function __construct(array $query = []) |
|
26 | + { |
|
27 | + parent::__construct(); |
|
28 | + |
|
29 | + $this->setPath('lookup'); |
|
30 | + } |
|
31 | + |
|
32 | + // -- Builder methods ------------------------------------------------------ |
|
33 | + |
|
34 | + /** |
|
35 | + * A list of up to 50 specific osm node, way or relations ids to return the addresses for |
|
36 | + * |
|
37 | + * @param string $id |
|
38 | + * |
|
39 | + * @return maxh\Nominatim\Lookup |
|
40 | + */ |
|
41 | + public function osmIds($id) |
|
42 | + { |
|
43 | + $this->query['osm_ids'] = $id; |
|
44 | + |
|
45 | + return $this; |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Output format for the geometry of results |
|
50 | + * |
|
51 | + * @param string $polygon |
|
52 | + * |
|
53 | + * @throws maxh\Nominatim\Exceptions\InvalidParameterException Polygon is not supported with lookup |
|
54 | + */ |
|
55 | + public function polygon($polygon) |
|
56 | + { |
|
57 | + throw new InvalidParameterException("The polygon is not supported with lookup"); |
|
58 | + } |
|
59 | 59 | |
60 | 60 | |
61 | 61 | } |