-
Notifications
You must be signed in to change notification settings - Fork 522
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
Implement httplug #487
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ composer.lock | |
composer.phar | ||
phpunit.xml | ||
php-cs-fixer.phar | ||
.puli/ |
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" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} | ||
|
||
/** | ||
* Returns the HTTP adapter. | ||
* | ||
* @return HttpAdapterInterface | ||
* @return HttpClient | ||
*/ | ||
public function getAdapter() | ||
public function getHttpClient() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]> | ||
|
@@ -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,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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]> | ||
|
@@ -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->messageFactory->createRequest('GET', $query); | ||
$content = (string) $this->getHttpClient()->sendRequest($request)->getBody(); | ||
|
||
if (empty($content)) { | ||
throw new NoResult(sprintf('Could not execute query "%s".', $query)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]> | ||
|
@@ -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->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)); | ||
|
There was a problem hiding this comment.
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.