From b1b7063d10f41d28794ab1cd3ba722bafebc8b3c Mon Sep 17 00:00:00 2001 From: Baachi Date: Mon, 18 Jan 2016 22:57:16 +0100 Subject: [PATCH 01/16] Implement httplug --- .puli/GeneratedPuliFactory.php | 85 +++++++ composer.json | 11 +- puli.json | 216 ++++++++++++++++++ .../Provider/AbstractHttpProvider.php | 22 +- src/Geocoder/Provider/ArcGISOnline.php | 12 +- src/Geocoder/Provider/BingMaps.php | 11 +- src/Geocoder/Provider/FreeGeoIp.php | 3 +- src/Geocoder/Provider/GeoIPs.php | 11 +- src/Geocoder/Provider/GeoPlugin.php | 3 +- src/Geocoder/Provider/Geonames.php | 11 +- src/Geocoder/Provider/GoogleMaps.php | 11 +- src/Geocoder/Provider/GoogleMapsBusiness.php | 6 +- src/Geocoder/Provider/HostIp.php | 3 +- src/Geocoder/Provider/IpInfoDb.php | 11 +- src/Geocoder/Provider/MapQuest.php | 11 +- src/Geocoder/Provider/MaxMind.php | 11 +- src/Geocoder/Provider/Nominatim.php | 12 +- src/Geocoder/Provider/OpenCage.php | 11 +- src/Geocoder/Provider/OpenStreetMap.php | 8 +- src/Geocoder/Provider/TomTom.php | 11 +- src/Geocoder/Provider/Yandex.php | 11 +- .../Geocoder/Tests/CachedResponseAdapter.php | 69 ------ tests/Geocoder/Tests/CachedResponseClient.php | 51 +++++ .../Tests/Provider/AbstractProviderTest.php | 19 +- tests/Geocoder/Tests/TestCase.php | 31 ++- 25 files changed, 476 insertions(+), 185 deletions(-) create mode 100644 .puli/GeneratedPuliFactory.php create mode 100644 puli.json delete mode 100644 tests/Geocoder/Tests/CachedResponseAdapter.php create mode 100644 tests/Geocoder/Tests/CachedResponseClient.php diff --git a/.puli/GeneratedPuliFactory.php b/.puli/GeneratedPuliFactory.php new file mode 100644 index 000000000..ed801ccfc --- /dev/null +++ b/.puli/GeneratedPuliFactory.php @@ -0,0 +1,85 @@ + @@ -18,27 +21,28 @@ class AbstractHttpProvider extends AbstractProvider { /** - * @var HttpAdapterInterface + * @var HttpClient */ - private $adapter; + private $client; /** - * @param HttpAdapterInterface $adapter An HTTP adapter + * @param HttpClient $client An HTTP adapter */ - public function __construct(HttpAdapterInterface $adapter) + public function __construct(HttpClient $client = null, MessageFactory $factory = null) { parent::__construct(); - $this->adapter = $adapter; + $this->client = $client ?: HttpClientDiscovery::find(); + $this->factory = $factory ?: MessageFactoryDiscovery::find(); } /** * Returns the HTTP adapter. * - * @return HttpAdapterInterface + * @return HttpClient */ - public function getAdapter() + public function getHttpClient() { - return $this->adapter; + return $this->client; } } diff --git a/src/Geocoder/Provider/ArcGISOnline.php b/src/Geocoder/Provider/ArcGISOnline.php index da3994c98..4b9331964 100644 --- a/src/Geocoder/Provider/ArcGISOnline.php +++ b/src/Geocoder/Provider/ArcGISOnline.php @@ -12,7 +12,7 @@ use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; -use Ivory\HttpAdapter\HttpAdapterInterface; +use Http\Client\HttpClientt; /** * @author ALKOUM Dorian @@ -40,13 +40,13 @@ class ArcGISOnline extends AbstractHttpProvider implements Provider private $protocol; /** - * @param HttpAdapterInterface $adapter An HTTP adapter + * @param HttpClient $client An HTTP adapter * @param string $sourceCountry Country biasing (optional) * @param bool $useSsl Whether to use an SSL connection (optional) */ - public function __construct(HttpAdapterInterface $adapter, $sourceCountry = null, $useSsl = false) + public function __construct(HttpClient $client, $sourceCountry = null, $useSsl = false) { - parent::__construct($adapter); + parent::__construct($client); $this->sourceCountry = $sourceCountry; $this->protocol = $useSsl ? 'https' : 'http'; @@ -167,8 +167,8 @@ private function buildQuery($query) */ private function executeQuery($query) { - $query = $this->buildQuery($query); - $content = (string) $this->getAdapter()->get($query)->getBody(); + $request = $this->request->sendRequest('GET', $this->buildQuery($query)); + $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { throw new NoResult(sprintf('Could not execute query "%s".', $query)); diff --git a/src/Geocoder/Provider/BingMaps.php b/src/Geocoder/Provider/BingMaps.php index 296755ead..ac6d5df5d 100644 --- a/src/Geocoder/Provider/BingMaps.php +++ b/src/Geocoder/Provider/BingMaps.php @@ -13,7 +13,7 @@ use Geocoder\Exception\InvalidCredentials; use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; -use Ivory\HttpAdapter\HttpAdapterInterface; +use Http\Client\HttpClientt; /** * @author David Guyon @@ -38,13 +38,13 @@ class BingMaps extends AbstractHttpProvider implements LocaleAwareProvider private $apiKey; /** - * @param HttpAdapterInterface $adapter An HTTP adapter + * @param HttpClient $client An HTTP adapter * @param string $apiKey An API key * @param string $locale A locale (optional) */ - public function __construct(HttpAdapterInterface $adapter, $apiKey, $locale = null) + public function __construct(HttpClient $client, $apiKey, $locale = null) { - parent::__construct($adapter); + parent::__construct($client); $this->apiKey = $apiKey; $this->locale = $locale; @@ -100,7 +100,8 @@ private function executeQuery($query) $query = sprintf('%s&culture=%s', $query, str_replace('_', '-', $this->getLocale())); } - $content = (string) $this->getAdapter()->get($query)->getBody(); + $request = $this->factory->createRequest('GET', $query); + $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { throw new NoResult(sprintf('Could not execute query "%s".', $query)); diff --git a/src/Geocoder/Provider/FreeGeoIp.php b/src/Geocoder/Provider/FreeGeoIp.php index 9f1aeb555..5462f75f2 100644 --- a/src/Geocoder/Provider/FreeGeoIp.php +++ b/src/Geocoder/Provider/FreeGeoIp.php @@ -65,7 +65,8 @@ public function getName() */ private function executeQuery($query) { - $content = (string) $this->getAdapter()->get($query)->getBody(); + $request = $this->factory->createRequest('GET', $query); + $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { throw new NoResult(sprintf('Could not execute query %s', $query)); diff --git a/src/Geocoder/Provider/GeoIPs.php b/src/Geocoder/Provider/GeoIPs.php index 438775555..4ae5547e3 100644 --- a/src/Geocoder/Provider/GeoIPs.php +++ b/src/Geocoder/Provider/GeoIPs.php @@ -15,7 +15,7 @@ use Geocoder\Exception\NoResult; use Geocoder\Exception\QuotaExceeded; use Geocoder\Exception\UnsupportedOperation; -use Ivory\HttpAdapter\HttpAdapterInterface; +use Http\Client\HttpClient; /** * @author Andrea Cristaudo @@ -50,12 +50,12 @@ class GeoIPs extends AbstractHttpProvider implements Provider private $apiKey; /** - * @param HttpAdapterInterface $adapter An HTTP adapter + * @param HttpClient $client An HTTP adapter * @param string $apiKey An API key */ - public function __construct(HttpAdapterInterface $adapter, $apiKey) + public function __construct(HttpClient $client, $apiKey) { - parent::__construct($adapter); + parent::__construct($client); $this->apiKey = $apiKey; } @@ -107,7 +107,8 @@ public function getName() */ private function executeQuery($query) { - $content = (string) $this->getAdapter()->get($query)->getBody(); + $request = $this->factory->createRequest($query); + $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { throw new NoResult(sprintf('Invalid response from GeoIPs API for query "%s".', $query)); diff --git a/src/Geocoder/Provider/GeoPlugin.php b/src/Geocoder/Provider/GeoPlugin.php index efe2172d0..5f56628f3 100644 --- a/src/Geocoder/Provider/GeoPlugin.php +++ b/src/Geocoder/Provider/GeoPlugin.php @@ -62,7 +62,8 @@ public function getName() */ private function executeQuery($query) { - $content = (string) $this->getAdapter()->get($query)->getBody(); + $request = $this->factory->createRequest($query); + $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { throw new NoResult(sprintf('Could not execute query "%s".', $query)); diff --git a/src/Geocoder/Provider/Geonames.php b/src/Geocoder/Provider/Geonames.php index c7fe3425f..9432b05f6 100644 --- a/src/Geocoder/Provider/Geonames.php +++ b/src/Geocoder/Provider/Geonames.php @@ -14,7 +14,7 @@ use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; use Geocoder\Model\AdminLevelCollection; -use Ivory\HttpAdapter\HttpAdapterInterface; +use Http\Client\HttpClient; /** * @author Giovanni Pirrotta @@ -39,13 +39,13 @@ class Geonames extends AbstractHttpProvider implements LocaleAwareProvider private $username; /** - * @param HttpAdapterInterface $adapter An HTTP adapter + * @param HttpClient $client An HTTP adapter * @param string $username Username login (Free registration at http://www.geonames.org/login) * @param string $locale A locale (optional) */ - public function __construct(HttpAdapterInterface $adapter, $username, $locale = null) + public function __construct(HttpClient $client, $username, $locale = null) { - parent::__construct($adapter); + parent::__construct($client); $this->username = $username; $this->locale = $locale; @@ -102,7 +102,8 @@ private function executeQuery($query) $query = sprintf('%s&lang=%s', $query, substr($this->getLocale(), 0, 2)); } - $content = (string) $this->getAdapter()->get($query)->getBody(); + $request = $this->factory->createRequest($query); + $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { throw new NoResult(sprintf('Could not execute query "%s".', $query)); diff --git a/src/Geocoder/Provider/GoogleMaps.php b/src/Geocoder/Provider/GoogleMaps.php index 031dceb76..d4641121e 100644 --- a/src/Geocoder/Provider/GoogleMaps.php +++ b/src/Geocoder/Provider/GoogleMaps.php @@ -15,7 +15,7 @@ use Geocoder\Exception\NoResult; use Geocoder\Exception\QuotaExceeded; use Geocoder\Exception\UnsupportedOperation; -use Ivory\HttpAdapter\HttpAdapterInterface; +use Http\Client\HttpClient; /** * @author William Durand @@ -50,15 +50,15 @@ class GoogleMaps extends AbstractHttpProvider implements LocaleAwareProvider private $apiKey; /** - * @param HttpAdapterInterface $adapter An HTTP adapter + * @param HttpClient $client An HTTP adapter * @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) */ - public function __construct(HttpAdapterInterface $adapter, $locale = null, $region = null, $useSsl = false, $apiKey = null) + public function __construct(HttpClient $client, $locale = null, $region = null, $useSsl = false, $apiKey = null) { - parent::__construct($adapter); + parent::__construct($client); $this->locale = $locale; $this->region = $region; @@ -136,7 +136,8 @@ protected function buildQuery($query) private function executeQuery($query) { $query = $this->buildQuery($query); - $content = (string) $this->getAdapter()->get($query)->getBody(); + $request = $this->factory->createRequest($query); + $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); // Throw exception if invalid clientID and/or privateKey used with GoogleMapsBusinessProvider if (strpos($content, "Provided 'signature' is not valid for the provided client ID") !== false) { diff --git a/src/Geocoder/Provider/GoogleMapsBusiness.php b/src/Geocoder/Provider/GoogleMapsBusiness.php index 889c58cf2..81995476e 100644 --- a/src/Geocoder/Provider/GoogleMapsBusiness.php +++ b/src/Geocoder/Provider/GoogleMapsBusiness.php @@ -10,7 +10,7 @@ namespace Geocoder\Provider; -use Ivory\HttpAdapter\HttpAdapterInterface; +use Http\Client\HttpClient; /** * Google Maps for Business @@ -31,14 +31,14 @@ class GoogleMapsBusiness extends GoogleMaps implements Provider private $privateKey; /** - * @param HttpAdapterInterface $adapter An HTTP adapter. + * @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) */ - public function __construct(HttpAdapterInterface $adapter, $clientId, $privateKey = null, $locale = null, $region = null, $useSsl = false) + public function __construct(HttpClient $client, $clientId, $privateKey = null, $locale = null, $region = null, $useSsl = false) { parent::__construct($adapter, $locale, $region, $useSsl); diff --git a/src/Geocoder/Provider/HostIp.php b/src/Geocoder/Provider/HostIp.php index d3c258af1..7c77aec5e 100644 --- a/src/Geocoder/Provider/HostIp.php +++ b/src/Geocoder/Provider/HostIp.php @@ -69,7 +69,8 @@ public function getName() */ private function executeQuery($query) { - $content = (string) $this->getAdapter()->get($query)->getBody(); + $request = $this->factory->createRequest($query); + $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); $data = json_decode($content, true); diff --git a/src/Geocoder/Provider/IpInfoDb.php b/src/Geocoder/Provider/IpInfoDb.php index a2ab2dc76..0f7ba5d82 100644 --- a/src/Geocoder/Provider/IpInfoDb.php +++ b/src/Geocoder/Provider/IpInfoDb.php @@ -14,7 +14,7 @@ use Geocoder\Exception\InvalidCredentials; use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; -use Ivory\HttpAdapter\HttpAdapterInterface; +use Http\Client\HttpClient; /** * @author William Durand @@ -42,15 +42,15 @@ class IpInfoDb extends AbstractHttpProvider implements Provider private $endpointUrl; /** - * @param HttpAdapterInterface $adapter An HTTP adapter. + * @param HttpClient $client An HTTP adapter. * @param string $apiKey An API key. * @param string $precision The endpoint precision. Either "city" or "country" (faster) * * @throws Geocoder\Exception\InvalidArgument */ - public function __construct(HttpAdapterInterface $adapter, $apiKey, $precision = 'city') + public function __construct(HttpClient $client, $apiKey, $precision = 'city') { - parent::__construct($adapter); + parent::__construct($client); $this->apiKey = $apiKey; switch ($precision) { @@ -121,7 +121,8 @@ public function getName() */ private function executeQuery($query) { - $content = (string) $this->getAdapter()->get($query)->getBody(); + $request = $this->factory->createRequest($query); + $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { throw new NoResult(sprintf('Could not execute query "%s".', $query)); diff --git a/src/Geocoder/Provider/MapQuest.php b/src/Geocoder/Provider/MapQuest.php index 0e37cac46..d9f7b9a0a 100644 --- a/src/Geocoder/Provider/MapQuest.php +++ b/src/Geocoder/Provider/MapQuest.php @@ -13,7 +13,7 @@ use Geocoder\Exception\InvalidCredentials; use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; -use Ivory\HttpAdapter\HttpAdapterInterface; +use Http\Client\HttpClient; /** * @author William Durand @@ -54,13 +54,13 @@ class MapQuest extends AbstractHttpProvider implements Provider private $apiKey; /** - * @param HttpAdapterInterface $adapter An HTTP adapter. + * @param HttpClient $client An HTTP adapter. * @param string $apiKey An API key. * @param bool $licensed True to use MapQuest's licensed endpoints, default is false to use the open endpoints (optional). */ - public function __construct(HttpAdapterInterface $adapter, $apiKey, $licensed = false) + public function __construct(HttpClient $client, $apiKey, $licensed = false) { - parent::__construct($adapter); + parent::__construct($client); $this->apiKey = $apiKey; $this->licensed = $licensed; @@ -120,7 +120,8 @@ public function getName() */ private function executeQuery($query) { - $content = (string) $this->getAdapter()->get($query)->getBody(); + $request = $this->factory->createRequest($query); + $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { throw new NoResult(sprintf('Could not execute query "%s".', $query)); diff --git a/src/Geocoder/Provider/MaxMind.php b/src/Geocoder/Provider/MaxMind.php index 5b5ffee3e..a2007801c 100644 --- a/src/Geocoder/Provider/MaxMind.php +++ b/src/Geocoder/Provider/MaxMind.php @@ -13,7 +13,7 @@ use Geocoder\Exception\InvalidCredentials; use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; -use Ivory\HttpAdapter\HttpAdapterInterface; +use Http\Client\HttpClient; /** * @author Andrea Cristaudo @@ -56,14 +56,14 @@ class MaxMind extends AbstractHttpProvider implements Provider private $useSsl = false; /** - * @param HttpAdapterInterface $adapter An HTTP adapter. + * @param HttpClient $client An HTTP adapter. * @param string $apiKey An API key. * @param string $service The specific Maxmind service to use (optional). * @param bool $useSsl Whether to use an SSL connection (optional). */ - public function __construct(HttpAdapterInterface $adapter, $apiKey, $service = self::CITY_EXTENDED_SERVICE, $useSsl = false) + public function __construct(HttpClient $client, $apiKey, $service = self::CITY_EXTENDED_SERVICE, $useSsl = false) { - parent::__construct($adapter); + parent::__construct($client); $this->apiKey = $apiKey; $this->service = $service; @@ -116,7 +116,8 @@ public function getName() */ private function executeQuery($query) { - $content = (string) $this->getAdapter()->get($query)->getBody(); + $request = $this->factory->createRequest($query); + $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); $fields = $this->fieldsForService($this->service); if (null === $content || '' === $content) { diff --git a/src/Geocoder/Provider/Nominatim.php b/src/Geocoder/Provider/Nominatim.php index d1a73d24b..01b2922eb 100644 --- a/src/Geocoder/Provider/Nominatim.php +++ b/src/Geocoder/Provider/Nominatim.php @@ -12,7 +12,7 @@ use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; -use Ivory\HttpAdapter\HttpAdapterInterface; +use Http\Client\HttpClient; /** * @author Niklas Närhinen @@ -27,13 +27,13 @@ class Nominatim extends AbstractHttpProvider implements LocaleAwareProvider private $rootUrl; /** - * @param HttpAdapterInterface $adapter An HTTP adapter. + * @param HttpClient $client An HTTP adapter. * @param string $rootUrl Root URL of the nominatim server * @param string $locale A locale (optional). */ - public function __construct(HttpAdapterInterface $adapter, $rootUrl, $locale = null) + public function __construct(HttpClient $client, $rootUrl, $locale = null) { - parent::__construct($adapter); + parent::__construct($client); $this->rootUrl = rtrim($rootUrl, '/'); $this->locale = $locale; @@ -163,7 +163,9 @@ private function executeQuery($query) $query = sprintf('%s&accept-language=%s', $query, $this->getLocale()); } - return (string) $this->getAdapter()->get($query)->getBody(); + $request = $this->factory->createRequest($query); + + return (string) $this->getHttpClient()->sendRequest($request)->getBody(); } private function getGeocodeEndpointUrl() diff --git a/src/Geocoder/Provider/OpenCage.php b/src/Geocoder/Provider/OpenCage.php index 5d48e9fc8..4f927726f 100644 --- a/src/Geocoder/Provider/OpenCage.php +++ b/src/Geocoder/Provider/OpenCage.php @@ -13,7 +13,7 @@ use Geocoder\Exception\QuotaExceeded; use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; -use Ivory\HttpAdapter\HttpAdapterInterface; +use Http\Client\HttpClient; /** * @author mtm @@ -38,14 +38,14 @@ class OpenCage extends AbstractHttpProvider implements LocaleAwareProvider private $apiKey; /** - * @param HttpAdapterInterface $adapter An HTTP adapter. + * @param HttpClient $client An HTTP adapter. * @param string $apiKey An API key. * @param bool $useSsl Whether to use an SSL connection (optional). * @param string|null $locale A locale (optional). */ - public function __construct(HttpAdapterInterface $adapter, $apiKey, $useSsl = false, $locale = null) + public function __construct(HttpClient $client, $apiKey, $useSsl = false, $locale = null) { - parent::__construct($adapter); + parent::__construct($client); $this->apiKey = $apiKey; $this->scheme = $useSsl ? 'https' : 'http'; @@ -99,7 +99,8 @@ private function executeQuery($query) $query = sprintf('%s&language=%s', $query, $this->getLocale()); } - $content = (string) $this->getAdapter()->get($query)->getBody(); + $request = $this->factory->createRequest($query); + $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { throw new NoResult(sprintf('Could not execute query "%s".', $query)); diff --git a/src/Geocoder/Provider/OpenStreetMap.php b/src/Geocoder/Provider/OpenStreetMap.php index 8097d3474..131f9e3d5 100644 --- a/src/Geocoder/Provider/OpenStreetMap.php +++ b/src/Geocoder/Provider/OpenStreetMap.php @@ -10,7 +10,7 @@ namespace Geocoder\Provider; -use Ivory\HttpAdapter\HttpAdapterInterface; +use Http\Client\HttpClient; /** * @author Niklas Närhinen @@ -23,12 +23,12 @@ class OpenStreetMap extends Nominatim const ROOT_URL = 'http://nominatim.openstreetmap.org'; /** - * @param HttpAdapterInterface $adapter An HTTP adapter. + * @param HttpClient $client An HTTP adapter. * @param string $locale A locale (optional). */ - public function __construct(HttpAdapterInterface $adapter, $locale = null) + public function __construct(HttpClient $client, $locale = null) { - parent::__construct($adapter, static::ROOT_URL, $locale); + parent::__construct($client, static::ROOT_URL, $locale); } /** diff --git a/src/Geocoder/Provider/TomTom.php b/src/Geocoder/Provider/TomTom.php index fefec969f..1689f04ba 100644 --- a/src/Geocoder/Provider/TomTom.php +++ b/src/Geocoder/Provider/TomTom.php @@ -13,7 +13,7 @@ use Geocoder\Exception\InvalidCredentials; use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; -use Ivory\HttpAdapter\HttpAdapterInterface; +use Http\Client\HttpClient; /** * @author Antoine Corcy @@ -38,13 +38,13 @@ class TomTom extends AbstractHttpProvider implements LocaleAwareProvider private $apiKey; /** - * @param HttpAdapterInterface $adapter An HTTP adapter. + * @param HttpClient $client An HTTP adapter. * @param string $apiKey An API key. * @param string $locale A locale (optional). */ - public function __construct(HttpAdapterInterface $adapter, $apiKey, $locale = null) + public function __construct(HttpClient $client, $apiKey, $locale = null) { - parent::__construct($adapter); + parent::__construct($client); $this->apiKey = $apiKey; $this->locale = $locale; @@ -102,7 +102,8 @@ private function executeQuery($query) $query = sprintf('%s&language=%s', $query, substr($this->getLocale(), 0, 2)); } - $content = (string) $this->getAdapter()->get($query)->getBody(); + $request = $this->factory->createRequest($query); + $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (false !== stripos($content, "Developer Inactive")) { throw new InvalidCredentials('Map API Key provided is not valid.'); diff --git a/src/Geocoder/Provider/Yandex.php b/src/Geocoder/Provider/Yandex.php index 2a3f08d4f..722b146a1 100644 --- a/src/Geocoder/Provider/Yandex.php +++ b/src/Geocoder/Provider/Yandex.php @@ -12,7 +12,7 @@ use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; -use Ivory\HttpAdapter\HttpAdapterInterface; +use Http\Client\HttpClient; /** * @author Antoine Corcy @@ -37,13 +37,13 @@ class Yandex extends AbstractHttpProvider implements LocaleAwareProvider private $toponym; /** - * @param HttpAdapterInterface $adapter An HTTP adapter. + * @param HttpClient $client An HTTP adapter. * @param string $locale A locale (optional). * @param string $toponym Toponym biasing only for reverse geocoding (optional). */ - public function __construct(HttpAdapterInterface $adapter, $locale = null, $toponym = null) + public function __construct(HttpClient $client, $locale = null, $toponym = null) { - parent::__construct($adapter); + parent::__construct($client); $this->locale = $locale; $this->toponym = $toponym; @@ -97,7 +97,8 @@ private function executeQuery($query) $query = sprintf('%s&results=%d', $query, $this->getLimit()); - $content = (string) $this->getAdapter()->get($query)->getBody(); + $request = $this->factory->createRequest($query); + $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); $json = (array) json_decode($content, true); if (empty($json) || isset($json['error']) || diff --git a/tests/Geocoder/Tests/CachedResponseAdapter.php b/tests/Geocoder/Tests/CachedResponseAdapter.php deleted file mode 100644 index 3ef242d67..000000000 --- a/tests/Geocoder/Tests/CachedResponseAdapter.php +++ /dev/null @@ -1,69 +0,0 @@ -adapter = $adapter; - $this->useCache = $useCache; - $this->apiKey = $apiKey; - $this->cacheDir = $cacheDir; - } - - /** - * {@inheritDoc} - */ - public function getName() - { - return 'cached_response'; - } - - /** - * {@inheritDoc} - */ - protected function sendInternalRequest(InternalRequestInterface $internalRequest) - { - $url = (string) $internalRequest->getUri(); - if ($this->apiKey) { - $url = str_replace($this->apiKey, '[apikey]', $url); - } - - $file = sprintf('%s/%s/%s', realpath(__DIR__ . '/../../'), $this->cacheDir, sha1($url)); - - if ($this->useCache && is_file($file) && is_readable($file)) { - $content = unserialize(file_get_contents($file)); - - if (!empty($content)) { - return $this->adapter - ->getConfiguration() - ->getMessageFactory() - ->createResponse(200, RequestInterface::PROTOCOL_VERSION_1_1, [], $content); - } - } - - $response = $this->adapter->get($url); - - if ($this->useCache) { - file_put_contents($file, serialize((string) $response->getBody())); - } - - return $response; - } -} diff --git a/tests/Geocoder/Tests/CachedResponseClient.php b/tests/Geocoder/Tests/CachedResponseClient.php new file mode 100644 index 000000000..eafdbe892 --- /dev/null +++ b/tests/Geocoder/Tests/CachedResponseClient.php @@ -0,0 +1,51 @@ +delegate = $delegate; + $this->useCache = $useCache; + $this->apiKey = $apiKey; + $this->cacheDir = $cacheDir; + } + + /** + * {@inheritDoc} + */ + public function sendRequest(RequestInterface $request) + { + $url = (string) $request->getUri(); + if ($this->apiKey) { + $url = str_replace($this->apiKey, '[apikey]', $url); + } + + $file = sprintf('%s/%s/%s', realpath(__DIR__ . '/../../'), $this->cacheDir, sha1($url)); + + if ($this->useCache && is_file($file) && is_readable($file)) { + return new Response(200, [], stream_for(fopen($file))); + } + + $response = $this->delegate->sendRequest($request); + + if ($this->useCache) { + file_put_contents($file, $response->getBody()->getContents()); + } + + return $response; + } +} diff --git a/tests/Geocoder/Tests/Provider/AbstractProviderTest.php b/tests/Geocoder/Tests/Provider/AbstractProviderTest.php index be774d220..9c16a1d32 100644 --- a/tests/Geocoder/Tests/Provider/AbstractProviderTest.php +++ b/tests/Geocoder/Tests/Provider/AbstractProviderTest.php @@ -3,10 +3,8 @@ namespace Geocoder\Tests\Provider; use Geocoder\Tests\TestCase; - +use Http\Mock\Client; use Geocoder\Provider\AbstractProvider; -use Ivory\HttpAdapter\AbstractHttpAdapter; -use Ivory\HttpAdapter\Message\InternalRequestInterface; /** * @author William Durand @@ -15,8 +13,7 @@ class AbstractProviderTest extends TestCase { public function testGetLocalhostDefaults() { - $adapter = new MockHttpAdapter(); - $provider = new MockProvider($adapter); + $provider = new MockProvider(new Client()); $result = $provider->getLocalhostDefaults(); $this->assertEquals(2, count($result)); @@ -32,15 +29,3 @@ public function getLocalhostDefaults() return parent::getLocalhostDefaults(); } } - -class MockHttpAdapter extends AbstractHttpAdapter -{ - public function getName() - { - return 'mock_http_adapter'; - } - - protected function sendInternalRequest(InternalRequestInterface $internalRequest) - { - } -} diff --git a/tests/Geocoder/Tests/TestCase.php b/tests/Geocoder/Tests/TestCase.php index d65fcaeeb..d0372fae3 100644 --- a/tests/Geocoder/Tests/TestCase.php +++ b/tests/Geocoder/Tests/TestCase.php @@ -3,8 +3,9 @@ namespace Geocoder\Tests; use Geocoder\Model\AddressFactory; -use Ivory\HttpAdapter\HttpAdapterInterface; -use Ivory\HttpAdapter\CurlHttpAdapter; +use Http\Client\HttpClient; +use Http\Mock\Client as MockClient; +use Http\Adapter\Guzzle6\Client as GuzzleClient; /** * @author William Durand @@ -33,13 +34,10 @@ protected function getMockAdapter($expects = null) ->method('getBody') ->will($this->returnValue($stream)); - $adapter = $this->getMock('Ivory\HttpAdapter\HttpAdapterInterface'); - $adapter - ->expects($expects) - ->method('get') - ->will($this->returnValue($response)); + $client = new MockClient(); + $client->addResponse($response); - return $adapter; + return $client; } /** @@ -60,24 +58,25 @@ protected function getMockAdapterReturns($returnValue) ->method('getBody') ->will($this->returnValue($body)); - $adapter = $this->getMock('Ivory\HttpAdapter\HttpAdapterInterface'); - $adapter - ->expects($this->once()) - ->method('get') - ->will($this->returnValue($response)); + $client = new MockClient(); + $client->addResponse($response); - return $adapter; + return $client; } /** * Because I was bored to fix the test suite because of * a change in a third-party API... * - * @return HttpAdapterInterface + * @return HttpClient */ protected function getAdapter($apiKey = null) { - return new CachedResponseAdapter(new CurlHttpAdapter(), $this->useCache(), $apiKey); + return new CachedResponseClient( + new GuzzleClient(), + $this->useCache(), + $apiKey + ); } /** From 294eccc9e8cb9ecc655552ac3c5939a32d2e9a0b Mon Sep 17 00:00:00 2001 From: Baachi Date: Mon, 1 Feb 2016 23:13:02 +0100 Subject: [PATCH 02/16] Fix tests and remove .puli from repo --- .gitignore | 1 + .puli/GeneratedPuliFactory.php | 85 ------------------- composer.json | 9 +- puli.json | 70 +++------------ src/Geocoder/Provider/ArcGISOnline.php | 5 +- src/Geocoder/Provider/BingMaps.php | 1 + src/Geocoder/Provider/GeoIPs.php | 2 +- src/Geocoder/Provider/GeoPlugin.php | 2 +- src/Geocoder/Provider/Geonames.php | 2 +- src/Geocoder/Provider/GoogleMaps.php | 2 +- src/Geocoder/Provider/GoogleMapsBusiness.php | 2 +- src/Geocoder/Provider/HostIp.php | 2 +- src/Geocoder/Provider/IpInfoDb.php | 2 +- src/Geocoder/Provider/MapQuest.php | 2 +- src/Geocoder/Provider/MaxMind.php | 2 +- src/Geocoder/Provider/Nominatim.php | 4 +- src/Geocoder/Provider/OpenCage.php | 2 +- src/Geocoder/Provider/TomTom.php | 2 +- src/Geocoder/Provider/Yandex.php | 2 +- tests/Geocoder/Tests/CachedResponseClient.php | 5 +- .../Tests/Provider/AbstractProviderTest.php | 3 +- .../Geocoder/Tests/Provider/GeonamesTest.php | 4 +- .../Geocoder/Tests/Provider/IpInfoDbTest.php | 4 +- tests/Geocoder/Tests/TestCase.php | 4 +- 24 files changed, 46 insertions(+), 173 deletions(-) delete mode 100644 .puli/GeneratedPuliFactory.php diff --git a/.gitignore b/.gitignore index edc927f26..5d5fa0e4a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ composer.lock composer.phar phpunit.xml php-cs-fixer.phar +.puli/ diff --git a/.puli/GeneratedPuliFactory.php b/.puli/GeneratedPuliFactory.php deleted file mode 100644 index ed801ccfc..000000000 --- a/.puli/GeneratedPuliFactory.php +++ /dev/null @@ -1,85 +0,0 @@ - @@ -167,7 +167,8 @@ private function buildQuery($query) */ private function executeQuery($query) { - $request = $this->request->sendRequest('GET', $this->buildQuery($query)); + $query = $this->buildQuery($query); + $request = $this->factory->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { diff --git a/src/Geocoder/Provider/BingMaps.php b/src/Geocoder/Provider/BingMaps.php index ac6d5df5d..03cf464e0 100644 --- a/src/Geocoder/Provider/BingMaps.php +++ b/src/Geocoder/Provider/BingMaps.php @@ -10,6 +10,7 @@ namespace Geocoder\Provider; +use Http\Client\HttpClient; use Geocoder\Exception\InvalidCredentials; use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; diff --git a/src/Geocoder/Provider/GeoIPs.php b/src/Geocoder/Provider/GeoIPs.php index 4ae5547e3..33bcb69db 100644 --- a/src/Geocoder/Provider/GeoIPs.php +++ b/src/Geocoder/Provider/GeoIPs.php @@ -107,7 +107,7 @@ public function getName() */ private function executeQuery($query) { - $request = $this->factory->createRequest($query); + $request = $this->factory->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { diff --git a/src/Geocoder/Provider/GeoPlugin.php b/src/Geocoder/Provider/GeoPlugin.php index 5f56628f3..c635abfae 100644 --- a/src/Geocoder/Provider/GeoPlugin.php +++ b/src/Geocoder/Provider/GeoPlugin.php @@ -62,7 +62,7 @@ public function getName() */ private function executeQuery($query) { - $request = $this->factory->createRequest($query); + $request = $this->factory->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { diff --git a/src/Geocoder/Provider/Geonames.php b/src/Geocoder/Provider/Geonames.php index 9432b05f6..b2dd94851 100644 --- a/src/Geocoder/Provider/Geonames.php +++ b/src/Geocoder/Provider/Geonames.php @@ -102,7 +102,7 @@ private function executeQuery($query) $query = sprintf('%s&lang=%s', $query, substr($this->getLocale(), 0, 2)); } - $request = $this->factory->createRequest($query); + $request = $this->factory->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { diff --git a/src/Geocoder/Provider/GoogleMaps.php b/src/Geocoder/Provider/GoogleMaps.php index d4641121e..a0c1c976d 100644 --- a/src/Geocoder/Provider/GoogleMaps.php +++ b/src/Geocoder/Provider/GoogleMaps.php @@ -136,7 +136,7 @@ protected function buildQuery($query) private function executeQuery($query) { $query = $this->buildQuery($query); - $request = $this->factory->createRequest($query); + $request = $this->factory->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); // Throw exception if invalid clientID and/or privateKey used with GoogleMapsBusinessProvider diff --git a/src/Geocoder/Provider/GoogleMapsBusiness.php b/src/Geocoder/Provider/GoogleMapsBusiness.php index 81995476e..35828b07b 100644 --- a/src/Geocoder/Provider/GoogleMapsBusiness.php +++ b/src/Geocoder/Provider/GoogleMapsBusiness.php @@ -40,7 +40,7 @@ class GoogleMapsBusiness extends GoogleMaps implements Provider */ public function __construct(HttpClient $client, $clientId, $privateKey = null, $locale = null, $region = null, $useSsl = false) { - parent::__construct($adapter, $locale, $region, $useSsl); + parent::__construct($client, $locale, $region, $useSsl); $this->clientId = $clientId; $this->privateKey = $privateKey; diff --git a/src/Geocoder/Provider/HostIp.php b/src/Geocoder/Provider/HostIp.php index 7c77aec5e..9eb9dc063 100644 --- a/src/Geocoder/Provider/HostIp.php +++ b/src/Geocoder/Provider/HostIp.php @@ -69,7 +69,7 @@ public function getName() */ private function executeQuery($query) { - $request = $this->factory->createRequest($query); + $request = $this->factory->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); $data = json_decode($content, true); diff --git a/src/Geocoder/Provider/IpInfoDb.php b/src/Geocoder/Provider/IpInfoDb.php index 0f7ba5d82..cae4bebcd 100644 --- a/src/Geocoder/Provider/IpInfoDb.php +++ b/src/Geocoder/Provider/IpInfoDb.php @@ -121,7 +121,7 @@ public function getName() */ private function executeQuery($query) { - $request = $this->factory->createRequest($query); + $request = $this->factory->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { diff --git a/src/Geocoder/Provider/MapQuest.php b/src/Geocoder/Provider/MapQuest.php index d9f7b9a0a..5e001ad12 100644 --- a/src/Geocoder/Provider/MapQuest.php +++ b/src/Geocoder/Provider/MapQuest.php @@ -120,7 +120,7 @@ public function getName() */ private function executeQuery($query) { - $request = $this->factory->createRequest($query); + $request = $this->factory->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { diff --git a/src/Geocoder/Provider/MaxMind.php b/src/Geocoder/Provider/MaxMind.php index a2007801c..db7b52a8e 100644 --- a/src/Geocoder/Provider/MaxMind.php +++ b/src/Geocoder/Provider/MaxMind.php @@ -116,7 +116,7 @@ public function getName() */ private function executeQuery($query) { - $request = $this->factory->createRequest($query); + $request = $this->factory->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); $fields = $this->fieldsForService($this->service); diff --git a/src/Geocoder/Provider/Nominatim.php b/src/Geocoder/Provider/Nominatim.php index 01b2922eb..ce832448b 100644 --- a/src/Geocoder/Provider/Nominatim.php +++ b/src/Geocoder/Provider/Nominatim.php @@ -163,8 +163,8 @@ private function executeQuery($query) $query = sprintf('%s&accept-language=%s', $query, $this->getLocale()); } - $request = $this->factory->createRequest($query); - + $request = $this->factory->createRequest('GET', $query); + return (string) $this->getHttpClient()->sendRequest($request)->getBody(); } diff --git a/src/Geocoder/Provider/OpenCage.php b/src/Geocoder/Provider/OpenCage.php index 4f927726f..88cc4fd45 100644 --- a/src/Geocoder/Provider/OpenCage.php +++ b/src/Geocoder/Provider/OpenCage.php @@ -99,7 +99,7 @@ private function executeQuery($query) $query = sprintf('%s&language=%s', $query, $this->getLocale()); } - $request = $this->factory->createRequest($query); + $request = $this->factory->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { diff --git a/src/Geocoder/Provider/TomTom.php b/src/Geocoder/Provider/TomTom.php index 1689f04ba..5f5483c1f 100644 --- a/src/Geocoder/Provider/TomTom.php +++ b/src/Geocoder/Provider/TomTom.php @@ -102,7 +102,7 @@ private function executeQuery($query) $query = sprintf('%s&language=%s', $query, substr($this->getLocale(), 0, 2)); } - $request = $this->factory->createRequest($query); + $request = $this->factory->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (false !== stripos($content, "Developer Inactive")) { diff --git a/src/Geocoder/Provider/Yandex.php b/src/Geocoder/Provider/Yandex.php index 722b146a1..6ad55e687 100644 --- a/src/Geocoder/Provider/Yandex.php +++ b/src/Geocoder/Provider/Yandex.php @@ -97,7 +97,7 @@ private function executeQuery($query) $query = sprintf('%s&results=%d', $query, $this->getLimit()); - $request = $this->factory->createRequest($query); + $request = $this->factory->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); $json = (array) json_decode($content, true); diff --git a/tests/Geocoder/Tests/CachedResponseClient.php b/tests/Geocoder/Tests/CachedResponseClient.php index eafdbe892..97cc212fd 100644 --- a/tests/Geocoder/Tests/CachedResponseClient.php +++ b/tests/Geocoder/Tests/CachedResponseClient.php @@ -4,7 +4,8 @@ use Http\Client\HttpClient; use Psr\Http\Message\RequestInterface; -use Http\Discovery\MessageFactoryDiscovery; +use GuzzleHttp\Psr7\Response; +use GuzzleHttp\Psr7; class CachedResponseClient implements HttpClient { @@ -37,7 +38,7 @@ public function sendRequest(RequestInterface $request) $file = sprintf('%s/%s/%s', realpath(__DIR__ . '/../../'), $this->cacheDir, sha1($url)); if ($this->useCache && is_file($file) && is_readable($file)) { - return new Response(200, [], stream_for(fopen($file))); + return new Response(200, [], Psr7\stream_for(unserialize(file_get_contents($file)))); } $response = $this->delegate->sendRequest($request); diff --git a/tests/Geocoder/Tests/Provider/AbstractProviderTest.php b/tests/Geocoder/Tests/Provider/AbstractProviderTest.php index 9c16a1d32..36df0f355 100644 --- a/tests/Geocoder/Tests/Provider/AbstractProviderTest.php +++ b/tests/Geocoder/Tests/Provider/AbstractProviderTest.php @@ -13,7 +13,8 @@ class AbstractProviderTest extends TestCase { public function testGetLocalhostDefaults() { - $provider = new MockProvider(new Client()); + $client = $this->prophesize('Http\Client\HttpClient'); + $provider = new MockProvider($client->reveal()); $result = $provider->getLocalhostDefaults(); $this->assertEquals(2, count($result)); diff --git a/tests/Geocoder/Tests/Provider/GeonamesTest.php b/tests/Geocoder/Tests/Provider/GeonamesTest.php index d54cedf18..b3c779a76 100644 --- a/tests/Geocoder/Tests/Provider/GeonamesTest.php +++ b/tests/Geocoder/Tests/Provider/GeonamesTest.php @@ -19,7 +19,7 @@ public function testGetName() */ public function testGeocodeWithNullUsername() { - $provider = new Geonames($this->getMock('\Ivory\HttpAdapter\HttpAdapterInterface'), null); + $provider = new Geonames($this->getMock('Http\Client\HttpClient'), null); $provider->geocode('foo'); } @@ -29,7 +29,7 @@ public function testGeocodeWithNullUsername() */ public function testReverseWithNullUsername() { - $provider = new Geonames($this->getMock('\Ivory\HttpAdapter\HttpAdapterInterface'), null); + $provider = new Geonames($this->getMock('Http\Client\HttpClient'), null); $provider->reverse(1,2); } diff --git a/tests/Geocoder/Tests/Provider/IpInfoDbTest.php b/tests/Geocoder/Tests/Provider/IpInfoDbTest.php index 80897f3fc..fadd0e861 100644 --- a/tests/Geocoder/Tests/Provider/IpInfoDbTest.php +++ b/tests/Geocoder/Tests/Provider/IpInfoDbTest.php @@ -27,7 +27,7 @@ public function testGetName() */ public function testGetDataWithNullApiKey() { - $provider = new IpInfoDb($this->getMock('\Ivory\HttpAdapter\HttpAdapterInterface'), null); + $provider = new IpInfoDb($this->getMock('Http\Client\HttpClient'), null); $provider->geocode('foo'); } @@ -196,7 +196,7 @@ public function testGetGeocodedDataWithCountryPrecision() */ public function testReverse() { - $provider = new IpInfoDb($this->getMock('\Ivory\HttpAdapter\HttpAdapterInterface'), 'api_key'); + $provider = new IpInfoDb($this->getMock('Http\Client\HttpClient'), 'api_key'); $provider->reverse(null, null); } } diff --git a/tests/Geocoder/Tests/TestCase.php b/tests/Geocoder/Tests/TestCase.php index d0372fae3..4b89cfd33 100644 --- a/tests/Geocoder/Tests/TestCase.php +++ b/tests/Geocoder/Tests/TestCase.php @@ -28,7 +28,7 @@ protected function getMockAdapter($expects = null) ->method('__toString') ->will($this->returnValue('')); - $response = $this->getMock('Psr\Http\Message\MessageInterface'); + $response = $this->getMock('Psr\Http\Message\ResponseInterface'); $response ->expects($this->any()) ->method('getBody') @@ -52,7 +52,7 @@ protected function getMockAdapterReturns($returnValue) ->method('__toString') ->will($this->returnValue((string) $returnValue)); - $response = $this->getMock('Psr\Http\Message\MessageInterface'); + $response = $this->getMock('Psr\Http\Message\ResponseInterface'); $response ->expects($this->once()) ->method('getBody') From a2b1d60fe9347c093d8f5ab9acf5eac8e0b9dc45 Mon Sep 17 00:00:00 2001 From: Baachi Date: Mon, 1 Feb 2016 23:22:46 +0100 Subject: [PATCH 03/16] Remove php 5.4 --- .travis.yml | 3 +-- puli.json | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index c4cd39b92..e69055484 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,6 @@ env: - deps="" php: - - 5.4 - 5.5 - 5.6 - 7.0 @@ -21,7 +20,7 @@ php: matrix: fast_finish: true include: - - php: 5.4 + - php: 5.5 env: deps="low" before_script: diff --git a/puli.json b/puli.json index b88998b7d..9bb3de40b 100644 --- a/puli.json +++ b/puli.json @@ -66,8 +66,7 @@ }, "php-http/httplug": { "install-path": "vendor/php-http/httplug", - "installer": "composer", - "env": "dev" + "installer": "composer" }, "php-http/message": { "install-path": "vendor/php-http/message", @@ -85,8 +84,7 @@ }, "php-http/promise": { "install-path": "vendor/php-http/promise", - "installer": "composer", - "env": "dev" + "installer": "composer" }, "psr/http-message": { "install-path": "vendor/psr/http-message", From 27dcf694283a8f9d29f2854daae0993574b4e214 Mon Sep 17 00:00:00 2001 From: Baachi Date: Mon, 1 Feb 2016 23:35:06 +0100 Subject: [PATCH 04/16] Rename to --- src/Geocoder/Provider/AbstractHttpProvider.php | 9 +++++++-- src/Geocoder/Provider/ArcGISOnline.php | 2 +- src/Geocoder/Provider/BingMaps.php | 2 +- src/Geocoder/Provider/FreeGeoIp.php | 2 +- src/Geocoder/Provider/GeoIPs.php | 2 +- src/Geocoder/Provider/GeoPlugin.php | 2 +- src/Geocoder/Provider/Geonames.php | 2 +- src/Geocoder/Provider/GoogleMaps.php | 2 +- src/Geocoder/Provider/HostIp.php | 2 +- src/Geocoder/Provider/IpInfoDb.php | 2 +- src/Geocoder/Provider/MapQuest.php | 2 +- src/Geocoder/Provider/MaxMind.php | 2 +- src/Geocoder/Provider/Nominatim.php | 2 +- src/Geocoder/Provider/OpenCage.php | 2 +- src/Geocoder/Provider/TomTom.php | 2 +- src/Geocoder/Provider/Yandex.php | 2 +- 16 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/Geocoder/Provider/AbstractHttpProvider.php b/src/Geocoder/Provider/AbstractHttpProvider.php index ca485b112..18e738524 100644 --- a/src/Geocoder/Provider/AbstractHttpProvider.php +++ b/src/Geocoder/Provider/AbstractHttpProvider.php @@ -23,7 +23,12 @@ class AbstractHttpProvider extends AbstractProvider /** * @var HttpClient */ - private $client; + protected $client; + + /** + * @var MessageFactory + */ + protected $messageFactory; /** * @param HttpClient $client An HTTP adapter @@ -33,7 +38,7 @@ public function __construct(HttpClient $client = null, MessageFactory $factory = parent::__construct(); $this->client = $client ?: HttpClientDiscovery::find(); - $this->factory = $factory ?: MessageFactoryDiscovery::find(); + $this->messageFactory = $factory ?: MessageFactoryDiscovery::find(); } /** diff --git a/src/Geocoder/Provider/ArcGISOnline.php b/src/Geocoder/Provider/ArcGISOnline.php index 41f82a5b6..b214e694e 100644 --- a/src/Geocoder/Provider/ArcGISOnline.php +++ b/src/Geocoder/Provider/ArcGISOnline.php @@ -168,7 +168,7 @@ private function buildQuery($query) private function executeQuery($query) { $query = $this->buildQuery($query); - $request = $this->factory->createRequest('GET', $query); + $request = $this->messageFactory->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { diff --git a/src/Geocoder/Provider/BingMaps.php b/src/Geocoder/Provider/BingMaps.php index 03cf464e0..70e2b0e03 100644 --- a/src/Geocoder/Provider/BingMaps.php +++ b/src/Geocoder/Provider/BingMaps.php @@ -101,7 +101,7 @@ private function executeQuery($query) $query = sprintf('%s&culture=%s', $query, str_replace('_', '-', $this->getLocale())); } - $request = $this->factory->createRequest('GET', $query); + $request = $this->messageFactory->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { diff --git a/src/Geocoder/Provider/FreeGeoIp.php b/src/Geocoder/Provider/FreeGeoIp.php index 5462f75f2..e40dc68cf 100644 --- a/src/Geocoder/Provider/FreeGeoIp.php +++ b/src/Geocoder/Provider/FreeGeoIp.php @@ -65,7 +65,7 @@ public function getName() */ private function executeQuery($query) { - $request = $this->factory->createRequest('GET', $query); + $request = $this->messageFactory->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { diff --git a/src/Geocoder/Provider/GeoIPs.php b/src/Geocoder/Provider/GeoIPs.php index 33bcb69db..c665bf95e 100644 --- a/src/Geocoder/Provider/GeoIPs.php +++ b/src/Geocoder/Provider/GeoIPs.php @@ -107,7 +107,7 @@ public function getName() */ private function executeQuery($query) { - $request = $this->factory->createRequest('GET', $query); + $request = $this->messageFactory->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { diff --git a/src/Geocoder/Provider/GeoPlugin.php b/src/Geocoder/Provider/GeoPlugin.php index c635abfae..a5e173016 100644 --- a/src/Geocoder/Provider/GeoPlugin.php +++ b/src/Geocoder/Provider/GeoPlugin.php @@ -62,7 +62,7 @@ public function getName() */ private function executeQuery($query) { - $request = $this->factory->createRequest('GET', $query); + $request = $this->messageFactory->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { diff --git a/src/Geocoder/Provider/Geonames.php b/src/Geocoder/Provider/Geonames.php index b2dd94851..9fc2410f4 100644 --- a/src/Geocoder/Provider/Geonames.php +++ b/src/Geocoder/Provider/Geonames.php @@ -102,7 +102,7 @@ private function executeQuery($query) $query = sprintf('%s&lang=%s', $query, substr($this->getLocale(), 0, 2)); } - $request = $this->factory->createRequest('GET', $query); + $request = $this->messageFactory->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { diff --git a/src/Geocoder/Provider/GoogleMaps.php b/src/Geocoder/Provider/GoogleMaps.php index a0c1c976d..0274d20e5 100644 --- a/src/Geocoder/Provider/GoogleMaps.php +++ b/src/Geocoder/Provider/GoogleMaps.php @@ -136,7 +136,7 @@ protected function buildQuery($query) private function executeQuery($query) { $query = $this->buildQuery($query); - $request = $this->factory->createRequest('GET', $query); + $request = $this->messageFactory->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); // Throw exception if invalid clientID and/or privateKey used with GoogleMapsBusinessProvider diff --git a/src/Geocoder/Provider/HostIp.php b/src/Geocoder/Provider/HostIp.php index 9eb9dc063..a91a4e28f 100644 --- a/src/Geocoder/Provider/HostIp.php +++ b/src/Geocoder/Provider/HostIp.php @@ -69,7 +69,7 @@ public function getName() */ private function executeQuery($query) { - $request = $this->factory->createRequest('GET', $query); + $request = $this->messageFactory->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); $data = json_decode($content, true); diff --git a/src/Geocoder/Provider/IpInfoDb.php b/src/Geocoder/Provider/IpInfoDb.php index cae4bebcd..c465b97c7 100644 --- a/src/Geocoder/Provider/IpInfoDb.php +++ b/src/Geocoder/Provider/IpInfoDb.php @@ -121,7 +121,7 @@ public function getName() */ private function executeQuery($query) { - $request = $this->factory->createRequest('GET', $query); + $request = $this->messageFactory->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { diff --git a/src/Geocoder/Provider/MapQuest.php b/src/Geocoder/Provider/MapQuest.php index 5e001ad12..0c5c60655 100644 --- a/src/Geocoder/Provider/MapQuest.php +++ b/src/Geocoder/Provider/MapQuest.php @@ -120,7 +120,7 @@ public function getName() */ private function executeQuery($query) { - $request = $this->factory->createRequest('GET', $query); + $request = $this->messageFactory->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { diff --git a/src/Geocoder/Provider/MaxMind.php b/src/Geocoder/Provider/MaxMind.php index db7b52a8e..487a9934f 100644 --- a/src/Geocoder/Provider/MaxMind.php +++ b/src/Geocoder/Provider/MaxMind.php @@ -116,7 +116,7 @@ public function getName() */ private function executeQuery($query) { - $request = $this->factory->createRequest('GET', $query); + $request = $this->messageFactory->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); $fields = $this->fieldsForService($this->service); diff --git a/src/Geocoder/Provider/Nominatim.php b/src/Geocoder/Provider/Nominatim.php index ce832448b..9042af9c9 100644 --- a/src/Geocoder/Provider/Nominatim.php +++ b/src/Geocoder/Provider/Nominatim.php @@ -163,7 +163,7 @@ private function executeQuery($query) $query = sprintf('%s&accept-language=%s', $query, $this->getLocale()); } - $request = $this->factory->createRequest('GET', $query); + $request = $this->messageFactory->createRequest('GET', $query); return (string) $this->getHttpClient()->sendRequest($request)->getBody(); } diff --git a/src/Geocoder/Provider/OpenCage.php b/src/Geocoder/Provider/OpenCage.php index 88cc4fd45..52d6364e9 100644 --- a/src/Geocoder/Provider/OpenCage.php +++ b/src/Geocoder/Provider/OpenCage.php @@ -99,7 +99,7 @@ private function executeQuery($query) $query = sprintf('%s&language=%s', $query, $this->getLocale()); } - $request = $this->factory->createRequest('GET', $query); + $request = $this->messageFactory->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { diff --git a/src/Geocoder/Provider/TomTom.php b/src/Geocoder/Provider/TomTom.php index 5f5483c1f..65a48b235 100644 --- a/src/Geocoder/Provider/TomTom.php +++ b/src/Geocoder/Provider/TomTom.php @@ -102,7 +102,7 @@ private function executeQuery($query) $query = sprintf('%s&language=%s', $query, substr($this->getLocale(), 0, 2)); } - $request = $this->factory->createRequest('GET', $query); + $request = $this->messageFactory->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (false !== stripos($content, "Developer Inactive")) { diff --git a/src/Geocoder/Provider/Yandex.php b/src/Geocoder/Provider/Yandex.php index 6ad55e687..46eda91df 100644 --- a/src/Geocoder/Provider/Yandex.php +++ b/src/Geocoder/Provider/Yandex.php @@ -97,7 +97,7 @@ private function executeQuery($query) $query = sprintf('%s&results=%d', $query, $this->getLimit()); - $request = $this->factory->createRequest('GET', $query); + $request = $this->messageFactory->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); $json = (array) json_decode($content, true); From 69965560854bceaa2c733bbbf7eef389eb08d410 Mon Sep 17 00:00:00 2001 From: Baachi Date: Mon, 1 Feb 2016 23:40:33 +0100 Subject: [PATCH 05/16] Add scrutinizr patches --- src/Geocoder/Provider/AbstractHttpProvider.php | 2 +- src/Geocoder/Provider/BingMaps.php | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Geocoder/Provider/AbstractHttpProvider.php b/src/Geocoder/Provider/AbstractHttpProvider.php index 18e738524..a8c519682 100644 --- a/src/Geocoder/Provider/AbstractHttpProvider.php +++ b/src/Geocoder/Provider/AbstractHttpProvider.php @@ -10,10 +10,10 @@ namespace Geocoder\Provider; -use Http\Client\HttpClient; use Http\Message\MessageFactory; use Http\Discovery\HttpClientDiscovery; use Http\Discovery\MessageFactoryDiscovery; +use Http\Client\HttpClient; /** * @author William Durand diff --git a/src/Geocoder/Provider/BingMaps.php b/src/Geocoder/Provider/BingMaps.php index 70e2b0e03..279602a28 100644 --- a/src/Geocoder/Provider/BingMaps.php +++ b/src/Geocoder/Provider/BingMaps.php @@ -10,11 +10,10 @@ namespace Geocoder\Provider; -use Http\Client\HttpClient; use Geocoder\Exception\InvalidCredentials; use Geocoder\Exception\NoResult; use Geocoder\Exception\UnsupportedOperation; -use Http\Client\HttpClientt; +use Http\Client\HttpClient; /** * @author David Guyon From 6ccb90797d42948e57cef9b6597ff69b1fdd1255 Mon Sep 17 00:00:00 2001 From: Baachi Date: Sat, 20 Feb 2016 10:59:39 +0100 Subject: [PATCH 06/16] Use explicit @beta statements --- composer.json | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 1f71ff516..3ffb25971 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,11 @@ "php-http/mock-client": "^0.2", "php-http/message": "^1.0", "php-http/guzzle6-adapter": "^1.0", - "php-http/discovery": "^0.7.0" + "php-http/discovery": "^0.7.0", + "puli/composer-plugin": "^1.0.0@beta", + "puli/discovery": "^1.0.0@beta", + "puli/repository": "^1.0.0@beta", + "puli/url-generator": "^1.0.0@beta" }, "suggest": { "ext-geoip": "Enabling the geoip extension allows you to use the MaxMindProvider.", @@ -33,7 +37,6 @@ "geoip2/geoip2": "If you are going to use the GeoIP2DatabaseProvider.", "symfony/stopwatch": "If you want to use the TimedGeocoder" }, - "minimum-stability": "beta", "autoload": { "psr-0": { "Geocoder": "src/" } }, From 1697ef422ac16f74897dda5e5e2794a77c200da4 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sun, 12 Jun 2016 16:22:09 +0200 Subject: [PATCH 07/16] Minor fixes --- puli.json | 164 ------------------ .../Provider/AbstractHttpProvider.php | 52 +++++- src/Geocoder/Provider/ArcGISOnline.php | 2 +- src/Geocoder/Provider/BingMaps.php | 2 +- src/Geocoder/Provider/FreeGeoIp.php | 2 +- src/Geocoder/Provider/GeoIPs.php | 2 +- src/Geocoder/Provider/GeoPlugin.php | 2 +- src/Geocoder/Provider/Geonames.php | 2 +- src/Geocoder/Provider/GoogleMaps.php | 2 +- src/Geocoder/Provider/HostIp.php | 2 +- src/Geocoder/Provider/IpInfoDb.php | 2 +- src/Geocoder/Provider/MapQuest.php | 2 +- src/Geocoder/Provider/MaxMind.php | 2 +- src/Geocoder/Provider/Nominatim.php | 2 +- src/Geocoder/Provider/OpenCage.php | 2 +- src/Geocoder/Provider/TomTom.php | 2 +- src/Geocoder/Provider/Yandex.php | 2 +- 17 files changed, 60 insertions(+), 186 deletions(-) delete mode 100644 puli.json diff --git a/puli.json b/puli.json deleted file mode 100644 index 9bb3de40b..000000000 --- a/puli.json +++ /dev/null @@ -1,164 +0,0 @@ -{ - "version": "1.0", - "name": "willdurand/geocoder", - "config": { - "bootstrap-file": "vendor/autoload.php" - }, - "packages": { - "clue/stream-filter": { - "install-path": "vendor/clue/stream-filter", - "installer": "composer", - "env": "dev" - }, - "geoip2/geoip2": { - "install-path": "vendor/geoip2/geoip2", - "installer": "composer", - "env": "dev" - }, - "guzzlehttp/guzzle": { - "install-path": "vendor/guzzlehttp/guzzle", - "installer": "composer", - "env": "dev" - }, - "guzzlehttp/promises": { - "install-path": "vendor/guzzlehttp/promises", - "installer": "composer", - "env": "dev" - }, - "guzzlehttp/psr7": { - "install-path": "vendor/guzzlehttp/psr7", - "installer": "composer", - "env": "dev" - }, - "igorw/get-in": { - "install-path": "vendor/igorw/get-in", - "installer": "composer" - }, - "justinrainbow/json-schema": { - "install-path": "vendor/justinrainbow/json-schema", - "installer": "composer", - "env": "dev" - }, - "maxmind-db/reader": { - "install-path": "vendor/maxmind-db/reader", - "installer": "composer", - "env": "dev" - }, - "maxmind/web-service-common": { - "install-path": "vendor/maxmind/web-service-common", - "installer": "composer", - "env": "dev" - }, - "php-http/client-common": { - "install-path": "vendor/php-http/client-common", - "installer": "composer", - "env": "dev" - }, - "php-http/discovery": { - "install-path": "vendor/php-http/discovery", - "installer": "composer", - "env": "dev" - }, - "php-http/guzzle6-adapter": { - "install-path": "vendor/php-http/guzzle6-adapter", - "installer": "composer", - "env": "dev" - }, - "php-http/httplug": { - "install-path": "vendor/php-http/httplug", - "installer": "composer" - }, - "php-http/message": { - "install-path": "vendor/php-http/message", - "installer": "composer", - "env": "dev" - }, - "php-http/message-factory": { - "install-path": "vendor/php-http/message-factory", - "installer": "composer" - }, - "php-http/mock-client": { - "install-path": "vendor/php-http/mock-client", - "installer": "composer", - "env": "dev" - }, - "php-http/promise": { - "install-path": "vendor/php-http/promise", - "installer": "composer" - }, - "psr/http-message": { - "install-path": "vendor/psr/http-message", - "installer": "composer" - }, - "psr/log": { - "install-path": "vendor/psr/log", - "installer": "composer", - "env": "dev" - }, - "puli/composer-plugin": { - "install-path": "vendor/puli/composer-plugin", - "installer": "composer", - "env": "dev" - }, - "puli/discovery": { - "install-path": "vendor/puli/discovery", - "installer": "composer", - "env": "dev" - }, - "puli/repository": { - "install-path": "vendor/puli/repository", - "installer": "composer", - "env": "dev" - }, - "puli/url-generator": { - "install-path": "vendor/puli/url-generator", - "installer": "composer", - "env": "dev" - }, - "ramsey/uuid": { - "install-path": "vendor/ramsey/uuid", - "installer": "composer", - "env": "dev" - }, - "seld/jsonlint": { - "install-path": "vendor/seld/jsonlint", - "installer": "composer", - "env": "dev" - }, - "symfony/process": { - "install-path": "vendor/symfony/process", - "installer": "composer", - "env": "dev" - }, - "symfony/stopwatch": { - "install-path": "vendor/symfony/stopwatch", - "installer": "composer", - "env": "dev" - }, - "webmozart/assert": { - "install-path": "vendor/webmozart/assert", - "installer": "composer", - "env": "dev" - }, - "webmozart/expression": { - "install-path": "vendor/webmozart/expression", - "installer": "composer", - "env": "dev" - }, - "webmozart/glob": { - "install-path": "vendor/webmozart/glob", - "installer": "composer", - "env": "dev" - }, - "webmozart/json": { - "install-path": "vendor/webmozart/json", - "installer": "composer", - "env": "dev" - }, - "webmozart/path-util": { - "install-path": "vendor/webmozart/path-util", - "installer": "composer", - "env": "dev" - } - } -} diff --git a/src/Geocoder/Provider/AbstractHttpProvider.php b/src/Geocoder/Provider/AbstractHttpProvider.php index a8c519682..7fcbe013e 100644 --- a/src/Geocoder/Provider/AbstractHttpProvider.php +++ b/src/Geocoder/Provider/AbstractHttpProvider.php @@ -23,22 +23,24 @@ class AbstractHttpProvider extends AbstractProvider /** * @var HttpClient */ - protected $client; + private $client; /** * @var MessageFactory */ - protected $messageFactory; + private $messageFactory; /** - * @param HttpClient $client An HTTP adapter + * + * @param HttpClient|null $client + * @param MessageFactory|null $factory */ - public function __construct(HttpClient $client = null, MessageFactory $factory = null) + public function __construct(HttpClient $client, MessageFactory $factory = null) { parent::__construct(); - $this->client = $client ?: HttpClientDiscovery::find(); - $this->messageFactory = $factory ?: MessageFactoryDiscovery::find(); + $this->client = $client; + $this->messageFactory = $factory; } /** @@ -46,8 +48,44 @@ public function __construct(HttpClient $client = null, MessageFactory $factory = * * @return HttpClient */ - public function getHttpClient() + protected function getHttpClient() { return $this->client; } + + /** + * @return MessageFactory + */ + protected function getMessageFactory() + { + if ($this->messageFactory === null) { + $this->messageFactory = MessageFactoryDiscovery::find(); + } + + return $this->messageFactory; + } + + /** + * @param HttpClient $client + * + * @return AbstractHttpProvider + */ + public function setClient(HttpClient $client) + { + $this->client = $client; + + return $this; + } + + /** + * @param MessageFactory $messageFactory + * + * @return AbstractHttpProvider + */ + public function setMessageFactory(MessageFactory $messageFactory) + { + $this->messageFactory = $messageFactory; + + return $this; + } } diff --git a/src/Geocoder/Provider/ArcGISOnline.php b/src/Geocoder/Provider/ArcGISOnline.php index b214e694e..9fdc5d104 100644 --- a/src/Geocoder/Provider/ArcGISOnline.php +++ b/src/Geocoder/Provider/ArcGISOnline.php @@ -168,7 +168,7 @@ private function buildQuery($query) private function executeQuery($query) { $query = $this->buildQuery($query); - $request = $this->messageFactory->createRequest('GET', $query); + $request = $this->getMessageFactory()->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { diff --git a/src/Geocoder/Provider/BingMaps.php b/src/Geocoder/Provider/BingMaps.php index 279602a28..d5ece7414 100644 --- a/src/Geocoder/Provider/BingMaps.php +++ b/src/Geocoder/Provider/BingMaps.php @@ -100,7 +100,7 @@ private function executeQuery($query) $query = sprintf('%s&culture=%s', $query, str_replace('_', '-', $this->getLocale())); } - $request = $this->messageFactory->createRequest('GET', $query); + $request = $this->getMessageFactory()->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { diff --git a/src/Geocoder/Provider/FreeGeoIp.php b/src/Geocoder/Provider/FreeGeoIp.php index e40dc68cf..6ccb0e99c 100644 --- a/src/Geocoder/Provider/FreeGeoIp.php +++ b/src/Geocoder/Provider/FreeGeoIp.php @@ -65,7 +65,7 @@ public function getName() */ private function executeQuery($query) { - $request = $this->messageFactory->createRequest('GET', $query); + $request = $this->getMessageFactory()->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { diff --git a/src/Geocoder/Provider/GeoIPs.php b/src/Geocoder/Provider/GeoIPs.php index c665bf95e..88549c2f0 100644 --- a/src/Geocoder/Provider/GeoIPs.php +++ b/src/Geocoder/Provider/GeoIPs.php @@ -107,7 +107,7 @@ public function getName() */ private function executeQuery($query) { - $request = $this->messageFactory->createRequest('GET', $query); + $request = $this->getMessageFactory()->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { diff --git a/src/Geocoder/Provider/GeoPlugin.php b/src/Geocoder/Provider/GeoPlugin.php index a5e173016..2330c1e25 100644 --- a/src/Geocoder/Provider/GeoPlugin.php +++ b/src/Geocoder/Provider/GeoPlugin.php @@ -62,7 +62,7 @@ public function getName() */ private function executeQuery($query) { - $request = $this->messageFactory->createRequest('GET', $query); + $request = $this->getMessageFactory()->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { diff --git a/src/Geocoder/Provider/Geonames.php b/src/Geocoder/Provider/Geonames.php index 9fc2410f4..1989b5fdf 100644 --- a/src/Geocoder/Provider/Geonames.php +++ b/src/Geocoder/Provider/Geonames.php @@ -102,7 +102,7 @@ private function executeQuery($query) $query = sprintf('%s&lang=%s', $query, substr($this->getLocale(), 0, 2)); } - $request = $this->messageFactory->createRequest('GET', $query); + $request = $this->getMessageFactory()->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { diff --git a/src/Geocoder/Provider/GoogleMaps.php b/src/Geocoder/Provider/GoogleMaps.php index 0274d20e5..551985e2f 100644 --- a/src/Geocoder/Provider/GoogleMaps.php +++ b/src/Geocoder/Provider/GoogleMaps.php @@ -136,7 +136,7 @@ protected function buildQuery($query) private function executeQuery($query) { $query = $this->buildQuery($query); - $request = $this->messageFactory->createRequest('GET', $query); + $request = $this->getMessageFactory()->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); // Throw exception if invalid clientID and/or privateKey used with GoogleMapsBusinessProvider diff --git a/src/Geocoder/Provider/HostIp.php b/src/Geocoder/Provider/HostIp.php index a91a4e28f..be9c31726 100644 --- a/src/Geocoder/Provider/HostIp.php +++ b/src/Geocoder/Provider/HostIp.php @@ -69,7 +69,7 @@ public function getName() */ private function executeQuery($query) { - $request = $this->messageFactory->createRequest('GET', $query); + $request = $this->getMessageFactory()->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); $data = json_decode($content, true); diff --git a/src/Geocoder/Provider/IpInfoDb.php b/src/Geocoder/Provider/IpInfoDb.php index c465b97c7..cc612a96e 100644 --- a/src/Geocoder/Provider/IpInfoDb.php +++ b/src/Geocoder/Provider/IpInfoDb.php @@ -121,7 +121,7 @@ public function getName() */ private function executeQuery($query) { - $request = $this->messageFactory->createRequest('GET', $query); + $request = $this->getMessageFactory()->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { diff --git a/src/Geocoder/Provider/MapQuest.php b/src/Geocoder/Provider/MapQuest.php index 0c5c60655..8cb07c20c 100644 --- a/src/Geocoder/Provider/MapQuest.php +++ b/src/Geocoder/Provider/MapQuest.php @@ -120,7 +120,7 @@ public function getName() */ private function executeQuery($query) { - $request = $this->messageFactory->createRequest('GET', $query); + $request = $this->getMessageFactory()->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { diff --git a/src/Geocoder/Provider/MaxMind.php b/src/Geocoder/Provider/MaxMind.php index 487a9934f..1ddaeeedf 100644 --- a/src/Geocoder/Provider/MaxMind.php +++ b/src/Geocoder/Provider/MaxMind.php @@ -116,7 +116,7 @@ public function getName() */ private function executeQuery($query) { - $request = $this->messageFactory->createRequest('GET', $query); + $request = $this->getMessageFactory()->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); $fields = $this->fieldsForService($this->service); diff --git a/src/Geocoder/Provider/Nominatim.php b/src/Geocoder/Provider/Nominatim.php index 9042af9c9..96bf06ca3 100644 --- a/src/Geocoder/Provider/Nominatim.php +++ b/src/Geocoder/Provider/Nominatim.php @@ -163,7 +163,7 @@ private function executeQuery($query) $query = sprintf('%s&accept-language=%s', $query, $this->getLocale()); } - $request = $this->messageFactory->createRequest('GET', $query); + $request = $this->getMessageFactory()->createRequest('GET', $query); return (string) $this->getHttpClient()->sendRequest($request)->getBody(); } diff --git a/src/Geocoder/Provider/OpenCage.php b/src/Geocoder/Provider/OpenCage.php index 52d6364e9..68acba505 100644 --- a/src/Geocoder/Provider/OpenCage.php +++ b/src/Geocoder/Provider/OpenCage.php @@ -99,7 +99,7 @@ private function executeQuery($query) $query = sprintf('%s&language=%s', $query, $this->getLocale()); } - $request = $this->messageFactory->createRequest('GET', $query); + $request = $this->getMessageFactory()->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (empty($content)) { diff --git a/src/Geocoder/Provider/TomTom.php b/src/Geocoder/Provider/TomTom.php index 65a48b235..79483a429 100644 --- a/src/Geocoder/Provider/TomTom.php +++ b/src/Geocoder/Provider/TomTom.php @@ -102,7 +102,7 @@ private function executeQuery($query) $query = sprintf('%s&language=%s', $query, substr($this->getLocale(), 0, 2)); } - $request = $this->messageFactory->createRequest('GET', $query); + $request = $this->getMessageFactory()->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); if (false !== stripos($content, "Developer Inactive")) { diff --git a/src/Geocoder/Provider/Yandex.php b/src/Geocoder/Provider/Yandex.php index 46eda91df..d172ef9e1 100644 --- a/src/Geocoder/Provider/Yandex.php +++ b/src/Geocoder/Provider/Yandex.php @@ -97,7 +97,7 @@ private function executeQuery($query) $query = sprintf('%s&results=%d', $query, $this->getLimit()); - $request = $this->messageFactory->createRequest('GET', $query); + $request = $this->getMessageFactory()->createRequest('GET', $query); $content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); $json = (array) json_decode($content, true); From ec9de735cc789497a1d987ec2aa807f17a246f5a Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sun, 12 Jun 2016 16:27:52 +0200 Subject: [PATCH 08/16] Updated dependencies --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 3ffb25971..3fb2c9f0e 100644 --- a/composer.json +++ b/composer.json @@ -17,15 +17,15 @@ "psr/http-message-implementation": "^1.0", "php-http/client-implementation": "^1.0", "php-http/message-factory": "^1.0", - "php-http/httplug": "^1.0" + "php-http/httplug": "^1.0", + "php-http/discovery": "^0.8" }, "require-dev": { "geoip2/geoip2": "~2.0", "symfony/stopwatch": "~2.5", - "php-http/mock-client": "^0.2", "php-http/message": "^1.0", "php-http/guzzle6-adapter": "^1.0", - "php-http/discovery": "^0.7.0", + "php-http/mock-client": "^0.3.0", "puli/composer-plugin": "^1.0.0@beta", "puli/discovery": "^1.0.0@beta", "puli/repository": "^1.0.0@beta", From dd23be6ad60adc6879ee7a82f75003100a70c036 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Wed, 29 Jun 2016 14:42:02 +0200 Subject: [PATCH 09/16] Doc update and use latest discovery --- README.md | 18 +++++++++--------- composer.json | 8 ++------ 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 5fb058598..0ad4e240b 100644 --- a/README.md +++ b/README.md @@ -73,8 +73,8 @@ since each HTTP-based provider implements [PSR-7](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md). ```php -$curl = new \Ivory\HttpAdapter\CurlHttpAdapter(); -$geocoder = new \Geocoder\Provider\GoogleMaps($curl); +$adapter = new \Http\Adapter\Guzzle6\Client(); +$geocoder = new \Geocoder\Provider\GoogleMaps($adapter); $geocoder->geocode(...); $geocoder->reverse(...); @@ -214,14 +214,14 @@ In order to talk to geocoding APIs, you need HTTP adapters. While it was part of the library in Geocoder 1.x and 2.x, Geocoder 3.x and upper now relies on the [PSR-7 Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md) -which defines how HTTP message should be implemented. Choose any library that -follows this PSR and implement the specified interfaces to use with Geocoder. +which defines how HTTP message should be implemented. You can use any library to send HTTP messages +that implements [php-http/client-implementation](https://packagist.org/providers/php-http/client-implementation). -As making choices is rather hard, Geocoder ships with the -[egeloen/http-adapter](https://github.com/egeloen/ivory-http-adapter) library by -default, but it is up to you to choose a different implementation. +To use Guzzle 6 you should run the follwing command: -**Note:** not all providers are HTTP-based. +``` +$ composer require php-http/guzzle6-adapter +``` ### Providers @@ -360,7 +360,7 @@ when a provider returns a result. The result is returned by `GoogleMaps` because ``` php $geocoder = new \Geocoder\ProviderAggregator(); -$adapter = new \Ivory\HttpAdapter\CurlHttpAdapter(); +$adapter = new \Http\Adapter\Guzzle6\Client(); $chain = new \Geocoder\Provider\Chain([ new \Geocoder\Provider\FreeGeoIp($adapter), diff --git a/composer.json b/composer.json index 3fb2c9f0e..23b302503 100644 --- a/composer.json +++ b/composer.json @@ -18,18 +18,14 @@ "php-http/client-implementation": "^1.0", "php-http/message-factory": "^1.0", "php-http/httplug": "^1.0", - "php-http/discovery": "^0.8" + "php-http/discovery": "^0.9" }, "require-dev": { "geoip2/geoip2": "~2.0", "symfony/stopwatch": "~2.5", "php-http/message": "^1.0", "php-http/guzzle6-adapter": "^1.0", - "php-http/mock-client": "^0.3.0", - "puli/composer-plugin": "^1.0.0@beta", - "puli/discovery": "^1.0.0@beta", - "puli/repository": "^1.0.0@beta", - "puli/url-generator": "^1.0.0@beta" + "php-http/mock-client": "^0.3.0" }, "suggest": { "ext-geoip": "Enabling the geoip extension allows you to use the MaxMindProvider.", From 454471ad6285875c64e0c545f5b4766bc9b52bfd Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Wed, 29 Jun 2016 17:37:49 +0200 Subject: [PATCH 10/16] Make sure we using phpuinit 4 --- .travis.yml | 2 +- composer.json | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e69055484..1c6b940b1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,4 +30,4 @@ before_script: - if [ "$deps" = "" ]; then composer install --prefer-dist --no-interaction; fi - if [ "$TRAVIS_PHP_VERSION" == "7.0" ]; then composer require "geoip/geoip"; fi -script: phpunit --coverage-text +script: ./vendor/bin/phpunit --coverage-text diff --git a/composer.json b/composer.json index 23b302503..2aa17cbb0 100644 --- a/composer.json +++ b/composer.json @@ -21,6 +21,7 @@ "php-http/discovery": "^0.9" }, "require-dev": { + "phpunit/phpunit": "^4.8", "geoip2/geoip2": "~2.0", "symfony/stopwatch": "~2.5", "php-http/message": "^1.0", From a514e08ac2fb4cfa4239fcdfb7cd723e35878b85 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Wed, 29 Jun 2016 17:44:54 +0200 Subject: [PATCH 11/16] updating deps --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2aa17cbb0..db5762bb9 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "igorw/get-in": "~1.0", "psr/http-message-implementation": "^1.0", "php-http/client-implementation": "^1.0", - "php-http/message-factory": "^1.0", + "php-http/message-factory": "^1.0.2", "php-http/httplug": "^1.0", "php-http/discovery": "^0.9" }, From 27eba31c7320e84181c053f2c68214b639e41e60 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sun, 10 Jul 2016 23:10:20 +0200 Subject: [PATCH 12/16] typo --- src/Geocoder/Provider/AbstractHttpProvider.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Geocoder/Provider/AbstractHttpProvider.php b/src/Geocoder/Provider/AbstractHttpProvider.php index 7fcbe013e..ed2720443 100644 --- a/src/Geocoder/Provider/AbstractHttpProvider.php +++ b/src/Geocoder/Provider/AbstractHttpProvider.php @@ -31,8 +31,7 @@ class AbstractHttpProvider extends AbstractProvider private $messageFactory; /** - * - * @param HttpClient|null $client + * @param HttpClient $client * @param MessageFactory|null $factory */ public function __construct(HttpClient $client, MessageFactory $factory = null) From 510cfbc051f421372061461006df9865586af771 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 18 Jul 2016 12:16:43 +0200 Subject: [PATCH 13/16] Using discovery 1.0 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index db5762bb9..12ba76b30 100644 --- a/composer.json +++ b/composer.json @@ -12,13 +12,13 @@ } ], "require": { - "php": "^5.4|^7.0", + "php": "^5.5 || ^7.0", "igorw/get-in": "~1.0", "psr/http-message-implementation": "^1.0", "php-http/client-implementation": "^1.0", "php-http/message-factory": "^1.0.2", "php-http/httplug": "^1.0", - "php-http/discovery": "^0.9" + "php-http/discovery": "^1.0" }, "require-dev": { "phpunit/phpunit": "^4.8", From 45a3ecf213529b5b1e6508068ffa941a4e052bc2 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 18 Jul 2016 12:38:54 +0200 Subject: [PATCH 14/16] Syntax update to make travis run again --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 12ba76b30..8122ff7f7 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ ], "require": { "php": "^5.5 || ^7.0", - "igorw/get-in": "~1.0", + "igorw/get-in": "^1.0", "psr/http-message-implementation": "^1.0", "php-http/client-implementation": "^1.0", "php-http/message-factory": "^1.0.2", From 056dce17c1d7d4b192343c9358fa3f0c13e65274 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 16 Aug 2016 17:36:57 +0200 Subject: [PATCH 15/16] Fixed doc block alignment --- src/Geocoder/Provider/AbstractHttpProvider.php | 2 +- src/Geocoder/Provider/ArcGISOnline.php | 6 +++--- src/Geocoder/Provider/BingMaps.php | 4 ++-- src/Geocoder/Provider/GeoIPs.php | 2 +- src/Geocoder/Provider/Geonames.php | 6 +++--- src/Geocoder/Provider/GoogleMaps.php | 8 ++++---- src/Geocoder/Provider/GoogleMapsBusiness.php | 12 ++++++------ src/Geocoder/Provider/IpInfoDb.php | 8 ++++---- src/Geocoder/Provider/MapQuest.php | 6 +++--- src/Geocoder/Provider/MaxMind.php | 8 ++++---- src/Geocoder/Provider/Nominatim.php | 6 +++--- src/Geocoder/Provider/OpenCage.php | 8 ++++---- src/Geocoder/Provider/OpenStreetMap.php | 2 +- src/Geocoder/Provider/TomTom.php | 4 ++-- src/Geocoder/Provider/Yandex.php | 6 +++--- 15 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/Geocoder/Provider/AbstractHttpProvider.php b/src/Geocoder/Provider/AbstractHttpProvider.php index ed2720443..38f9e4cb1 100644 --- a/src/Geocoder/Provider/AbstractHttpProvider.php +++ b/src/Geocoder/Provider/AbstractHttpProvider.php @@ -31,7 +31,7 @@ class AbstractHttpProvider extends AbstractProvider private $messageFactory; /** - * @param HttpClient $client + * @param HttpClient $client * @param MessageFactory|null $factory */ public function __construct(HttpClient $client, MessageFactory $factory = null) diff --git a/src/Geocoder/Provider/ArcGISOnline.php b/src/Geocoder/Provider/ArcGISOnline.php index 9fdc5d104..1a1378abc 100644 --- a/src/Geocoder/Provider/ArcGISOnline.php +++ b/src/Geocoder/Provider/ArcGISOnline.php @@ -40,9 +40,9 @@ class ArcGISOnline extends AbstractHttpProvider implements Provider private $protocol; /** - * @param HttpClient $client An HTTP adapter - * @param string $sourceCountry Country biasing (optional) - * @param bool $useSsl Whether to use an SSL connection (optional) + * @param HttpClient $client An HTTP adapter + * @param string $sourceCountry Country biasing (optional) + * @param bool $useSsl Whether to use an SSL connection (optional) */ public function __construct(HttpClient $client, $sourceCountry = null, $useSsl = false) { diff --git a/src/Geocoder/Provider/BingMaps.php b/src/Geocoder/Provider/BingMaps.php index d5ece7414..38896617a 100644 --- a/src/Geocoder/Provider/BingMaps.php +++ b/src/Geocoder/Provider/BingMaps.php @@ -39,8 +39,8 @@ class BingMaps extends AbstractHttpProvider implements LocaleAwareProvider /** * @param HttpClient $client An HTTP adapter - * @param string $apiKey An API key - * @param string $locale A locale (optional) + * @param string $apiKey An API key + * @param string $locale A locale (optional) */ public function __construct(HttpClient $client, $apiKey, $locale = null) { diff --git a/src/Geocoder/Provider/GeoIPs.php b/src/Geocoder/Provider/GeoIPs.php index 88549c2f0..7eac8963c 100644 --- a/src/Geocoder/Provider/GeoIPs.php +++ b/src/Geocoder/Provider/GeoIPs.php @@ -51,7 +51,7 @@ class GeoIPs extends AbstractHttpProvider implements Provider /** * @param HttpClient $client An HTTP adapter - * @param string $apiKey An API key + * @param string $apiKey An API key */ public function __construct(HttpClient $client, $apiKey) { diff --git a/src/Geocoder/Provider/Geonames.php b/src/Geocoder/Provider/Geonames.php index 1989b5fdf..45b537fe9 100644 --- a/src/Geocoder/Provider/Geonames.php +++ b/src/Geocoder/Provider/Geonames.php @@ -39,9 +39,9 @@ class Geonames extends AbstractHttpProvider implements LocaleAwareProvider private $username; /** - * @param HttpClient $client An HTTP adapter - * @param string $username Username login (Free registration at http://www.geonames.org/login) - * @param string $locale A locale (optional) + * @param HttpClient $client An HTTP adapter + * @param string $username Username login (Free registration at http://www.geonames.org/login) + * @param string $locale A locale (optional) */ public function __construct(HttpClient $client, $username, $locale = null) { diff --git a/src/Geocoder/Provider/GoogleMaps.php b/src/Geocoder/Provider/GoogleMaps.php index 551985e2f..977dea858 100644 --- a/src/Geocoder/Provider/GoogleMaps.php +++ b/src/Geocoder/Provider/GoogleMaps.php @@ -51,10 +51,10 @@ class GoogleMaps extends AbstractHttpProvider implements LocaleAwareProvider /** * @param HttpClient $client An HTTP adapter - * @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) + * @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) */ public function __construct(HttpClient $client, $locale = null, $region = null, $useSsl = false, $apiKey = null) { diff --git a/src/Geocoder/Provider/GoogleMapsBusiness.php b/src/Geocoder/Provider/GoogleMapsBusiness.php index 35828b07b..3cb97891b 100644 --- a/src/Geocoder/Provider/GoogleMapsBusiness.php +++ b/src/Geocoder/Provider/GoogleMapsBusiness.php @@ -31,12 +31,12 @@ class GoogleMapsBusiness extends GoogleMaps implements Provider private $privateKey; /** - * @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 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) */ public function __construct(HttpClient $client, $clientId, $privateKey = null, $locale = null, $region = null, $useSsl = false) { diff --git a/src/Geocoder/Provider/IpInfoDb.php b/src/Geocoder/Provider/IpInfoDb.php index cc612a96e..a81c2d49e 100644 --- a/src/Geocoder/Provider/IpInfoDb.php +++ b/src/Geocoder/Provider/IpInfoDb.php @@ -42,11 +42,11 @@ class IpInfoDb extends AbstractHttpProvider implements Provider private $endpointUrl; /** - * @param HttpClient $client An HTTP adapter. - * @param string $apiKey An API key. - * @param string $precision The endpoint precision. Either "city" or "country" (faster) + * @param HttpClient $client An HTTP adapter. + * @param string $apiKey An API key. + * @param string $precision The endpoint precision. Either "city" or "country" (faster) * - * @throws Geocoder\Exception\InvalidArgument + * @throws \Geocoder\Exception\InvalidArgument */ public function __construct(HttpClient $client, $apiKey, $precision = 'city') { diff --git a/src/Geocoder/Provider/MapQuest.php b/src/Geocoder/Provider/MapQuest.php index 8cb07c20c..a37819ac9 100644 --- a/src/Geocoder/Provider/MapQuest.php +++ b/src/Geocoder/Provider/MapQuest.php @@ -54,9 +54,9 @@ class MapQuest extends AbstractHttpProvider implements Provider private $apiKey; /** - * @param HttpClient $client An HTTP adapter. - * @param string $apiKey An API key. - * @param bool $licensed True to use MapQuest's licensed endpoints, default is false to use the open endpoints (optional). + * @param HttpClient $client An HTTP adapter. + * @param string $apiKey An API key. + * @param bool $licensed True to use MapQuest's licensed endpoints, default is false to use the open endpoints (optional). */ public function __construct(HttpClient $client, $apiKey, $licensed = false) { diff --git a/src/Geocoder/Provider/MaxMind.php b/src/Geocoder/Provider/MaxMind.php index 1ddaeeedf..0bd7d0217 100644 --- a/src/Geocoder/Provider/MaxMind.php +++ b/src/Geocoder/Provider/MaxMind.php @@ -56,10 +56,10 @@ class MaxMind extends AbstractHttpProvider implements Provider private $useSsl = false; /** - * @param HttpClient $client An HTTP adapter. - * @param string $apiKey An API key. - * @param string $service The specific Maxmind service to use (optional). - * @param bool $useSsl Whether to use an SSL connection (optional). + * @param HttpClient $client An HTTP adapter. + * @param string $apiKey An API key. + * @param string $service The specific Maxmind service to use (optional). + * @param bool $useSsl Whether to use an SSL connection (optional). */ public function __construct(HttpClient $client, $apiKey, $service = self::CITY_EXTENDED_SERVICE, $useSsl = false) { diff --git a/src/Geocoder/Provider/Nominatim.php b/src/Geocoder/Provider/Nominatim.php index 96bf06ca3..f9ed8cac5 100644 --- a/src/Geocoder/Provider/Nominatim.php +++ b/src/Geocoder/Provider/Nominatim.php @@ -27,9 +27,9 @@ class Nominatim extends AbstractHttpProvider implements LocaleAwareProvider private $rootUrl; /** - * @param HttpClient $client An HTTP adapter. - * @param string $rootUrl Root URL of the nominatim server - * @param string $locale A locale (optional). + * @param HttpClient $client An HTTP adapter. + * @param string $rootUrl Root URL of the nominatim server + * @param string $locale A locale (optional). */ public function __construct(HttpClient $client, $rootUrl, $locale = null) { diff --git a/src/Geocoder/Provider/OpenCage.php b/src/Geocoder/Provider/OpenCage.php index 68acba505..e98786b11 100644 --- a/src/Geocoder/Provider/OpenCage.php +++ b/src/Geocoder/Provider/OpenCage.php @@ -38,10 +38,10 @@ class OpenCage extends AbstractHttpProvider implements LocaleAwareProvider private $apiKey; /** - * @param HttpClient $client An HTTP adapter. - * @param string $apiKey An API key. - * @param bool $useSsl Whether to use an SSL connection (optional). - * @param string|null $locale A locale (optional). + * @param HttpClient $client An HTTP adapter. + * @param string $apiKey An API key. + * @param bool $useSsl Whether to use an SSL connection (optional). + * @param string|null $locale A locale (optional). */ public function __construct(HttpClient $client, $apiKey, $useSsl = false, $locale = null) { diff --git a/src/Geocoder/Provider/OpenStreetMap.php b/src/Geocoder/Provider/OpenStreetMap.php index 131f9e3d5..081b56b8e 100644 --- a/src/Geocoder/Provider/OpenStreetMap.php +++ b/src/Geocoder/Provider/OpenStreetMap.php @@ -24,7 +24,7 @@ class OpenStreetMap extends Nominatim /** * @param HttpClient $client An HTTP adapter. - * @param string $locale A locale (optional). + * @param string $locale A locale (optional). */ public function __construct(HttpClient $client, $locale = null) { diff --git a/src/Geocoder/Provider/TomTom.php b/src/Geocoder/Provider/TomTom.php index 79483a429..e78750b70 100644 --- a/src/Geocoder/Provider/TomTom.php +++ b/src/Geocoder/Provider/TomTom.php @@ -39,8 +39,8 @@ class TomTom extends AbstractHttpProvider implements LocaleAwareProvider /** * @param HttpClient $client An HTTP adapter. - * @param string $apiKey An API key. - * @param string $locale A locale (optional). + * @param string $apiKey An API key. + * @param string $locale A locale (optional). */ public function __construct(HttpClient $client, $apiKey, $locale = null) { diff --git a/src/Geocoder/Provider/Yandex.php b/src/Geocoder/Provider/Yandex.php index d172ef9e1..6deab1e46 100644 --- a/src/Geocoder/Provider/Yandex.php +++ b/src/Geocoder/Provider/Yandex.php @@ -37,9 +37,9 @@ class Yandex extends AbstractHttpProvider implements LocaleAwareProvider private $toponym; /** - * @param HttpClient $client An HTTP adapter. - * @param string $locale A locale (optional). - * @param string $toponym Toponym biasing only for reverse geocoding (optional). + * @param HttpClient $client An HTTP adapter. + * @param string $locale A locale (optional). + * @param string $toponym Toponym biasing only for reverse geocoding (optional). */ public function __construct(HttpClient $client, $locale = null, $toponym = null) { From 902144df9e1e16c0057e69b2de2d8e6c4ac32167 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 16 Aug 2016 17:53:31 +0200 Subject: [PATCH 16/16] Use PSR7 implementations instead of mocks --- tests/Geocoder/Tests/TestCase.php | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/tests/Geocoder/Tests/TestCase.php b/tests/Geocoder/Tests/TestCase.php index 4b89cfd33..34be318e1 100644 --- a/tests/Geocoder/Tests/TestCase.php +++ b/tests/Geocoder/Tests/TestCase.php @@ -3,6 +3,7 @@ namespace Geocoder\Tests; use Geocoder\Model\AddressFactory; +use GuzzleHttp\Psr7\Response; use Http\Client\HttpClient; use Http\Mock\Client as MockClient; use Http\Adapter\Guzzle6\Client as GuzzleClient; @@ -14,7 +15,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase { /** * @param null|object $expects - * @return HttpAdapterInterface + * @return HttpClient */ protected function getMockAdapter($expects = null) { @@ -24,42 +25,24 @@ protected function getMockAdapter($expects = null) $stream = $this->getMock('Psr\Http\Message\StreamInterface'); $stream - ->expects($this->any()) + ->expects($expects) ->method('__toString') ->will($this->returnValue('')); - $response = $this->getMock('Psr\Http\Message\ResponseInterface'); - $response - ->expects($this->any()) - ->method('getBody') - ->will($this->returnValue($stream)); - $client = new MockClient(); - $client->addResponse($response); + $client->addResponse(new Response(200, [], $stream)); return $client; } /** * @param $returnValue - * @return HttpAdapterInterface + * @return HttpClient */ protected function getMockAdapterReturns($returnValue) { - $body = $this->getMock('Psr\Http\Message\StreamInterface'); - $body - ->expects($this->once()) - ->method('__toString') - ->will($this->returnValue((string) $returnValue)); - - $response = $this->getMock('Psr\Http\Message\ResponseInterface'); - $response - ->expects($this->once()) - ->method('getBody') - ->will($this->returnValue($body)); - $client = new MockClient(); - $client->addResponse($response); + $client->addResponse(new Response(200, [], (string) $returnValue)); return $client; }