<?php
|
|
|
|
namespace App\Service;
|
|
|
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
|
|
|
// Founit un accès à l’API Overpass
|
|
class OverpassClient {
|
|
|
|
public function __construct(
|
|
private HttpClientInterface $client,
|
|
) {
|
|
}
|
|
|
|
public function query($query, $prefix = '[out:json][timeout:25];', $suffix = 'out geom;')
|
|
{
|
|
$response = $this->client->request('GET', 'https://overpass-api.de/api/interpreter', [
|
|
'query' => [
|
|
'data' => $prefix . $query . $suffix,
|
|
],
|
|
]);
|
|
|
|
$isStatusCodeOk = ($response->getStatusCode() === 200);
|
|
$isContentTypeJson = ($response->getHeaders()['content-type'][0] === 'application/json');
|
|
|
|
if (!$isStatusCodeOk or !$isContentTypeJson) {
|
|
throw new \RuntimeException();
|
|
}
|
|
|
|
return $response->getContent();
|
|
}
|
|
|
|
}
|