From 805181d331bba791c7be294af35f6ac1ddca7cf0 Mon Sep 17 00:00:00 2001 From: Michael Dowling Date: Wed, 1 Jan 2014 17:56:37 -0800 Subject: [PATCH] Adding a before callable to the sendAll method --- src/Guzzle/Http/Client.php | 21 +++++++-------------- src/Guzzle/Http/ClientInterface.php | 5 +++-- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/Guzzle/Http/Client.php b/src/Guzzle/Http/Client.php index 1b3286df..70cdba16 100644 --- a/src/Guzzle/Http/Client.php +++ b/src/Guzzle/Http/Client.php @@ -209,28 +209,21 @@ class Client implements ClientInterface { $requests = function() use ($requests, $options) { foreach ($requests as $request) { + /** @var RequestInterface $request */ + if (isset($options['before'])) { + $request->getEventDispatcher()->addListener(RequestEvents::BEFORE_SEND, $options['before'], -255); + } if (isset($options['complete'])) { - $request->getEventDispatcher()->addListener( - RequestEvents::AFTER_SEND, - $options['complete'], - -255 - ); + $request->getEventDispatcher()->addListener(RequestEvents::AFTER_SEND, $options['complete'], -255); } if (isset($options['error'])) { - $request->getEventDispatcher()->addListener( - RequestEvents::ERROR, - $options['error'], - -255 - ); + $request->getEventDispatcher()->addListener(RequestEvents::ERROR, $options['error'], -255); } yield new Transaction($this, $request); } }; - $this->batchAdapter->batch( - $requests(), - isset($options['parallel']) ? $options['parallel'] : 50 - ); + $this->batchAdapter->batch($requests(), isset($options['parallel']) ? $options['parallel'] : 50); } /** diff --git a/src/Guzzle/Http/ClientInterface.php b/src/Guzzle/Http/ClientInterface.php index 174c7a0e..66facab0 100644 --- a/src/Guzzle/Http/ClientInterface.php +++ b/src/Guzzle/Http/ClientInterface.php @@ -122,8 +122,9 @@ interface ClientInterface extends HasDispatcherInterface * @param array|\Iterator $requests Requests to send in parallel * @param array $options Associative array of options * - parallel: (int) Max number of requests to send in parallel - * - complete: Callable that receives a RequestAfterSendEvent - * - error: Callable that receives a RequestErrorEvent + * - before: (callable) Receives a RequestBeforeSendEvent + * - complete: (callable) Receives a RequestAfterSendEvent + * - error: (callable) Receives a RequestErrorEvent */ public function sendAll($requests, array $options = []);