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 16b4a20..f10df12 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ -/behat.yml -/build/ -/composer.lock -/phpspec.yml -/phpunit.xml -/vendor/ +behat.yml +build/ +composer.lock +phpspec.yml +phpunit.xml +.phpunit.result.cache +vendor/ +.idea/ diff --git a/.travis.yml b/.travis.yml index befd55b..92ef314 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,8 @@ language: php -sudo: false - -cache: - directories: - - $HOME/.composer/cache/files - php: - - 5.6 - - 7.0 - - 7.1 + - 7.2 + - 7.4 env: global: @@ -25,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 @@ -47,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/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..01022e5 100644 --- a/composer.json +++ b/composer.json @@ -11,13 +11,14 @@ } ], "require": { - "php": "^5.6 || ^7.0", - "php-http/httplug": "^1.0", + "php": "^7.2", + "php-http/httplug": "^2.0", "php-http/discovery": "^1.0", - "cakephp/cakephp": "^3.4.12" + "cakephp/cakephp": "^4.0" }, "require-dev": { - "php-http/client-integration-tests": "^0.6" + "php-http/client-integration-tests": "^0.6", + "phpunit/phpunit": "^8.5" }, "autoload": { "psr-4": { @@ -36,9 +37,10 @@ "test": "vendor/bin/phpunit", "test-ci": "vendor/bin/phpunit --coverage-clover build/coverage.xml" }, + "prefer-stable": true, "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..dfd9e6b 100644 --- a/src/Client.php +++ b/src/Client.php @@ -10,21 +10,27 @@ use Http\Discovery\MessageFactoryDiscovery; use Http\Message\ResponseFactory; use Psr\Http\Message\RequestInterface; +use Psr\Http\Message\ResponseInterface; +use Throwable; /** * Client compatible with PSR7 and Httplug interfaces, using a CakePHP client. */ class Client implements HttpClient { - /** @var CakeClient */ + /** + * @var \Cake\Http\Client + */ private $client; - /** @var ResponseFactory */ + /** + * @var \Http\Message\ResponseFactory + */ private $responseFactory; /** - * @param CakeClient $client - * @param ResponseFactory $responseFactory + * @param \Cake\Http\Client|null $client + * @param \Http\Message\ResponseFactory|null $responseFactory */ public function __construct(CakeClient $client = null, ResponseFactory $responseFactory = null) { @@ -33,9 +39,9 @@ public function __construct(CakeClient $client = null, ResponseFactory $response } /** - * {@inheritdoc} + * @inheritdoc */ - public function sendRequest(RequestInterface $request) + public function sendRequest(RequestInterface $request): ResponseInterface { $cakeRequest = new Request( (string) $request->getUri(), @@ -47,13 +53,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(); }