From 760b01695ca9d6bd461fb2c5f034596812702d9d Mon Sep 17 00:00:00 2001 From: ADmad Date: Sat, 22 Jul 2017 13:10:34 +0530 Subject: [PATCH 1/7] Update client for CakePHP 3.4. --- composer.json | 2 +- src/Client.php | 34 ++++++++++++++-------------------- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/composer.json b/composer.json index 93a4dbb..f2515b5 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "php": "^5.5 || ^7.0", "php-http/httplug": "^1.0", "php-http/discovery": "^1.0", - "cakephp/cakephp": "^3.1" + "cakephp/cakephp": "^3.4" }, "require-dev": { "php-http/client-integration-tests": "^0.6" diff --git a/src/Client.php b/src/Client.php index 879e01d..7440065 100644 --- a/src/Client.php +++ b/src/Client.php @@ -3,8 +3,8 @@ namespace Http\Adapter\Cake; use Cake\Core\Exception\Exception; -use Cake\Network\Http\Client as CakeClient; -use Cake\Network\Http\Request; +use Cake\Http\Client as CakeClient; +use Cake\Http\Client\Request; use Http\Client\Exception\NetworkException; use Http\Client\HttpClient; use Http\Discovery\MessageFactoryDiscovery; @@ -12,7 +12,7 @@ use Psr\Http\Message\RequestInterface; /** - * Client compatible with PSR7 and Httplug interfaces, using a cackephp client. + * Client compatible with PSR7 and Httplug interfaces, using a CakePHP client. */ class Client implements HttpClient { @@ -37,32 +37,26 @@ public function __construct(CakeClient $client = null, ResponseFactory $response */ public function sendRequest(RequestInterface $request) { - $cakeRequest = new Request(); - $cakeRequest->method($request->getMethod()); - $cakeRequest->url((string) $request->getUri()); - $cakeRequest->version($request->getProtocolVersion()); - $cakeRequest->body($request->getBody()->getContents()); + $cakeRequest = new Request( + (string)$request->getUri(), + $request->getMethod(), + $request->getHeaders() + ); - foreach ($request->getHeaders() as $header => $values) { - $cakeRequest->header($header, $request->getHeaderLine($header)); - } + $cakeRequest = $cakeRequest + ->withProtocolVersion($request->getProtocolVersion()) + ->withBody($request->getBody()); - if (null === $cakeRequest->header('Content-Type')) { + if ($cakeRequest->header('Content-Type') === null) { $cakeRequest->header('Content-Type', 'application/x-www-form-urlencoded'); } try { - $cakeResponse = $this->client->send($cakeRequest, $this->client->config()); + $response = $this->client->send($cakeRequest, $this->client->config()); } catch (Exception $exception) { throw new NetworkException('Failed to send request', $request, $exception); } - return $this->responseFactory->createResponse( - $cakeResponse->statusCode(), - null, - $cakeResponse->headers(), - $cakeResponse->body(), - $cakeResponse->version() - ); + return $response; } } From ca0ca96ef0d884c1c3b6939d27907f889502571a Mon Sep 17 00:00:00 2001 From: ADmad Date: Fri, 4 Aug 2017 12:25:13 +0530 Subject: [PATCH 2/7] Don't use dev packages. --- composer.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/composer.json b/composer.json index f2515b5..8be5e2b 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,5 @@ "branch-alias": { "dev-master": "0.1-dev" } - }, - "prefer-stable": true, - "minimum-stability": "dev" + } } From 81f158d239eeb84b0cc560b5ba79f98fee8b8eea Mon Sep 17 00:00:00 2001 From: ADmad Date: Fri, 4 Aug 2017 12:34:02 +0530 Subject: [PATCH 3/7] Fix code styling issue. --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 7440065..ea9de35 100644 --- a/src/Client.php +++ b/src/Client.php @@ -38,7 +38,7 @@ public function __construct(CakeClient $client = null, ResponseFactory $response public function sendRequest(RequestInterface $request) { $cakeRequest = new Request( - (string)$request->getUri(), + (string) $request->getUri(), $request->getMethod(), $request->getHeaders() ); From 543aebc861798e9b6de9ce3ac2e442f9f5c1ac40 Mon Sep 17 00:00:00 2001 From: ADmad Date: Fri, 4 Aug 2017 12:40:34 +0530 Subject: [PATCH 4/7] Don't test on PHP 5.5 and min. PHP version supported by CakePHP is 5.6 --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 92bc412..befd55b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,6 @@ cache: - $HOME/.composer/cache/files php: - - 5.5 - 5.6 - 7.0 - 7.1 @@ -26,7 +25,7 @@ matrix: dist: trusty fast_finish: true include: - - php: 5.5 + - php: 5.6 env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" COVERAGE=true TEST_COMMAND="composer test-ci" - php: hhvm dist: trusty From d4433852d53edfdf38b0084bba846f85be34814b Mon Sep 17 00:00:00 2001 From: ADmad Date: Fri, 4 Aug 2017 21:59:20 +0530 Subject: [PATCH 5/7] Bump CakePHP version to 3.4.12. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8be5e2b..0f12580 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "php": "^5.5 || ^7.0", "php-http/httplug": "^1.0", "php-http/discovery": "^1.0", - "cakephp/cakephp": "^3.4" + "cakephp/cakephp": "^3.4.12" }, "require-dev": { "php-http/client-integration-tests": "^0.6" From 25efb94ff48d913ad0a7acb260905237c51cb358 Mon Sep 17 00:00:00 2001 From: ADmad Date: Fri, 4 Aug 2017 22:38:35 +0530 Subject: [PATCH 6/7] Bump PHP version to 5.6 since thats the min. version Cake 3.4 supports. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0f12580..96a2f32 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ } ], "require": { - "php": "^5.5 || ^7.0", + "php": "^5.6 || ^7.0", "php-http/httplug": "^1.0", "php-http/discovery": "^1.0", "cakephp/cakephp": "^3.4.12" From 0398337c145df32f08182e85c3984dbc7ae40fed Mon Sep 17 00:00:00 2001 From: ADmad Date: Fri, 4 Aug 2017 22:59:27 +0530 Subject: [PATCH 7/7] Revert to "yoda" syntax. --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index ea9de35..613493c 100644 --- a/src/Client.php +++ b/src/Client.php @@ -47,7 +47,7 @@ public function sendRequest(RequestInterface $request) ->withProtocolVersion($request->getProtocolVersion()) ->withBody($request->getBody()); - if ($cakeRequest->header('Content-Type') === null) { + if (null === $cakeRequest->header('Content-Type')) { $cakeRequest->header('Content-Type', 'application/x-www-form-urlencoded'); }