8000 [GraphHopper] Add provider parameter by bisleadity · Pull Request #1251 · geocoder-php/Geocoder · GitHub
[go: up one dir, main page]

Skip to content

[GraphHopper] Add provider parameter #1251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[GraphHopper] Add GraphHopperProvider enum for provider options of Gr…
…aphHopper geocoding api

Graphhopper geocoding supports different providers. Hereby the option is given to use only available providers.

[GraphHopper] Add GraphHopperProviders enum for provider options of GraphHopper geocoding api

Graphhopper geocoding supports different providers. Hereby the option is given to use only available providers.
  • Loading branch information
bisleadity committed Mar 28, 2025
commit 320b5d783d1cda50cc6b7434d3bb4e24adfe45a8
2 changes: 1 addition & 1 deletion src/Provider/GraphHopper/GraphHopper.php
< 8000 tr data-hunk="d31d863454dbdba6a8b321e7820c3827fe663ac261a6968c5c7dd85e77dada92" class="show-top-border">
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function geocodeQuery(GeocodeQuery $query): Collection
}

$provider = $query->getData('provider');
if (is_string($provider) && '' !== $provider) {
if (is_string($provider) && GraphHopperProvider::tryFrom($provider)) {
$url .= sprintf('&provider=%s', urlencode($provider));
}

Expand Down
14 changes: 14 additions & 0 deletions src/Provider/GraphHopper/GraphHopperProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace Geocoder\Provider\GraphHopper;

enum GraphHopperProvider: string
{
case Default = 'default';
case Nominatim = 'nominatim';
case Gisgraphy = 'gisgraphy';
case Nettoolkit = 'nettoolkit';
case Opencagedata = 'opencagedata';
}
29 changes: 29 additions & 0 deletions src/Provider/GraphHopper/Tests/GraphHopperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,35 @@ function (RequestInterface $request) use (&$uri) {
);
}

public function testNoProviderIsAppendedWhenProviderNotInEnum(): void
{
$uri = '';

$provider = new GraphHopper(
$this->getMockedHttpClientCallback(
function (RequestInterface $request) use (&$uri) {
$uri = (string) $request->getUri();
}
),
'api_key'
);

$query = GeocodeQuery::create('242 Acklam Road, London, United Kingdom')
->withLocale('fr')
->withData('provider', 'invalidProvider');

try {
$provider->geocodeQuery($query);
} catch (InvalidServerResponse $e) {
}

$this->assertEquals('https://graphhopper.com/api/1/geocode'.
'?q=242+Acklam+Road%2C+London%2C+United+Kingdom'.
'&key=api_key&locale=fr&limit=5',
$uri
);
}

public function testReverseWithRealCoordinates(): void
{
if (!isset($_SERVER['GRAPHHOPPER_API_KEY'])) {
Expand Down
Loading
0