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

[WIP] Implement Guzzle 6 adapter #1

Merged
merged 2 commits into from
May 30, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
"homepage": "http://php-http.org",
"authors": [
{
"name": "Eric GELOEN",
"email": "[email protected]"
"name": "David de Boer",
"email": "[email protected]"
}
],
"require": {
"php": ">=5.4",
"php-http/adapter-core": "dev-internal_separation"
"php-http/adapter-core": "dev-internal_separation",
"guzzlehttp/guzzle": "6.x-dev"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should be changed to ~6.0 when Guzzle 6 has been released.

},
"require-dev": {
"ext-curl": "*",
Expand Down
99 changes: 99 additions & 0 deletions src/Guzzle6HttpAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

Copy link
Member

Choose a reason for hiding this comment

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

Missing file header, check guzzle5-adapter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

/**
* This file is part of the Http Adapter package.
*
* (c) Eric GELOEN <[email protected]>
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code.
*/

namespace Http\Adapter;

use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Pool;
use Http\Adapter\Common\Exception\HttpAdapterException;
use Http\Adapter\Common\Exception\MultiHttpAdapterException;
use Psr\Http\Message\RequestInterface;

/**
* Guzzle 6 HTTP adapter
*
* @author David de Boer <[email protected]>
*/
class Guzzle6HttpAdapter implements PsrHttpAdapter
Copy link
Member

Choose a reason for hiding this comment

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

Please add author information here

{
/**
* @param Client $client
*/
public function __construct(Client $client = null)
Copy link
Member

Choose a reason for hiding this comment

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

Please add docblock without a description but with the parameter.

{
$this->client = $client ?: new Client();
}

/**
* {@inheritdoc}
*/
public function sendRequest(RequestInterface $request)
{
try {
return $this->client->send($request);
} catch (RequestException $exception) {
throw new $this->createException($exception);
}
}

/**
* {@inheritdoc}
*/
public function sendRequests(array $requests)
{
$results = Pool::batch(
$this->client,
$requests
);

$exceptions = [];
foreach ($results as $result) {
if ($result instanceof TransferException) {
$exceptions[] = $this->createException($result);
}
}

if (count($exceptions) > 0) {
throw new MultiHttpAdapterException($exceptions);
}

return $results;
}

/**
* {@inheritdoc}
*/
public function getName()
{
return 'guzzle6';
}

/**
* Convert Guzzle exception into HttpAdapter exception
*
* @param RequestException $exception
*
* @return HttpAdapterException
*/
private function createException(RequestException $exception)
{
$adapterException = new HttpAdapterException(
$exception->getMessage(),
0,
$exception
);
$adapterException->setResponse($exception->getResponse());
$adapterException->setRequest($exception->getRequest());

return $adapterException;
}
}