egeloen/ivory-http-adapter — pull request #50 by egeloen (2014-12-20 20:33:54+00:00)
Title: Add parallel requests support

This PR is a proposal for parallel requests support. It closes #47 and #31.

To send multi requests, you need to use the `sendRequests` method which takes a unique parameter: an array of requests.

``` php
use Ivory\HttpAdapter\MultiHttpAdapterException;

// A request can be a string (url), an array (url, method, etc) or a psr request.
$requests = array(
'http://egeloen.fr',
array('http://egeloen.fr', 'POST'),
new Request(),
new InternalRequest(),
);

try {
$responses = $httpAdapter->sendRequests($requests);
} catch (MultiHttpAdapterException $e) {
$responses = $e->getResponses();
$exceptions = $e->getExceptions();
}
```

For the responses, you get a psr request where the request is available as parameter:

``` php
foreach ($responses as $response) {
$request = $response->getParameter('request');
}
```

For the exceptions, each one wraps the request and the response if available:

``` php
foreach ($exceptions as $exception) {
$request = $exception->getRequest();

if ($exception->hasResponse()) {
$response = $exception->getResponse();
}
}
```

As you can see, it does not work same as #47 but IMO, it is better to go this way and don't use callable. Futhermore, as the event system is working, you can still hook into the process using the event system.

I still have to work on it but here, we have something which starts to work well! :)

ping @kbond