From af00486412db184cfae8289a369814a706427a58 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Fri, 18 Aug 2017 14:37:44 +0200 Subject: [PATCH 01/13] Adding PSR package --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 9bf58c1..ad5bfe7 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,7 @@ "require": { "php": ">=5.4", "psr/http-message": "^1.0", + "psr/http-client": "^1.0", "php-http/promise": "^1.0" }, "require-dev": { From cbc903aadbe53e2dd39ebc700e6a5aea00b2bc46 Mon Sep 17 00:00:00 2001 From: Nyholm Date: Mon, 23 Jul 2018 13:31:08 -0700 Subject: [PATCH 02/13] Added return types and dropped PHP5 --- .travis.yml | 3 --- composer.json | 2 +- src/Exception.php | 2 +- src/Exception/HttpException.php | 4 ++-- src/Exception/RequestException.php | 2 +- src/HttpAsyncClient.php | 2 +- src/HttpClient.php | 5 +++-- 7 files changed, 9 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index b84eea2..69be8ba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,9 +7,6 @@ cache: - $HOME/.composer/cache/files php: - - 5.4 - - 5.5 - - 5.6 - 7.0 - 7.1 - 7.2 diff --git a/composer.json b/composer.json index ad5bfe7..7dd190a 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ } ], "require": { - "php": ">=5.4", + "php": "^7.0", "psr/http-message": "^1.0", "psr/http-client": "^1.0", "php-http/promise": "^1.0" diff --git a/src/Exception.php b/src/Exception.php index e7382c3..be15ef3 100644 --- a/src/Exception.php +++ b/src/Exception.php @@ -7,6 +7,6 @@ * * @author Márk Sági-Kazár */ -interface Exception +interface Exception extends \Throwable { } diff --git a/src/Exception/HttpException.php b/src/Exception/HttpException.php index f4f32a4..b7ee907 100644 --- a/src/Exception/HttpException.php +++ b/src/Exception/HttpException.php @@ -42,7 +42,7 @@ public function __construct( * * @return ResponseInterface */ - public function getResponse() + public function getResponse(): ResponseInterface { return $this->response; } @@ -60,7 +60,7 @@ public static function create( RequestInterface $request, ResponseInterface $response, \Exception $previous = null - ) { + ): self { $message = sprintf( '[url] %s [http method] %s [status code] %s [reason phrase] %s', $request->getRequestTarget(), diff --git a/src/Exception/RequestException.php b/src/Exception/RequestException.php index cdce14b..e06a0de 100644 --- a/src/Exception/RequestException.php +++ b/src/Exception/RequestException.php @@ -36,7 +36,7 @@ public function __construct($message, RequestInterface $request, \Exception $pre * * @return RequestInterface */ - public function getRequest() + public function getRequest(): RequestInterface { return $this->request; } diff --git a/src/HttpAsyncClient.php b/src/HttpAsyncClient.php index 492e511..9d6ceea 100644 --- a/src/HttpAsyncClient.php +++ b/src/HttpAsyncClient.php @@ -23,5 +23,5 @@ interface HttpAsyncClient * * @throws \Exception If processing the request is impossible (eg. bad configuration). */ - public function sendAsyncRequest(RequestInterface $request); + public function sendAsyncRequest(RequestInterface $request): Promise; } diff --git a/src/HttpClient.php b/src/HttpClient.php index 0e51749..b9c2b10 100644 --- a/src/HttpClient.php +++ b/src/HttpClient.php @@ -2,6 +2,7 @@ namespace Http\Client; +use Http\HttplugBundle\Tests\Unit\Collector\ClientInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -12,7 +13,7 @@ * @author Márk Sági-Kazár * @author David Buchmann */ -interface HttpClient +interface HttpClient extends ClientInterface { /** * Sends a PSR-7 request. @@ -24,5 +25,5 @@ interface HttpClient * @throws \Http\Client\Exception If an error happens during processing the request. * @throws \Exception If processing the request is impossible (eg. bad configuration). */ - public function sendRequest(RequestInterface $request); + public function sendRequest(RequestInterface $request): ResponseInterface; } From de1c01056a6055c976a2f2a5395048ece1181d97 Mon Sep 17 00:00:00 2001 From: Nyholm Date: Tue, 24 Jul 2018 13:12:56 -0700 Subject: [PATCH 03/13] Removed redundant comments --- src/Exception/HttpException.php | 11 ----------- src/Exception/RequestException.php | 5 ----- src/HttpAsyncClient.php | 2 -- src/HttpClient.php | 4 ---- 4 files changed, 22 deletions(-) diff --git a/src/Exception/HttpException.php b/src/Exception/HttpException.php index b7ee907..29b0507 100644 --- a/src/Exception/HttpException.php +++ b/src/Exception/HttpException.php @@ -37,11 +37,6 @@ public function __construct( $this->code = $response->getStatusCode(); } - /** - * Returns the response. - * - * @return ResponseInterface - */ public function getResponse(): ResponseInterface { return $this->response; @@ -49,12 +44,6 @@ public function getResponse(): ResponseInterface /** * Factory method to create a new exception with a normalized error message. - * - * @param RequestInterface $request - * @param ResponseInterface $response - * @param \Exception|null $previous - * - * @return HttpException */ public static function create( RequestInterface $request, diff --git a/src/Exception/RequestException.php b/src/Exception/RequestException.php index e06a0de..34e28fb 100644 --- a/src/Exception/RequestException.php +++ b/src/Exception/RequestException.php @@ -31,11 +31,6 @@ public function __construct($message, RequestInterface $request, \Exception $pre parent::__construct($message, 0, $previous); } - /** - * Returns the request. - * - * @return RequestInterface - */ public function getRequest(): RequestInterface { return $this->request; diff --git a/src/HttpAsyncClient.php b/src/HttpAsyncClient.php index 9d6ceea..eacf874 100644 --- a/src/HttpAsyncClient.php +++ b/src/HttpAsyncClient.php @@ -17,8 +17,6 @@ interface HttpAsyncClient * * Exceptions related to processing the request are available from the returned Promise. * - * @param RequestInterface $request - * * @return Promise Resolves a PSR-7 Response or fails with an Http\Client\Exception. * * @throws \Exception If processing the request is impossible (eg. bad configuration). diff --git a/src/HttpClient.php b/src/HttpClient.php index b9c2b10..70c4d45 100644 --- a/src/HttpClient.php +++ b/src/HttpClient.php @@ -18,10 +18,6 @@ interface HttpClient extends ClientInterface /** * Sends a PSR-7 request. * - * @param RequestInterface $request - * - * @return ResponseInterface - * * @throws \Http\Client\Exception If an error happens during processing the request. * @throws \Exception If processing the request is impossible (eg. bad configuration). */ From 307c7fe23f69d234803ad49a5182585745c07d7d Mon Sep 17 00:00:00 2001 From: Nyholm Date: Tue, 24 Jul 2018 13:20:01 -0700 Subject: [PATCH 04/13] Removed return type --- src/HttpAsyncClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/HttpAsyncClient.php b/src/HttpAsyncClient.php index eacf874..bc9d5ee 100644 --- a/src/HttpAsyncClient.php +++ b/src/HttpAsyncClient.php @@ -21,5 +21,5 @@ interface HttpAsyncClient * * @throws \Exception If processing the request is impossible (eg. bad configuration). */ - public function sendAsyncRequest(RequestInterface $request): Promise; + public function sendAsyncRequest(RequestInterface $request); } From 58d0ada70c2069e980deb869b22a66892521c15a Mon Sep 17 00:00:00 2001 From: Nyholm Date: Tue, 24 Jul 2018 13:20:29 -0700 Subject: [PATCH 05/13] Removed return types --- src/Exception/HttpException.php | 9 +++++++-- src/Exception/RequestException.php | 7 ++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Exception/HttpException.php b/src/Exception/HttpException.php index 29b0507..5857b01 100644 --- a/src/Exception/HttpException.php +++ b/src/Exception/HttpException.php @@ -37,7 +37,12 @@ public function __construct( $this->code = $response->getStatusCode(); } - public function getResponse(): ResponseInterface + /** + * Returns the response. + * + * @return ResponseInterface + */ + public function getResponse() { return $this->response; } @@ -49,7 +54,7 @@ public static function create( RequestInterface $request, ResponseInterface $response, \Exception $previous = null - ): self { + ) { $message = sprintf( '[url] %s [http method] %s [status code] %s [reason phrase] %s', $request->getRequestTarget(), diff --git a/src/Exception/RequestException.php b/src/Exception/RequestException.php index 34e28fb..cdce14b 100644 --- a/src/Exception/RequestException.php +++ b/src/Exception/RequestException.php @@ -31,7 +31,12 @@ public function __construct($message, RequestInterface $request, \Exception $pre parent::__construct($message, 0, $previous); } - public function getRequest(): RequestInterface + /** + * Returns the request. + * + * @return RequestInterface + */ + public function getRequest() { return $this->request; } From 7d9f4ec7585bc631a8f735b0c2ff6cdc4ef59d7b Mon Sep 17 00:00:00 2001 From: Nyholm Date: Sat, 28 Jul 2018 19:14:23 -0700 Subject: [PATCH 06/13] Make sure our exception implements the correct interfaces --- src/Exception.php | 4 +++- src/Exception/NetworkException.php | 2 +- src/Exception/RequestException.php | 9 ++------- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Exception.php b/src/Exception.php index be15ef3..4d2a6ad 100644 --- a/src/Exception.php +++ b/src/Exception.php @@ -2,11 +2,13 @@ namespace Http\Client; +use Psr\Http\Client\ClientException; + /** * Every HTTP Client related Exception must implement this interface. * * @author Márk Sági-Kazár */ -interface Exception extends \Throwable +interface Exception extends ClientException { } diff --git a/src/Exception/NetworkException.php b/src/Exception/NetworkException.php index f2198e5..0a1def2 100644 --- a/src/Exception/NetworkException.php +++ b/src/Exception/NetworkException.php @@ -9,6 +9,6 @@ * * @author Márk Sági-Kazár */ -class NetworkException extends RequestException +class NetworkException extends RequestException implements \Psr\Http\Client\Exception\NetworkException { } diff --git a/src/Exception/RequestException.php b/src/Exception/RequestException.php index cdce14b..817cbf2 100644 --- a/src/Exception/RequestException.php +++ b/src/Exception/RequestException.php @@ -12,7 +12,7 @@ * * @author Márk Sági-Kazár */ -class RequestException extends TransferException +class RequestException extends TransferException implements \Psr\Http\Client\Exception\RequestException { /** * @var RequestInterface @@ -31,12 +31,7 @@ public function __construct($message, RequestInterface $request, \Exception $pre parent::__construct($message, 0, $previous); } - /** - * Returns the request. - * - * @return RequestInterface - */ - public function getRequest() + public function getRequest(): RequestInterface { return $this->request; } From f2173243cdb24ce54b780225de65254689411dff Mon Sep 17 00:00:00 2001 From: Nyholm Date: Sat, 28 Jul 2018 19:21:34 -0700 Subject: [PATCH 07/13] Make it more clear what interface we are implementing --- src/Exception.php | 4 ++-- src/Exception/NetworkException.php | 4 +++- src/Exception/RequestException.php | 3 ++- src/HttpClient.php | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Exception.php b/src/Exception.php index 4d2a6ad..41e3958 100644 --- a/src/Exception.php +++ b/src/Exception.php @@ -2,13 +2,13 @@ namespace Http\Client; -use Psr\Http\Client\ClientException; +use Psr\Http\Client\ClientException as PsrClientException; /** * Every HTTP Client related Exception must implement this interface. * * @author Márk Sági-Kazár */ -interface Exception extends ClientException +interface Exception extends PsrClientException { } diff --git a/src/Exception/NetworkException.php b/src/Exception/NetworkException.php index 0a1def2..69b4a4e 100644 --- a/src/Exception/NetworkException.php +++ b/src/Exception/NetworkException.php @@ -2,6 +2,8 @@ namespace Http\Client\Exception; +use Psr\Http\Client\Exception\NetworkException as PsrNetworkException; + /** * Thrown when the request cannot be completed because of network issues. * @@ -9,6 +11,6 @@ * * @author Márk Sági-Kazár */ -class NetworkException extends RequestException implements \Psr\Http\Client\Exception\NetworkException +class NetworkException extends RequestException implements PsrNetworkException { } diff --git a/src/Exception/RequestException.php b/src/Exception/RequestException.php index 817cbf2..f95d8d9 100644 --- a/src/Exception/RequestException.php +++ b/src/Exception/RequestException.php @@ -3,6 +3,7 @@ namespace Http\Client\Exception; use Psr\Http\Message\RequestInterface; +use Psr\Http\Client\Exception\RequestException as PsrRequestException; /** * Exception for when a request failed, providing access to the failed request. @@ -12,7 +13,7 @@ * * @author Márk Sági-Kazár */ -class RequestException extends TransferException implements \Psr\Http\Client\Exception\RequestException +class RequestException extends TransferException implements PsrRequestException { /** * @var RequestInterface diff --git a/src/HttpClient.php b/src/HttpClient.php index 70c4d45..9dda516 100644 --- a/src/HttpClient.php +++ b/src/HttpClient.php @@ -2,7 +2,7 @@ namespace Http\Client; -use Http\HttplugBundle\Tests\Unit\Collector\ClientInterface; +use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; From 310b13f8aa28f2c9985fc202ef9b2363ae3392f2 Mon Sep 17 00:00:00 2001 From: Nyholm Date: Sat, 28 Jul 2018 19:23:26 -0700 Subject: [PATCH 08/13] minor --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 69be8ba..0977137 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ branches: matrix: fast_finish: true include: - - php: 5.4 + - php: 7.0 env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" COVERAGE=true TEST_COMMAND="composer test-ci" - php: hhvm dist: trusty From b45b737573d8f2332786e89b256c88708726703c Mon Sep 17 00:00:00 2001 From: Nyholm Date: Sat, 28 Jul 2018 19:24:49 -0700 Subject: [PATCH 09/13] Use version 0.1 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7dd190a..cf99788 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "require": { "php": "^7.0", "psr/http-message": "^1.0", - "psr/http-client": "^1.0", + "psr/http-client": "^0.1", "php-http/promise": "^1.0" }, "require-dev": { From f5b7e91757041f2b83a64f122d71c269ea78550e Mon Sep 17 00:00:00 2001 From: Nyholm Date: Sat, 28 Jul 2018 19:32:25 -0700 Subject: [PATCH 10/13] Remove HHVM --- .travis.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0977137..ad1cb28 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,12 +24,9 @@ matrix: include: - php: 7.0 env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" COVERAGE=true TEST_COMMAND="composer test-ci" - - php: hhvm - dist: trusty before_install: - - if [[ $COVERAGE != true && $TRAVIS_PHP_VERSION != hhvm ]]; then phpenv config-rm xdebug.ini || true; fi - - travis_retry composer self-update + - if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi install: - travis_retry composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction From b1f4ee62d2637db7e3b3cf30fc1b0a4cb979a160 Mon Sep 17 00:00:00 2001 From: Nyholm Date: Sat, 28 Jul 2018 19:54:03 -0700 Subject: [PATCH 11/13] Added change log --- CHANGELOG.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 42824b4..6f085d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,24 @@ # Change Log +## 2.0.0 - UNRELEASED + +This version contains is technically a BC break because we drop PHP5 and add return +type annotation to support `psr/http-client`. + +### Added + +- Support for PSR-18 (Http client). + +### Removed + +- PHP 5 support + +### Changed + +- [BC Break] `HttpClient::sendRequest(RequestInterface $request)` has a return type annotation. The mew +signature is `HttpClient::sendRequest(RequestInterface $request): ResponseInterface`. +- [BC Break] `RequestException::getRequest()` has a return type annotation. The new +signature is `RequestException::getRequest(): RequestInterface`. ## 1.1.0 - 2016-08-31 From 1b29077f1262866b608e5b35c7297e665ffd914f Mon Sep 17 00:00:00 2001 From: Nyholm Date: Mon, 30 Jul 2018 00:07:44 -0700 Subject: [PATCH 12/13] Small fixes --- CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f085d4..8ba4c8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,12 +2,12 @@ ## 2.0.0 - UNRELEASED -This version contains is technically a BC break because we drop PHP5 and add return -type annotation to support `psr/http-client`. +This version is no BC break for consumers using HTTPlug. However, HTTP clients that +implement HTTPlug need to adjust because we add return type declarations. ### Added -- Support for PSR-18 (Http client). +- Support for PSR-18 (HTTP client). ### Removed @@ -15,7 +15,7 @@ type annotation to support `psr/http-client`. ### Changed -- [BC Break] `HttpClient::sendRequest(RequestInterface $request)` has a return type annotation. The mew +- [BC Break] `HttpClient::sendRequest(RequestInterface $request)` has a return type annotation. The new signature is `HttpClient::sendRequest(RequestInterface $request): ResponseInterface`. - [BC Break] `RequestException::getRequest()` has a return type annotation. The new signature is `RequestException::getRequest(): RequestInterface`. From b16582baf09317db2d8d256de5527f2f1f16c770 Mon Sep 17 00:00:00 2001 From: Nyholm Date: Mon, 30 Jul 2018 00:07:59 -0700 Subject: [PATCH 13/13] Updated branch alias --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index cf99788..256dbe0 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.2-dev" + "dev-master": "2.0-dev" } } }