summaryrefslogtreecommitdiff
path: root/vendor/guzzle/guzzle/src/Guzzle/Batch
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/guzzle/guzzle/src/Guzzle/Batch')
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Batch/AbstractBatchDecorator.php66
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Batch/Batch.php92
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Batch/BatchBuilder.php199
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Batch/BatchClosureDivisor.php39
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Batch/BatchClosureTransfer.php40
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Batch/BatchCommandTransfer.php75
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Batch/BatchDivisorInterface.php18
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Batch/BatchInterface.php32
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Batch/BatchRequestTransfer.php65
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Batch/BatchSizeDivisor.php47
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Batch/BatchTransferInterface.php16
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Batch/Exception/BatchTransferException.php90
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Batch/ExceptionBufferingBatch.php50
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Batch/FlushingBatch.php60
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Batch/HistoryBatch.php39
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Batch/NotifyingBatch.php38
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Batch/composer.json31
17 files changed, 997 insertions, 0 deletions
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Batch/AbstractBatchDecorator.php b/vendor/guzzle/guzzle/src/Guzzle/Batch/AbstractBatchDecorator.php
new file mode 100644
index 0000000..0625d71
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Batch/AbstractBatchDecorator.php
@@ -0,0 +1,66 @@
+<?php
+
+namespace Guzzle\Batch;
+
+/**
+ * Abstract decorator used when decorating a BatchInterface
+ */
+abstract class AbstractBatchDecorator implements BatchInterface
+{
+ /** @var BatchInterface Decorated batch object */
+ protected $decoratedBatch;
+
+ /**
+ * @param BatchInterface $decoratedBatch BatchInterface that is being decorated
+ */
+ public function __construct(BatchInterface $decoratedBatch)
+ {
+ $this->decoratedBatch = $decoratedBatch;
+ }
+
+ /**
+ * Allow decorators to implement custom methods
+ *
+ * @param string $method Missing method name
+ * @param array $args Method arguments
+ *
+ * @return mixed
+ * @codeCoverageIgnore
+ */
+ public function __call($method, array $args)
+ {
+ return call_user_func_array(array($this->decoratedBatch, $method), $args);
+ }
+
+ public function add($item)
+ {
+ $this->decoratedBatch->add($item);
+
+ return $this;
+ }
+
+ public function flush()
+ {
+ return $this->decoratedBatch->flush();
+ }
+
+ public function isEmpty()
+ {
+ return $this->decoratedBatch->isEmpty();
+ }
+
+ /**
+ * Trace the decorators associated with the batch
+ *
+ * @return array
+ */
+ public function getDecorators()
+ {
+ $found = array($this);
+ if (method_exists($this->decoratedBatch, 'getDecorators')) {
+ $found = array_merge($found, $this->decoratedBatch->getDecorators());
+ }
+
+ return $found;
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Batch/Batch.php b/vendor/guzzle/guzzle/src/Guzzle/Batch/Batch.php
new file mode 100644
index 0000000..4d41c54
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Batch/Batch.php
@@ -0,0 +1,92 @@
+<?php
+
+namespace Guzzle\Batch;
+
+use Guzzle\Batch\Exception\BatchTransferException;
+
+/**
+ * Default batch implementation used to convert queued items into smaller chunks of batches using a
+ * {@see BatchDivisorIterface} and transfers each batch using a {@see BatchTransferInterface}.
+ *
+ * Any exception encountered during a flush operation will throw a {@see BatchTransferException} object containing the
+ * batch that failed. After an exception is encountered, you can flush the batch again to attempt to finish transferring
+ * any previously created batches or queued items.
+ */
+class Batch implements BatchInterface
+{
+ /** @var \SplQueue Queue of items in the queue */
+ protected $queue;
+
+ /** @var array Divided batches to be transferred */
+ protected $dividedBatches;
+
+ /** @var BatchTransferInterface */
+ protected $transferStrategy;
+
+ /** @var BatchDivisorInterface */
+ protected $divisionStrategy;
+
+ /**
+ * @param BatchTransferInterface $transferStrategy Strategy used to transfer items
+ * @param BatchDivisorInterface $divisionStrategy Divisor used to create batches
+ */
+ public function __construct(BatchTransferInterface $transferStrategy, BatchDivisorInterface $divisionStrategy)
+ {
+ $this->transferStrategy = $transferStrategy;
+ $this->divisionStrategy = $divisionStrategy;
+ $this->queue = new \SplQueue();
+ $this->queue->setIteratorMode(\SplQueue::IT_MODE_DELETE);
+ $this->dividedBatches = array();
+ }
+
+ public function add($item)
+ {
+ $this->queue->enqueue($item);
+
+ return $this;
+ }
+
+ public function flush()
+ {
+ $this->createBatches();
+
+ $items = array();
+ foreach ($this->dividedBatches as $batchIndex => $dividedBatch) {
+ while ($dividedBatch->valid()) {
+ $batch = $dividedBatch->current();
+ $dividedBatch->next();
+ try {
+ $this->transferStrategy->transfer($batch);
+ $items = array_merge($items, $batch);
+ } catch (\Exception $e) {
+ throw new BatchTransferException($batch, $items, $e, $this->transferStrategy, $this->divisionStrategy);
+ }
+ }
+ // Keep the divided batch down to a minimum in case of a later exception
+ unset($this->dividedBatches[$batchIndex]);
+ }
+
+ return $items;
+ }
+
+ public function isEmpty()
+ {
+ return count($this->queue) == 0 && count($this->dividedBatches) == 0;
+ }
+
+ /**
+ * Create batches for any queued items
+ */
+ protected function createBatches()
+ {
+ if (count($this->queue)) {
+ if ($batches = $this->divisionStrategy->createBatches($this->queue)) {
+ // Convert arrays into iterators
+ if (is_array($batches)) {
+ $batches = new \ArrayIterator($batches);
+ }
+ $this->dividedBatches[] = $batches;
+ }
+ }
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Batch/BatchBuilder.php b/vendor/guzzle/guzzle/src/Guzzle/Batch/BatchBuilder.php
new file mode 100644
index 0000000..ea99b4d
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Batch/BatchBuilder.php
@@ -0,0 +1,199 @@
+<?php
+
+namespace Guzzle\Batch;
+
+use Guzzle\Common\Exception\InvalidArgumentException;
+use Guzzle\Common\Exception\RuntimeException;
+
+/**
+ * Builder used to create custom batch objects
+ */
+class BatchBuilder
+{
+ /** @var bool Whether or not the batch should automatically flush*/
+ protected $autoFlush = false;
+
+ /** @var bool Whether or not to maintain a batch history */
+ protected $history = false;
+
+ /** @var bool Whether or not to buffer exceptions encountered in transfer */
+ protected $exceptionBuffering = false;
+
+ /** @var mixed Callable to invoke each time a flush completes */
+ protected $afterFlush;
+
+ /** @var BatchTransferInterface Object used to transfer items in the queue */
+ protected $transferStrategy;
+
+ /** @var BatchDivisorInterface Object used to divide the queue into batches */
+ protected $divisorStrategy;
+
+ /** @var array of Mapped transfer strategies by handle name */
+ protected static $mapping = array(
+ 'request' => 'Guzzle\Batch\BatchRequestTransfer',
+ 'command' => 'Guzzle\Batch\BatchCommandTransfer'
+ );
+
+ /**
+ * Create a new instance of the BatchBuilder
+ *
+ * @return BatchBuilder
+ */
+ public static function factory()
+ {
+ return new self();
+ }
+
+ /**
+ * Automatically flush the batch when the size of the queue reaches a certain threshold. Adds {@see FlushingBatch}.
+ *
+ * @param $threshold Number of items to allow in the queue before a flush
+ *
+ * @return BatchBuilder
+ */
+ public function autoFlushAt($threshold)
+ {
+ $this->autoFlush = $threshold;
+
+ return $this;
+ }
+
+ /**
+ * Maintain a history of all items that have been transferred using the batch. Adds {@see HistoryBatch}.
+ *
+ * @return BatchBuilder
+ */
+ public function keepHistory()
+ {
+ $this->history = true;
+
+ return $this;
+ }
+
+ /**
+ * Buffer exceptions thrown during transfer so that you can transfer as much as possible, and after a transfer
+ * completes, inspect each exception that was thrown. Enables the {@see ExceptionBufferingBatch} decorator.
+ *
+ * @return BatchBuilder
+ */
+ public function bufferExceptions()
+ {
+ $this->exceptionBuffering = true;
+
+ return $this;
+ }
+
+ /**
+ * Notify a callable each time a batch flush completes. Enables the {@see NotifyingBatch} decorator.
+ *
+ * @param mixed $callable Callable function to notify
+ *
+ * @return BatchBuilder
+ * @throws InvalidArgumentException if the argument is not callable
+ */
+ public function notify($callable)
+ {
+ $this->afterFlush = $callable;
+
+ return $this;
+ }
+
+ /**
+ * Configures the batch to transfer batches of requests. Associates a {@see \Guzzle\Http\BatchRequestTransfer}
+ * object as both the transfer and divisor strategy.
+ *
+ * @param int $batchSize Batch size for each batch of requests
+ *
+ * @return BatchBuilder
+ */
+ public function transferRequests($batchSize = 50)
+ {
+ $className = self::$mapping['request'];
+ $this->transferStrategy = new $className($batchSize);
+ $this->divisorStrategy = $this->transferStrategy;
+
+ return $this;
+ }
+
+ /**
+ * Configures the batch to transfer batches commands. Associates as
+ * {@see \Guzzle\Service\Command\BatchCommandTransfer} as both the transfer and divisor strategy.
+ *
+ * @param int $batchSize Batch size for each batch of commands
+ *
+ * @return BatchBuilder
+ */
+ public function transferCommands($batchSize = 50)
+ {
+ $className = self::$mapping['command'];
+ $this->transferStrategy = new $className($batchSize);
+ $this->divisorStrategy = $this->transferStrategy;
+
+ return $this;
+ }
+
+ /**
+ * Specify the strategy used to divide the queue into an array of batches
+ *
+ * @param BatchDivisorInterface $divisorStrategy Strategy used to divide a batch queue into batches
+ *
+ * @return BatchBuilder
+ */
+ public function createBatchesWith(BatchDivisorInterface $divisorStrategy)
+ {
+ $this->divisorStrategy = $divisorStrategy;
+
+ return $this;
+ }
+
+ /**
+ * Specify the strategy used to transport the items when flush is called
+ *
+ * @param BatchTransferInterface $transferStrategy How items are transferred
+ *
+ * @return BatchBuilder
+ */
+ public function transferWith(BatchTransferInterface $transferStrategy)
+ {
+ $this->transferStrategy = $transferStrategy;
+
+ return $this;
+ }
+
+ /**
+ * Create and return the instantiated batch
+ *
+ * @return BatchInterface
+ * @throws RuntimeException if no transfer strategy has been specified
+ */
+ public function build()
+ {
+ if (!$this->transferStrategy) {
+ throw new RuntimeException('No transfer strategy has been specified');
+ }
+
+ if (!$this->divisorStrategy) {
+ throw new RuntimeException('No divisor strategy has been specified');
+ }
+
+ $batch = new Batch($this->transferStrategy, $this->divisorStrategy);
+
+ if ($this->exceptionBuffering) {
+ $batch = new ExceptionBufferingBatch($batch);
+ }
+
+ if ($this->afterFlush) {
+ $batch = new NotifyingBatch($batch, $this->afterFlush);
+ }
+
+ if ($this->autoFlush) {
+ $batch = new FlushingBatch($batch, $this->autoFlush);
+ }
+
+ if ($this->history) {
+ $batch = new HistoryBatch($batch);
+ }
+
+ return $batch;
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Batch/BatchClosureDivisor.php b/vendor/guzzle/guzzle/src/Guzzle/Batch/BatchClosureDivisor.php
new file mode 100644
index 0000000..e0a2d95
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Batch/BatchClosureDivisor.php
@@ -0,0 +1,39 @@
+<?php
+
+namespace Guzzle\Batch;
+
+use Guzzle\Common\Exception\InvalidArgumentException;
+
+/**
+ * Divides batches using a callable
+ */
+class BatchClosureDivisor implements BatchDivisorInterface
+{
+ /** @var callable Method used to divide the batches */
+ protected $callable;
+
+ /** @var mixed $context Context passed to the callable */
+ protected $context;
+
+ /**
+ * @param callable $callable Method used to divide the batches. The method must accept an \SplQueue and return an
+ * array of arrays containing the divided items.
+ * @param mixed $context Optional context to pass to the batch divisor
+ *
+ * @throws InvalidArgumentException if the callable is not callable
+ */
+ public function __construct($callable, $context = null)
+ {
+ if (!is_callable($callable)) {
+ throw new InvalidArgumentException('Must pass a callable');
+ }
+
+ $this->callable = $callable;
+ $this->context = $context;
+ }
+
+ public function createBatches(\SplQueue $queue)
+ {
+ return call_user_func($this->callable, $queue, $this->context);
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Batch/BatchClosureTransfer.php b/vendor/guzzle/guzzle/src/Guzzle/Batch/BatchClosureTransfer.php
new file mode 100644
index 0000000..9cbf1ab
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Batch/BatchClosureTransfer.php
@@ -0,0 +1,40 @@
+<?php
+
+namespace Guzzle\Batch;
+
+use Guzzle\Common\Exception\InvalidArgumentException;
+
+/**
+ * Batch transfer strategy where transfer logic can be defined via a Closure.
+ * This class is to be used with {@see Guzzle\Batch\BatchInterface}
+ */
+class BatchClosureTransfer implements BatchTransferInterface
+{
+ /** @var callable A closure that performs the transfer */
+ protected $callable;
+
+ /** @var mixed $context Context passed to the callable */
+ protected $context;
+
+ /**
+ * @param mixed $callable Callable that performs the transfer. This function should accept two arguments:
+ * (array $batch, mixed $context).
+ * @param mixed $context Optional context to pass to the batch divisor
+ *
+ * @throws InvalidArgumentException
+ */
+ public function __construct($callable, $context = null)
+ {
+ if (!is_callable($callable)) {
+ throw new InvalidArgumentException('Argument must be callable');
+ }
+
+ $this->callable = $callable;
+ $this->context = $context;
+ }
+
+ public function transfer(array $batch)
+ {
+ return empty($batch) ? null : call_user_func($this->callable, $batch, $this->context);
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Batch/BatchCommandTransfer.php b/vendor/guzzle/guzzle/src/Guzzle/Batch/BatchCommandTransfer.php
new file mode 100644
index 0000000..d55ac7d
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Batch/BatchCommandTransfer.php
@@ -0,0 +1,75 @@
+<?php
+
+namespace Guzzle\Batch;
+
+use Guzzle\Batch\BatchTransferInterface;
+use Guzzle\Batch\BatchDivisorInterface;
+use Guzzle\Common\Exception\InvalidArgumentException;
+use Guzzle\Service\Command\CommandInterface;
+use Guzzle\Service\Exception\InconsistentClientTransferException;
+
+/**
+ * Efficiently transfers multiple commands in parallel per client
+ * This class is to be used with {@see Guzzle\Batch\BatchInterface}
+ */
+class BatchCommandTransfer implements BatchTransferInterface, BatchDivisorInterface
+{
+ /** @var int Size of each command batch */
+ protected $batchSize;
+
+ /**
+ * @param int $batchSize Size of each batch
+ */
+ public function __construct($batchSize = 50)
+ {
+ $this->batchSize = $batchSize;
+ }
+
+ /**
+ * Creates batches by grouping commands by their associated client
+ * {@inheritdoc}
+ */
+ public function createBatches(\SplQueue $queue)
+ {
+ $groups = new \SplObjectStorage();
+ foreach ($queue as $item) {
+ if (!$item instanceof CommandInterface) {
+ throw new InvalidArgumentException('All items must implement Guzzle\Service\Command\CommandInterface');
+ }
+ $client = $item->getClient();
+ if (!$groups->contains($client)) {
+ $groups->attach($client, new \ArrayObject(array($item)));
+ } else {
+ $groups[$client]->append($item);
+ }
+ }
+
+ $batches = array();
+ foreach ($groups as $batch) {
+ $batches = array_merge($batches, array_chunk($groups[$batch]->getArrayCopy(), $this->batchSize));
+ }
+
+ return $batches;
+ }
+
+ public function transfer(array $batch)
+ {
+ if (empty($batch)) {
+ return;
+ }
+
+ // Get the client of the first found command
+ $client = reset($batch)->getClient();
+
+ // Keep a list of all commands with invalid clients
+ $invalid = array_filter($batch, function ($command) use ($client) {
+ return $command->getClient() !== $client;
+ });
+
+ if (!empty($invalid)) {
+ throw new InconsistentClientTransferException($invalid);
+ }
+
+ $client->execute($batch);
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Batch/BatchDivisorInterface.php b/vendor/guzzle/guzzle/src/Guzzle/Batch/BatchDivisorInterface.php
new file mode 100644
index 0000000..0214f05
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Batch/BatchDivisorInterface.php
@@ -0,0 +1,18 @@
+<?php
+
+namespace Guzzle\Batch;
+
+/**
+ * Interface used for dividing a queue of items into an array of batches
+ */
+interface BatchDivisorInterface
+{
+ /**
+ * Divide a queue of items into an array batches
+ *
+ * @param \SplQueue $queue Queue of items to divide into batches. Items are removed as they are iterated.
+ *
+ * @return array|\Traversable Returns an array or Traversable object that contains arrays of items to transfer
+ */
+ public function createBatches(\SplQueue $queue);
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Batch/BatchInterface.php b/vendor/guzzle/guzzle/src/Guzzle/Batch/BatchInterface.php
new file mode 100644
index 0000000..28ea65c
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Batch/BatchInterface.php
@@ -0,0 +1,32 @@
+<?php
+
+namespace Guzzle\Batch;
+
+/**
+ * Interface for efficiently transferring items in a queue using batches
+ */
+interface BatchInterface
+{
+ /**
+ * Add an item to the queue
+ *
+ * @param mixed $item Item to add
+ *
+ * @return self
+ */
+ public function add($item);
+
+ /**
+ * Flush the batch and transfer the items
+ *
+ * @return array Returns an array flushed items
+ */
+ public function flush();
+
+ /**
+ * Check if the batch is empty and has further items to transfer
+ *
+ * @return bool
+ */
+ public function isEmpty();
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Batch/BatchRequestTransfer.php b/vendor/guzzle/guzzle/src/Guzzle/Batch/BatchRequestTransfer.php
new file mode 100644
index 0000000..4d8489c
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Batch/BatchRequestTransfer.php
@@ -0,0 +1,65 @@
+<?php
+
+namespace Guzzle\Batch;
+
+use Guzzle\Batch\BatchTransferInterface;
+use Guzzle\Batch\BatchDivisorInterface;
+use Guzzle\Common\Exception\InvalidArgumentException;
+use Guzzle\Http\Message\RequestInterface;
+
+/**
+ * Batch transfer strategy used to efficiently transfer a batch of requests.
+ * This class is to be used with {@see Guzzle\Batch\BatchInterface}
+ */
+class BatchRequestTransfer implements BatchTransferInterface, BatchDivisorInterface
+{
+ /** @var int Size of each command batch */
+ protected $batchSize;
+
+ /**
+ * Constructor used to specify how large each batch should be
+ *
+ * @param int $batchSize Size of each batch
+ */
+ public function __construct($batchSize = 50)
+ {
+ $this->batchSize = $batchSize;
+ }
+
+ /**
+ * Creates batches of requests by grouping requests by their associated curl multi object.
+ * {@inheritdoc}
+ */
+ public function createBatches(\SplQueue $queue)
+ {
+ // Create batches by client objects
+ $groups = new \SplObjectStorage();
+ foreach ($queue as $item) {
+ if (!$item instanceof RequestInterface) {
+ throw new InvalidArgumentException('All items must implement Guzzle\Http\Message\RequestInterface');
+ }
+ $client = $item->getClient();
+ if (!$groups->contains($client)) {
+ $groups->attach($client, array($item));
+ } else {
+ $current = $groups[$client];
+ $current[] = $item;
+ $groups[$client] = $current;
+ }
+ }
+
+ $batches = array();
+ foreach ($groups as $batch) {
+ $batches = array_merge($batches, array_chunk($groups[$batch], $this->batchSize));
+ }
+
+ return $batches;
+ }
+
+ public function transfer(array $batch)
+ {
+ if ($batch) {
+ reset($batch)->getClient()->send($batch);
+ }
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Batch/BatchSizeDivisor.php b/vendor/guzzle/guzzle/src/Guzzle/Batch/BatchSizeDivisor.php
new file mode 100644
index 0000000..67f90a5
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Batch/BatchSizeDivisor.php
@@ -0,0 +1,47 @@
+<?php
+
+namespace Guzzle\Batch;
+
+/**
+ * Divides batches into smaller batches under a certain size
+ */
+class BatchSizeDivisor implements BatchDivisorInterface
+{
+ /** @var int Size of each batch */
+ protected $size;
+
+ /** @param int $size Size of each batch */
+ public function __construct($size)
+ {
+ $this->size = $size;
+ }
+
+ /**
+ * Set the size of each batch
+ *
+ * @param int $size Size of each batch
+ *
+ * @return BatchSizeDivisor
+ */
+ public function setSize($size)
+ {
+ $this->size = $size;
+
+ return $this;
+ }
+
+ /**
+ * Get the size of each batch
+ *
+ * @return int
+ */
+ public function getSize()
+ {
+ return $this->size;
+ }
+
+ public function createBatches(\SplQueue $queue)
+ {
+ return array_chunk(iterator_to_array($queue, false), $this->size);
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Batch/BatchTransferInterface.php b/vendor/guzzle/guzzle/src/Guzzle/Batch/BatchTransferInterface.php
new file mode 100644
index 0000000..2e0b60d
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Batch/BatchTransferInterface.php
@@ -0,0 +1,16 @@
+<?php
+
+namespace Guzzle\Batch;
+
+/**
+ * Interface used for transferring batches of items
+ */
+interface BatchTransferInterface
+{
+ /**
+ * Transfer an array of items
+ *
+ * @param array $batch Array of items to transfer
+ */
+ public function transfer(array $batch);
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Batch/Exception/BatchTransferException.php b/vendor/guzzle/guzzle/src/Guzzle/Batch/Exception/BatchTransferException.php
new file mode 100644
index 0000000..2e1f817
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Batch/Exception/BatchTransferException.php
@@ -0,0 +1,90 @@
+<?php
+
+namespace Guzzle\Batch\Exception;
+
+use Guzzle\Common\Exception\GuzzleException;
+use Guzzle\Batch\BatchTransferInterface as TransferStrategy;
+use Guzzle\Batch\BatchDivisorInterface as DivisorStrategy;
+
+/**
+ * Exception thrown during a batch transfer
+ */
+class BatchTransferException extends \Exception implements GuzzleException
+{
+ /** @var array The batch being sent when the exception occurred */
+ protected $batch;
+
+ /** @var TransferStrategy The transfer strategy in use when the exception occurred */
+ protected $transferStrategy;
+
+ /** @var DivisorStrategy The divisor strategy in use when the exception occurred */
+ protected $divisorStrategy;
+
+ /** @var array Items transferred at the point in which the exception was encountered */
+ protected $transferredItems;
+
+ /**
+ * @param array $batch The batch being sent when the exception occurred
+ * @param array $transferredItems Items transferred at the point in which the exception was encountered
+ * @param \Exception $exception Exception encountered
+ * @param TransferStrategy $transferStrategy The transfer strategy in use when the exception occurred
+ * @param DivisorStrategy $divisorStrategy The divisor strategy in use when the exception occurred
+ */
+ public function __construct(
+ array $batch,
+ array $transferredItems,
+ \Exception $exception,
+ TransferStrategy $transferStrategy = null,
+ DivisorStrategy $divisorStrategy = null
+ ) {
+ $this->batch = $batch;
+ $this->transferredItems = $transferredItems;
+ $this->transferStrategy = $transferStrategy;
+ $this->divisorStrategy = $divisorStrategy;
+ parent::__construct(
+ 'Exception encountered while transferring batch: ' . $exception->getMessage(),
+ $exception->getCode(),
+ $exception
+ );
+ }
+
+ /**
+ * Get the batch that we being sent when the exception occurred
+ *
+ * @return array
+ */
+ public function getBatch()
+ {
+ return $this->batch;
+ }
+
+ /**
+ * Get the items transferred at the point in which the exception was encountered
+ *
+ * @return array
+ */
+ public function getTransferredItems()
+ {
+ return $this->transferredItems;
+ }
+
+ /**
+ * Get the transfer strategy
+ *
+ * @return TransferStrategy
+ */
+ public function getTransferStrategy()
+ {
+ return $this->transferStrategy;
+ }
+
+ /**
+ * Get the divisor strategy
+ *
+ * @return DivisorStrategy
+ */
+ public function getDivisorStrategy()
+ {
+ return $this->divisorStrategy;
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Batch/ExceptionBufferingBatch.php b/vendor/guzzle/guzzle/src/Guzzle/Batch/ExceptionBufferingBatch.php
new file mode 100644
index 0000000..d7a8928
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Batch/ExceptionBufferingBatch.php
@@ -0,0 +1,50 @@
+<?php
+
+namespace Guzzle\Batch;
+
+use Guzzle\Batch\Exception\BatchTransferException;
+
+/**
+ * BatchInterface decorator used to buffer exceptions encountered during a transfer. The exceptions can then later be
+ * processed after a batch flush has completed.
+ */
+class ExceptionBufferingBatch extends AbstractBatchDecorator
+{
+ /** @var array Array of BatchTransferException exceptions */
+ protected $exceptions = array();
+
+ public function flush()
+ {
+ $items = array();
+
+ while (!$this->decoratedBatch->isEmpty()) {
+ try {
+ $transferredItems = $this->decoratedBatch->flush();
+ } catch (BatchTransferException $e) {
+ $this->exceptions[] = $e;
+ $transferredItems = $e->getTransferredItems();
+ }
+ $items = array_merge($items, $transferredItems);
+ }
+
+ return $items;
+ }
+
+ /**
+ * Get the buffered exceptions
+ *
+ * @return array Array of BatchTransferException objects
+ */
+ public function getExceptions()
+ {
+ return $this->exceptions;
+ }
+
+ /**
+ * Clear the buffered exceptions
+ */
+ public function clearExceptions()
+ {
+ $this->exceptions = array();
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Batch/FlushingBatch.php b/vendor/guzzle/guzzle/src/Guzzle/Batch/FlushingBatch.php
new file mode 100644
index 0000000..367b684
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Batch/FlushingBatch.php
@@ -0,0 +1,60 @@
+<?php
+
+namespace Guzzle\Batch;
+
+/**
+ * BatchInterface decorator used to add automatic flushing of the queue when the size of the queue reaches a threshold.
+ */
+class FlushingBatch extends AbstractBatchDecorator
+{
+ /** @var int The threshold for which to automatically flush */
+ protected $threshold;
+
+ /** @var int Current number of items known to be in the queue */
+ protected $currentTotal = 0;
+
+ /**
+ * @param BatchInterface $decoratedBatch BatchInterface that is being decorated
+ * @param int $threshold Flush when the number in queue matches the threshold
+ */
+ public function __construct(BatchInterface $decoratedBatch, $threshold)
+ {
+ $this->threshold = $threshold;
+ parent::__construct($decoratedBatch);
+ }
+
+ /**
+ * Set the auto-flush threshold
+ *
+ * @param int $threshold The auto-flush threshold
+ *
+ * @return FlushingBatch
+ */
+ public function setThreshold($threshold)
+ {
+ $this->threshold = $threshold;
+
+ return $this;
+ }
+
+ /**
+ * Get the auto-flush threshold
+ *
+ * @return int
+ */
+ public function getThreshold()
+ {
+ return $this->threshold;
+ }
+
+ public function add($item)
+ {
+ $this->decoratedBatch->add($item);
+ if (++$this->currentTotal >= $this->threshold) {
+ $this->currentTotal = 0;
+ $this->decoratedBatch->flush();
+ }
+
+ return $this;
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Batch/HistoryBatch.php b/vendor/guzzle/guzzle/src/Guzzle/Batch/HistoryBatch.php
new file mode 100644
index 0000000..e345fdc
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Batch/HistoryBatch.php
@@ -0,0 +1,39 @@
+<?php
+
+namespace Guzzle\Batch;
+
+/**
+ * BatchInterface decorator used to keep a history of items that were added to the batch. You must clear the history
+ * manually to remove items from the history.
+ */
+class HistoryBatch extends AbstractBatchDecorator
+{
+ /** @var array Items in the history */
+ protected $history = array();
+
+ public function add($item)
+ {
+ $this->history[] = $item;
+ $this->decoratedBatch->add($item);
+
+ return $this;
+ }
+
+ /**
+ * Get the batch history
+ *
+ * @return array
+ */
+ public function getHistory()
+ {
+ return $this->history;
+ }
+
+ /**
+ * Clear the batch history
+ */
+ public function clearHistory()
+ {
+ $this->history = array();
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Batch/NotifyingBatch.php b/vendor/guzzle/guzzle/src/Guzzle/Batch/NotifyingBatch.php
new file mode 100644
index 0000000..96d04da
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Batch/NotifyingBatch.php
@@ -0,0 +1,38 @@
+<?php
+
+namespace Guzzle\Batch;
+
+use Guzzle\Common\Exception\InvalidArgumentException;
+
+/**
+ * BatchInterface decorator used to call a method each time flush is called
+ */
+class NotifyingBatch extends AbstractBatchDecorator
+{
+ /** @var mixed Callable to call */
+ protected $callable;
+
+ /**
+ * @param BatchInterface $decoratedBatch Batch object to decorate
+ * @param mixed $callable Callable to call
+ *
+ * @throws InvalidArgumentException
+ */
+ public function __construct(BatchInterface $decoratedBatch, $callable)
+ {
+ if (!is_callable($callable)) {
+ throw new InvalidArgumentException('The passed argument is not callable');
+ }
+
+ $this->callable = $callable;
+ parent::__construct($decoratedBatch);
+ }
+
+ public function flush()
+ {
+ $items = $this->decoratedBatch->flush();
+ call_user_func($this->callable, $items);
+
+ return $items;
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Batch/composer.json b/vendor/guzzle/guzzle/src/Guzzle/Batch/composer.json
new file mode 100644
index 0000000..12404d3
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Batch/composer.json
@@ -0,0 +1,31 @@
+{
+ "name": "guzzle/batch",
+ "description": "Guzzle batch component for batching requests, commands, or custom transfers",
+ "homepage": "http://guzzlephp.org/",
+ "keywords": ["batch", "HTTP", "REST", "guzzle"],
+ "license": "MIT",
+ "authors": [
+ {
+ "name": "Michael Dowling",
+ "email": "mtdowling@gmail.com",
+ "homepage": "https://github.com/mtdowling"
+ }
+ ],
+ "require": {
+ "php": ">=5.3.2",
+ "guzzle/common": "self.version"
+ },
+ "autoload": {
+ "psr-0": { "Guzzle\\Batch": "" }
+ },
+ "suggest": {
+ "guzzle/http": "self.version",
+ "guzzle/service": "self.version"
+ },
+ "target-dir": "Guzzle/Batch",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "3.7-dev"
+ }
+ }
+}