From b599f8392b8a52aaae1b9bfc89d5820f8d263781 Mon Sep 17 00:00:00 2001 From: mscherer Date: Wed, 4 Sep 2019 11:48:40 +0200 Subject: [PATCH 1/5] Update for CakePHP 4.x. --- .gitignore | 1 + .travis.yml | 5 +---- CHANGELOG.md | 4 ++++ README.md | 3 ++- composer.json | 11 +++++++---- src/Client.php | 21 +++++++++++++-------- tests/ClientTest.php | 5 ++++- 7 files changed, 32 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 16b4a20..7c21d0e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /phpspec.yml /phpunit.xml /vendor/ +/.idea/ diff --git a/.travis.yml b/.travis.yml index befd55b..9723d47 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,12 @@ language: php -sudo: false - cache: directories: - $HOME/.composer/cache/files php: - - 5.6 - - 7.0 - 7.1 + - 7.3 env: global: diff --git a/CHANGELOG.md b/CHANGELOG.md index a367104..0f6361c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## 0.3.0 + +- CakePHP 4.x compatibility + ## 0.2.0 ### Changed diff --git a/README.md b/README.md index 59ca624..6840dc0 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,9 @@ [![Quality Score](https://img.shields.io/scrutinizer/g/php-http/cakephp-adapter.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-http/cakephp-adapter) [![Total Downloads](https://img.shields.io/packagist/dt/php-http/cakephp-adapter.svg?style=flat-square)](https://packagist.org/packages/php-http/cakephp-adapter) -**Httplug adapter for the cakephp network library** +Httplug adapter for the **CakePHP** HTTP library. +This branch is for use with CakePHP 4.0+. ## Install diff --git a/composer.json b/composer.json index eaa0b43..52eaae8 100644 --- a/composer.json +++ b/composer.json @@ -11,13 +11,14 @@ } ], "require": { - "php": "^5.6 || ^7.0", + "php": "^7.2", "php-http/httplug": "^1.0", "php-http/discovery": "^1.0", - "cakephp/cakephp": "^3.4.12" + "cakephp/cakephp": "4.x-dev" }, "require-dev": { - "php-http/client-integration-tests": "^0.6" + "php-http/client-integration-tests": "^0.6", + "phpunit/phpunit": "*" }, "autoload": { "psr-4": { @@ -36,9 +37,11 @@ "test": "vendor/bin/phpunit", "test-ci": "vendor/bin/phpunit --coverage-clover build/coverage.xml" }, + "prefer-stable": true, + "minimum-stability": "dev", "extra": { "branch-alias": { - "dev-master": "0.2-dev" + "dev-master": "0.3-dev" } } } diff --git a/src/Client.php b/src/Client.php index 613493c..710c9b5 100644 --- a/src/Client.php +++ b/src/Client.php @@ -10,21 +10,26 @@ use Http\Discovery\MessageFactoryDiscovery; use Http\Message\ResponseFactory; use Psr\Http\Message\RequestInterface; +use Throwable; /** * Client compatible with PSR7 and Httplug interfaces, using a CakePHP client. */ class Client implements HttpClient { - /** @var CakeClient */ + /** + * @var CakeClient + */ private $client; - /** @var ResponseFactory */ + /** + * @var ResponseFactory + */ private $responseFactory; /** - * @param CakeClient $client - * @param ResponseFactory $responseFactory + * @param CakeClient|null $client + * @param ResponseFactory|null $responseFactory */ public function __construct(CakeClient $client = null, ResponseFactory $responseFactory = null) { @@ -47,13 +52,13 @@ public function sendRequest(RequestInterface $request) ->withProtocolVersion($request->getProtocolVersion()) ->withBody($request->getBody()); - if (null === $cakeRequest->header('Content-Type')) { - $cakeRequest->header('Content-Type', 'application/x-www-form-urlencoded'); + if (null === $cakeRequest->getHeader('Content-Type')) { + $cakeRequest = $cakeRequest->withHeader('Content-Type', 'application/x-www-form-urlencoded'); } try { - $response = $this->client->send($cakeRequest, $this->client->config()); - } catch (Exception $exception) { + $response = $this->client->send($cakeRequest, $this->client->getConfig()); + } catch (Throwable $exception) { throw new NetworkException('Failed to send request', $request, $exception); } diff --git a/tests/ClientTest.php b/tests/ClientTest.php index bb598ad..5b7b2b8 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -7,7 +7,10 @@ class ClientTest extends HttpClientTest { - protected function createHttpAdapter() + /** + * @return \Http\Adapter\Cake\Client + */ + protected function createHttpAdapter(): Client { return new Client(); } From 726435ba78909c374d7399808f7a0d4321e8a51c Mon Sep 17 00:00:00 2001 From: mscherer Date: Mon, 30 Dec 2019 12:17:30 +0100 Subject: [PATCH 2/5] Use stable releases. --- .gitattributes | 4 ++++ .gitignore | 15 ++++++++------- .travis.yml | 14 +++++++------- composer.json | 5 ++--- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/.gitattributes b/.gitattributes index c47225a..ad4bcf8 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,7 @@ +# Define the line ending behavior of the different file extensions +# Set default behavior, in case users don't have core.autocrlf set. +* text text=auto eol=lf + .editorconfig export-ignore .gitattributes export-ignore /.github/ export-ignore diff --git a/.gitignore b/.gitignore index 7c21d0e..f10df12 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ -/behat.yml -/build/ -/composer.lock -/phpspec.yml -/phpunit.xml -/vendor/ -/.idea/ +behat.yml +build/ +composer.lock +phpspec.yml +phpunit.xml +.phpunit.result.cache +vendor/ +.idea/ diff --git a/.travis.yml b/.travis.yml index 9723d47..92ef314 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,8 @@ language: php -cache: - directories: - - $HOME/.composer/cache/files - php: - - 7.1 - - 7.3 + - 7.2 + - 7.4 env: global: @@ -22,7 +18,7 @@ matrix: dist: trusty fast_finish: true include: - - php: 5.6 + - php: 7.2 env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" COVERAGE=true TEST_COMMAND="composer test-ci" - php: hhvm dist: trusty @@ -44,3 +40,7 @@ script: after_success: - if [[ $COVERAGE = true ]]; then wget https://scrutinizer-ci.com/ocular.phar; fi - if [[ $COVERAGE = true ]]; then php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml; fi + +cache: + directories: + - $HOME/.composer/cache/files diff --git a/composer.json b/composer.json index 52eaae8..d13eb22 100644 --- a/composer.json +++ b/composer.json @@ -14,11 +14,11 @@ "php": "^7.2", "php-http/httplug": "^1.0", "php-http/discovery": "^1.0", - "cakephp/cakephp": "4.x-dev" + "cakephp/cakephp": "^4.0" }, "require-dev": { "php-http/client-integration-tests": "^0.6", - "phpunit/phpunit": "*" + "phpunit/phpunit": "^8.5" }, "autoload": { "psr-4": { @@ -38,7 +38,6 @@ "test-ci": "vendor/bin/phpunit --coverage-clover build/coverage.xml" }, "prefer-stable": true, - "minimum-stability": "dev", "extra": { "branch-alias": { "dev-master": "0.3-dev" From daff520d3286bf3bd9ac81880296f4c5062f42a2 Mon Sep 17 00:00:00 2001 From: Mark Sch Date: Mon, 24 Feb 2020 11:05:38 +0100 Subject: [PATCH 3/5] Fix Doc Blocks --- src/Client.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Client.php b/src/Client.php index 710c9b5..1ddd401 100644 --- a/src/Client.php +++ b/src/Client.php @@ -18,18 +18,18 @@ class Client implements HttpClient { /** - * @var CakeClient + * @var \Cake\Http\Client */ private $client; /** - * @var ResponseFactory + * @var \Http\Message\ResponseFactory */ private $responseFactory; /** - * @param CakeClient|null $client - * @param ResponseFactory|null $responseFactory + * @param \Cake\Http\Client|null $client + * @param \Http\Message\ResponseFactory|null $responseFactory */ public function __construct(CakeClient $client = null, ResponseFactory $responseFactory = null) { @@ -38,7 +38,7 @@ public function __construct(CakeClient $client = null, ResponseFactory $response } /** - * {@inheritdoc} + * @inheritdoc */ public function sendRequest(RequestInterface $request) { From 9a351cf09395a27dde55eb2e97e0778b5d0568db Mon Sep 17 00:00:00 2001 From: Mark Sch Date: Mon, 24 Feb 2020 14:28:59 +0100 Subject: [PATCH 4/5] php-http/httplug v2 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d13eb22..01022e5 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ ], "require": { "php": "^7.2", - "php-http/httplug": "^1.0", + "php-http/httplug": "^2.0", "php-http/discovery": "^1.0", "cakephp/cakephp": "^4.0" }, From 28b3d496e6226a3e2a782bb8fd584491642a800b Mon Sep 17 00:00:00 2001 From: mscherer Date: Mon, 24 Feb 2020 14:56:30 +0100 Subject: [PATCH 5/5] Fix up signature --- src/Client.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 1ddd401..dfd9e6b 100644 --- a/src/Client.php +++ b/src/Client.php @@ -10,6 +10,7 @@ use Http\Discovery\MessageFactoryDiscovery; use Http\Message\ResponseFactory; use Psr\Http\Message\RequestInterface; +use Psr\Http\Message\ResponseInterface; use Throwable; /** @@ -40,7 +41,7 @@ public function __construct(CakeClient $client = null, ResponseFactory $response /** * @inheritdoc */ - public function sendRequest(RequestInterface $request) + public function sendRequest(RequestInterface $request): ResponseInterface { $cakeRequest = new Request( (string) $request->getUri(),