22 private const HTTP_VERSION = HttpClient::HTTP_1_1;
23 private const HTTP_SOCKET_TIMEOUT = 10;
24 private const HTTP_STREAM_TIMEOUT = 10;
29 private const API_SEARCH_LIMIT = 10;
31 private const API_AUTOCOMPLETE_LIMIT = 7;
42 $this->source = $source;
47 $client = $this->makeHttpClient();
56 'addressdetails' => isset(
$options[
'addressdetails']) ? (
int)
$options[
'addressdetails'] : 0,
57 'limit' => isset(
$options[
'limit']) ? (
int)
$options[
'limit'] : self::API_SEARCH_LIMIT,
58 'accept-language' =>
$options[
'accept-language'] ??
'',
65 return $this->getResponse($client, $body);
70 $client = $this->makeHttpClient();
74 'limit' => isset(
$options[
'limit']) ? (int)
$options[
'limit'] : self::API_AUTOCOMPLETE_LIMIT,
94 return $this->getResponse($client, $body);
99 $client = $this->makeHttpClient();
101 $body = $client->get(
105 $this->wrapQueryData(
107 'osm_ids' =>
$options[
'osm_ids'] ??
'',
108 'addressdetails' => isset(
$options[
'addressdetails']) ? (
int)
$options[
'addressdetails'] : 0,
109 'accept-language' =>
$options[
'accept-language'] ??
'',
116 return $this->getResponse($client, $body);
121 $client = $this->makeHttpClient();
123 $body = $client->get(
127 $this->wrapQueryData(
129 'osmtype' =>
$options[
'osm_type'] ??
'',
130 'osmid' =>
$options[
'osm_id'] ??
'',
132 'addressdetails' => isset(
$options[
'addressdetails']) ? (
int)
$options[
'addressdetails'] : 0,
133 'linkedplaces' => isset(
$options[
'linkedplaces']) ? (
int)
$options[
'linkedplaces'] : 0,
134 'hierarchy' => isset(
$options[
'hierarchy']) ? (
int)
$options[
'hierarchy'] : 0,
135 'accept-language' =>
$options[
'accept-language'] ??
'',
141 return $this->getResponse($client, $body);
146 $client = $this->makeHttpClient();
148 $body = $client->get(
152 $this->wrapQueryData(
158 'addressdetails' => isset(
$options[
'addressdetails']) ? (
int)
$options[
'addressdetails'] : 0,
159 'accept-language' =>
$options[
'accept-language'] ??
'',
165 return $this->getResponse($client, $body);
176 $client = $this->makeHttpClient();
178 $body = $client->get(
183 'latitude' => $latitude,
184 'longitude' => $longitude,
192 $response = $this->getResponse($client, $body);
217 catch (ArgumentException $e)
225 private function makeHttpClient(): HttpClient
227 $token = $this->source->getOsmToken();
231 'version' => self::HTTP_VERSION,
232 'socketTimeout' => self::HTTP_SOCKET_TIMEOUT,
233 'streamTimeout' => self::HTTP_STREAM_TIMEOUT,
239 sprintf(
'Bearer %s', ($token ? $token->getToken() :
''))
242 $result->setHeader(
'Bx-Location-Osm-Host', $this->source->getOsmHostName());
247 private function buildUrl(
string $controller,
string $action,
array $queryData): string
249 $serviceUrl = $this->source->getOsmApiUrl();
253 throw new RuntimeException(
'Service url is not specified');
263 'action' => sprintf(
'osmgateway.%s.%s', $controller,
$action)
270 private function wrapQueryData(
array $queryData):
array
273 'params' => $queryData