-
Notifications
You must be signed in to change notification settings - Fork 0
Upgrade to CakePHP 3.4 #6
Changes from 4 commits
760b016
ca0ca96
81f158d
543aebc
d443385
25efb94
0398337
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
{ | ||
|
@@ -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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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')) { | ||
if ($cakeRequest->header('Content-Type') === null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should use "yoda" syntax. Please revert this change. |
||
$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; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use 3.4.5 and the test will pass.
Versions before 3.4.5 had wrong dependencies.