You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

33 lines
866 B

<?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();
}
}