Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/Geocoder/Provider/ArcGISOnline.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* @author ALKOUM Dorian <baikunz@gmail.com>
*/
class ArcGISOnline extends AbstractHttpProvider implements Provider
final class ArcGISOnline extends AbstractHttpProvider implements Provider
{
/**
* @var string
Expand Down
2 changes: 1 addition & 1 deletion src/Geocoder/Provider/BingMaps.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/**
* @author David Guyon <dguyon@gmail.com>
*/
class BingMaps extends AbstractHttpProvider implements LocaleAwareProvider
final class BingMaps extends AbstractHttpProvider implements LocaleAwareProvider
{
use LocaleTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Geocoder/Provider/Chain.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* @author Markus Bachmann <markus.bachmann@bachi.biz>
*/
class Chain implements LocaleAwareProvider
final class Chain implements LocaleAwareProvider
{
use LocaleTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Geocoder/Provider/FreeGeoIp.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* @author William Durand <william.durand1@gmail.com>
*/
class FreeGeoIp extends AbstractHttpProvider implements Provider
final class FreeGeoIp extends AbstractHttpProvider implements Provider
{
/**
* @var string
Expand Down
2 changes: 1 addition & 1 deletion src/Geocoder/Provider/GeoIP2.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/**
* @author Jens Wiese <jens@howtrueisfalse.de>
*/
class GeoIP2 extends AbstractProvider implements LocaleAwareProvider
final class GeoIP2 extends AbstractProvider implements LocaleAwareProvider
{
use LocaleTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Geocoder/Provider/GeoIPs.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*
* @link http://www.geoips.com/en/developer/api-guide
*/
class GeoIPs extends AbstractHttpProvider implements Provider
final class GeoIPs extends AbstractHttpProvider implements Provider
{
/**
* @var string
Expand Down
2 changes: 1 addition & 1 deletion src/Geocoder/Provider/GeoPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* @author Andrea Cristaudo <andrea.cristaudo@gmail.com>
*/
class GeoPlugin extends AbstractHttpProvider implements Provider
final class GeoPlugin extends AbstractHttpProvider implements Provider
{
/**
* @var string
Expand Down
2 changes: 1 addition & 1 deletion src/Geocoder/Provider/Geoip.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*
* @link http://php.net/manual/ref.geoip.php
*/
class Geoip extends AbstractProvider implements Provider
final class Geoip extends AbstractProvider implements Provider
{
public function __construct()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Geocoder/Provider/Geonames.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/**
* @author Giovanni Pirrotta <giovanni.pirrotta@gmail.com>
*/
class Geonames extends AbstractHttpProvider implements LocaleAwareProvider
final class Geonames extends AbstractHttpProvider implements LocaleAwareProvider
{
/**
* @var string
Expand Down
71 changes: 69 additions & 2 deletions src/Geocoder/Provider/GoogleMaps.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/**
* @author William Durand <william.durand1@gmail.com>
*/
class GoogleMaps extends AbstractHttpProvider implements LocaleAwareProvider
final class GoogleMaps extends AbstractHttpProvider implements LocaleAwareProvider
{
/**
* @var string
Expand Down Expand Up @@ -49,6 +49,38 @@ class GoogleMaps extends AbstractHttpProvider implements LocaleAwareProvider
*/
private $apiKey;

/**
* @var string
*/
private $clientId;

/**
* @var string
*/
private $privateKey;

/**
* Google Maps for Business
* https://developers.google.com/maps/documentation/business/
*
* @param HttpClient $client An HTTP adapter
* @param string $clientId Your Client ID
* @param string $privateKey Your Private Key (optional)
* @param string $locale A locale (optional)
* @param string $region Region biasing (optional)
* @param bool $useSsl Whether to use an SSL connection (optional)
* @param string $apiKey Google Geocoding API key (optional)
* @return GoogleMaps
*/
public static function business(HttpClient $client, $clientId, $privateKey = null, $locale = null, $region = null, $useSsl = false, $apiKey = null)
{
$provider = new self($client, $locale, $region, $useSsl, $apiKey);
$provider->clientId = $clientId;
$provider->privateKey = $privateKey;

return $provider;
}

/**
* @param HttpClient $client An HTTP adapter
* @param string $locale A locale (optional)
Expand Down Expand Up @@ -113,7 +145,7 @@ public function setRegion($region)
*
* @return string query with extra params
*/
protected function buildQuery($query)
private function buildQuery($query)
{
if (null !== $this->getLocale()) {
$query = sprintf('%s&language=%s', $query, $this->getLocale());
Expand All @@ -127,6 +159,14 @@ protected function buildQuery($query)
$query = sprintf('%s&key=%s', $query, $this->apiKey);
}

if (null !== $this->clientId) {
$query = sprintf('%s&client=%s', $query, $this->clientId);

if (null !== $this->privateKey) {
$query = $this->signQuery($query);
}
}

return $query;
}

Expand Down Expand Up @@ -269,4 +309,31 @@ private function updateAddressComponent(&$resultSet, $type, $values)

return $resultSet;
}

/**
* Sign a URL with a given crypto key
* Note that this URL must be properly URL-encoded
* src: http://gmaps-samples.googlecode.com/svn/trunk/urlsigning/UrlSigner.php-source
*
* @param string $query Query to be signed
*
* @return string $query Query with signature appended.
*/
private function signQuery($query)
{
$url = parse_url($query);

$urlPartToSign = $url['path'] . '?' . $url['query'];

// Decode the private key into its binary format
$decodedKey = base64_decode(str_replace(array('-', '_'), array('+', '/'), $this->privateKey));

// Create a signature using the private key and the URL-encoded
// string using HMAC SHA1. This signature will be binary.
$signature = hash_hmac('sha1', $urlPartToSign, $decodedKey, true);

$encodedSignature = str_replace(array('+', '/'), array('-', '_'), base64_encode($signature));

return sprintf('%s&signature=%s', $query, $encodedSignature);
}
}
98 changes: 0 additions & 98 deletions src/Geocoder/Provider/GoogleMapsBusiness.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Geocoder/Provider/HostIp.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* @author William Durand <william.durand1@gmail.com>
*/
class HostIp extends AbstractHttpProvider implements Provider
final class HostIp extends AbstractHttpProvider implements Provider
{
/**
* @var string
Expand Down
2 changes: 1 addition & 1 deletion src/Geocoder/Provider/IpInfoDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/**
* @author William Durand <william.durand1@gmail.com>
*/
class IpInfoDb extends AbstractHttpProvider implements Provider
final class IpInfoDb extends AbstractHttpProvider implements Provider
{
/**
* @var string
Expand Down
2 changes: 1 addition & 1 deletion src/Geocoder/Provider/MapQuest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/**
* @author William Durand <william.durand1@gmail.com>
*/
class MapQuest extends AbstractHttpProvider implements Provider
final class MapQuest extends AbstractHttpProvider implements Provider
{
/**
* @var string
Expand Down
4 changes: 2 additions & 2 deletions src/Geocoder/Provider/Mapzen.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/**
* @author Gary Gale <gary@vicchi.org>
*/
class Mapzen extends AbstractHttpProvider
final class Mapzen extends AbstractHttpProvider
{
/**
* @var string
Expand Down Expand Up @@ -69,7 +69,7 @@ public function geocode($address)

$query = sprintf(self::GEOCODE_ENDPOINT_URL, $this->scheme, urlencode($address), $this->apiKey, $this->getLimit());

return $this->executeQuery($query);
return $this->executeQuery($query);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Geocoder/Provider/MaxMind.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/**
* @author Andrea Cristaudo <andrea.cristaudo@gmail.com>
*/
class MaxMind extends AbstractHttpProvider implements Provider
final class MaxMind extends AbstractHttpProvider implements Provider
{
/**
* @var string Country, City, ISP and Organization
Expand Down
2 changes: 1 addition & 1 deletion src/Geocoder/Provider/MaxMindBinary.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Geocoder\Exception\NoResult;
use Geocoder\Exception\UnsupportedOperation;

class MaxMindBinary extends AbstractProvider implements Provider
final class MaxMindBinary extends AbstractProvider implements Provider
{
/**
* @var string
Expand Down
12 changes: 11 additions & 1 deletion src/Geocoder/Provider/Nominatim.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* @author Niklas Närhinen <niklas@narhinen.net>
*/
class Nominatim extends AbstractHttpProvider implements LocaleAwareProvider
final class Nominatim extends AbstractHttpProvider implements LocaleAwareProvider
{
use LocaleTrait;

Expand All @@ -26,6 +26,16 @@ class Nominatim extends AbstractHttpProvider implements LocaleAwareProvider
*/
private $rootUrl;

/**
* @param HttpClient $client
* @param string|null $locale
* @return Nominatim
*/
public static function withOpenStreetMapServer(HttpClient $client, $locale = null)
{
return new self($client, 'http://nominatim.openstreetmap.org', $locale);
}

/**
* @param HttpClient $client An HTTP adapter.
* @param string $rootUrl Root URL of the nominatim server
Expand Down
2 changes: 1 addition & 1 deletion src/Geocoder/Provider/OpenCage.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/**
* @author mtm <mtm@opencagedata.com>
*/
class OpenCage extends AbstractHttpProvider implements LocaleAwareProvider
final class OpenCage extends AbstractHttpProvider implements LocaleAwareProvider
{
/**
* @var string
Expand Down
Loading