Skip to content
This repository was archived by the owner on Jan 8, 2024. It is now read-only.

Upgrade to CakePHP 3.4 #6

Merged
merged 7 commits into from
Aug 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ cache:
- $HOME/.composer/cache/files

php:
- 5.5
- 5.6
- 7.0
- 7.1
Expand All @@ -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
Expand Down
8 changes: 3 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
}
],
"require": {
"php": "^5.5 || ^7.0",
"php": "^5.6 || ^7.0",
"php-http/httplug": "^1.0",
"php-http/discovery": "^1.0",
"cakephp/cakephp": "^3.1"
"cakephp/cakephp": "^3.4.12"
},
"require-dev": {
"php-http/client-integration-tests": "^0.6"
Expand All @@ -40,7 +40,5 @@
"branch-alias": {
"dev-master": "0.1-dev"
}
},
"prefer-stable": true,
"minimum-stability": "dev"
}
}
32 changes: 13 additions & 19 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
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;
use Http\Message\ResponseFactory;
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
{
Expand All @@ -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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to create a new Request if CachePHP 3.4 supports PHP7?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes unfortunately Cake's HTTP client's method argument is typehinted as the concrete class Cake\Http\Client\Request instead of PSR7's interface. So for the time being this is required.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, okej. Thanks.

(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')) {
$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;
}
}