Skip to content

Implement httplug #487

New issue

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

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

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ composer.lock
composer.phar
phpunit.xml
php-cs-fixer.phar
.puli/
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ env:
- deps=""

php:
- 5.4
- 5.5
- 5.6
- 7.0
Expand All @@ -21,7 +20,7 @@ php:
matrix:
fast_finish: true
include:
- php: 5.4
- php: 5.5
env: deps="low"

before_script:
Expand Down
17 changes: 14 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,23 @@
],
"require": {
"php": ">=5.4.0",
"egeloen/http-adapter": "~0.8|~1.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",
"php-http/httplug": "^1.0"
},
"require-dev": {
"geoip2/geoip2": "~2.0",
"symfony/stopwatch": "~2.5"
"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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use "php-http/discovery": "^0.8.0" and put that in require.

"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.",
Expand Down
164 changes: 164 additions & 0 deletions puli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
{
"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"
}
}
}
27 changes: 18 additions & 9 deletions src/Geocoder/Provider/AbstractHttpProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,44 @@

namespace Geocoder\Provider;

use Ivory\HttpAdapter\HttpAdapterInterface;
use Http\Message\MessageFactory;
use Http\Discovery\HttpClientDiscovery;
use Http\Discovery\MessageFactoryDiscovery;
use Http\Client\HttpClient;

/**
* @author William Durand <[email protected]>
*/
class AbstractHttpProvider extends AbstractProvider
{
/**
* @var HttpAdapterInterface
* @var HttpClient
*/
private $adapter;
protected $client;

/**
* @param HttpAdapterInterface $adapter An HTTP adapter
* @var MessageFactory
*/
public function __construct(HttpAdapterInterface $adapter)
protected $messageFactory;

/**
* @param HttpClient $client An HTTP adapter
*/
public function __construct(HttpClient $client = null, MessageFactory $factory = null)
{
parent::__construct();

$this->adapter = $adapter;
$this->client = $client ?: HttpClientDiscovery::find();
$this->messageFactory = $factory ?: MessageFactoryDiscovery::find();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put these in the getters. This will allow us not to use puli discovery by using $provider->setHttpMessageFactory($factory)

}

/**
* Returns the HTTP adapter.
*
* @return HttpAdapterInterface
* @return HttpClient
*/
public function getAdapter()
public function getHttpClient()
Copy link
Member

@Nyholm Nyholm Mar 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add public setters and protected getters. Otherwise we have to modify the constructors of every provider.

{
return $this->adapter;
return $this->client;
}
}
13 changes: 7 additions & 6 deletions src/Geocoder/Provider/ArcGISOnline.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

use Geocoder\Exception\NoResult;
use Geocoder\Exception\UnsupportedOperation;
use Ivory\HttpAdapter\HttpAdapterInterface;
use Http\Client\HttpClient;

/**
* @author ALKOUM Dorian <[email protected]>
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -167,8 +167,9 @@ private function buildQuery($query)
*/
private function executeQuery($query)
{
$query = $this->buildQuery($query);
$content = (string) $this->getAdapter()->get($query)->getBody();
$query = $this->buildQuery($query);
$request = $this->messageFactory->createRequest('GET', $query);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use $this->getHttpMessageFactory() here and on other providers.

$content = (string) $this->getHttpClient()->sendRequest($request)->getBody();

if (empty($content)) {
throw new NoResult(sprintf('Could not execute query "%s".', $query));
Expand Down
11 changes: 6 additions & 5 deletions src/Geocoder/Provider/BingMaps.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 David Guyon <[email protected]>
Expand All @@ -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;
Expand Down Expand Up @@ -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->messageFactory->createRequest('GET', $query);
$content = (string) $this->getHttpClient()->sendRequest($request)->getBody();

if (empty($content)) {
throw new NoResult(sprintf('Could not execute query "%s".', $query));
Expand Down
3 changes: 2 additions & 1 deletion src/Geocoder/Provider/FreeGeoIp.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public function getName()
*/
private function executeQuery($query)
{
$content = (string) $this->getAdapter()->get($query)->getBody();
$request = $this->messageFactory->createRequest('GET', $query);
$content = (string) $this->getHttpClient()->sendRequest($request)->getBody();

if (empty($content)) {
throw new NoResult(sprintf('Could not execute query %s', $query));
Expand Down
11 changes: 6 additions & 5 deletions src/Geocoder/Provider/GeoIPs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -107,7 +107,8 @@ public function getName()
*/
private function executeQuery($query)
{
$content = (string) $this->getAdapter()->get($query)->getBody();
$request = $this->messageFactory->createRequest('GET', $query);
$content = (string) $this->getHttpClient()->sendRequest($request)->getBody();

if (empty($content)) {
throw new NoResult(sprintf('Invalid response from GeoIPs API for query "%s".', $query));
Expand Down
3 changes: 2 additions & 1 deletion src/Geocoder/Provider/GeoPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public function getName()
*/
private function executeQuery($query)
{
$content = (string) $this->getAdapter()->get($query)->getBody();
$request = $this->messageFactory->createRequest('GET', $query);
$content = (string) $this->getHttpClient()->sendRequest($request)->getBody();

if (empty($content)) {
throw new NoResult(sprintf('Could not execute query "%s".', $query));
Expand Down
Loading