summaryrefslogtreecommitdiff
path: root/vendor/guzzle/guzzle/src/Guzzle/Iterator
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/guzzle/guzzle/src/Guzzle/Iterator')
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Iterator/AppendIterator.php19
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Iterator/ChunkedIterator.php56
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Iterator/FilterIterator.php36
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Iterator/MapIterator.php34
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Iterator/MethodProxyIterator.php27
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Iterator/README.md25
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Iterator/composer.json27
7 files changed, 224 insertions, 0 deletions
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Iterator/AppendIterator.php b/vendor/guzzle/guzzle/src/Guzzle/Iterator/AppendIterator.php
new file mode 100644
index 0000000..1b6bd7e
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Iterator/AppendIterator.php
@@ -0,0 +1,19 @@
+<?php
+
+namespace Guzzle\Iterator;
+
+/**
+ * AppendIterator that is not affected by https://bugs.php.net/bug.php?id=49104
+ */
+class AppendIterator extends \AppendIterator
+{
+ /**
+ * Works around the bug in which PHP calls rewind() and next() when appending
+ *
+ * @param \Iterator $iterator Iterator to append
+ */
+ public function append(\Iterator $iterator)
+ {
+ $this->getArrayIterator()->append($iterator);
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Iterator/ChunkedIterator.php b/vendor/guzzle/guzzle/src/Guzzle/Iterator/ChunkedIterator.php
new file mode 100644
index 0000000..d76cdd4
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Iterator/ChunkedIterator.php
@@ -0,0 +1,56 @@
+<?php
+
+namespace Guzzle\Iterator;
+
+/**
+ * Pulls out chunks from an inner iterator and yields the chunks as arrays
+ */
+class ChunkedIterator extends \IteratorIterator
+{
+ /** @var int Size of each chunk */
+ protected $chunkSize;
+
+ /** @var array Current chunk */
+ protected $chunk;
+
+ /**
+ * @param \Traversable $iterator Traversable iterator
+ * @param int $chunkSize Size to make each chunk
+ * @throws \InvalidArgumentException
+ */
+ public function __construct(\Traversable $iterator, $chunkSize)
+ {
+ $chunkSize = (int) $chunkSize;
+ if ($chunkSize < 0 ) {
+ throw new \InvalidArgumentException("The chunk size must be equal or greater than zero; $chunkSize given");
+ }
+
+ parent::__construct($iterator);
+ $this->chunkSize = $chunkSize;
+ }
+
+ public function rewind()
+ {
+ parent::rewind();
+ $this->next();
+ }
+
+ public function next()
+ {
+ $this->chunk = array();
+ for ($i = 0; $i < $this->chunkSize && parent::valid(); $i++) {
+ $this->chunk[] = parent::current();
+ parent::next();
+ }
+ }
+
+ public function current()
+ {
+ return $this->chunk;
+ }
+
+ public function valid()
+ {
+ return (bool) $this->chunk;
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Iterator/FilterIterator.php b/vendor/guzzle/guzzle/src/Guzzle/Iterator/FilterIterator.php
new file mode 100644
index 0000000..b103367
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Iterator/FilterIterator.php
@@ -0,0 +1,36 @@
+<?php
+
+namespace Guzzle\Iterator;
+
+use Guzzle\Common\Exception\InvalidArgumentException;
+
+/**
+ * Filters values using a callback
+ *
+ * Used when PHP 5.4's {@see \CallbackFilterIterator} is not available
+ */
+class FilterIterator extends \FilterIterator
+{
+ /** @var mixed Callback used for filtering */
+ protected $callback;
+
+ /**
+ * @param \Iterator $iterator Traversable iterator
+ * @param array|\Closure $callback Callback used for filtering. Return true to keep or false to filter.
+ *
+ * @throws InvalidArgumentException if the callback if not callable
+ */
+ public function __construct(\Iterator $iterator, $callback)
+ {
+ parent::__construct($iterator);
+ if (!is_callable($callback)) {
+ throw new InvalidArgumentException('The callback must be callable');
+ }
+ $this->callback = $callback;
+ }
+
+ public function accept()
+ {
+ return call_user_func($this->callback, $this->current());
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Iterator/MapIterator.php b/vendor/guzzle/guzzle/src/Guzzle/Iterator/MapIterator.php
new file mode 100644
index 0000000..7e586bd
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Iterator/MapIterator.php
@@ -0,0 +1,34 @@
+<?php
+
+namespace Guzzle\Iterator;
+
+use Guzzle\Common\Exception\InvalidArgumentException;
+
+/**
+ * Maps values before yielding
+ */
+class MapIterator extends \IteratorIterator
+{
+ /** @var mixed Callback */
+ protected $callback;
+
+ /**
+ * @param \Traversable $iterator Traversable iterator
+ * @param array|\Closure $callback Callback used for iterating
+ *
+ * @throws InvalidArgumentException if the callback if not callable
+ */
+ public function __construct(\Traversable $iterator, $callback)
+ {
+ parent::__construct($iterator);
+ if (!is_callable($callback)) {
+ throw new InvalidArgumentException('The callback must be callable');
+ }
+ $this->callback = $callback;
+ }
+
+ public function current()
+ {
+ return call_user_func($this->callback, parent::current());
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Iterator/MethodProxyIterator.php b/vendor/guzzle/guzzle/src/Guzzle/Iterator/MethodProxyIterator.php
new file mode 100644
index 0000000..de4ab03
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Iterator/MethodProxyIterator.php
@@ -0,0 +1,27 @@
+<?php
+
+namespace Guzzle\Iterator;
+
+/**
+ * Proxies missing method calls to the innermost iterator
+ */
+class MethodProxyIterator extends \IteratorIterator
+{
+ /**
+ * Proxy method calls to the wrapped iterator
+ *
+ * @param string $name Name of the method
+ * @param array $args Arguments to proxy
+ *
+ * @return mixed
+ */
+ public function __call($name, array $args)
+ {
+ $i = $this->getInnerIterator();
+ while ($i instanceof \OuterIterator) {
+ $i = $i->getInnerIterator();
+ }
+
+ return call_user_func_array(array($i, $name), $args);
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Iterator/README.md b/vendor/guzzle/guzzle/src/Guzzle/Iterator/README.md
new file mode 100644
index 0000000..8bb7e08
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Iterator/README.md
@@ -0,0 +1,25 @@
+Guzzle Iterator
+===============
+
+Provides useful Iterators and Iterator decorators
+
+- ChunkedIterator: Pulls out chunks from an inner iterator and yields the chunks as arrays
+- FilterIterator: Used when PHP 5.4's CallbackFilterIterator is not available
+- MapIterator: Maps values before yielding
+- MethodProxyIterator: Proxies missing method calls to the innermost iterator
+
+### Installing via Composer
+
+```bash
+# Install Composer
+curl -sS https://getcomposer.org/installer | php
+
+# Add Guzzle as a dependency
+php composer.phar require guzzle/iterator:~3.0
+```
+
+After installing, you need to require Composer's autoloader:
+
+```php
+require 'vendor/autoload.php';
+```
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Iterator/composer.json b/vendor/guzzle/guzzle/src/Guzzle/Iterator/composer.json
new file mode 100644
index 0000000..ee17379
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Iterator/composer.json
@@ -0,0 +1,27 @@
+{
+ "name": "guzzle/iterator",
+ "description": "Provides helpful iterators and iterator decorators",
+ "keywords": ["iterator", "guzzle"],
+ "homepage": "http://guzzlephp.org/",
+ "license": "MIT",
+ "authors": [
+ {
+ "name": "Michael Dowling",
+ "email": "mtdowling@gmail.com",
+ "homepage": "https://github.com/mtdowling"
+ }
+ ],
+ "require": {
+ "php": ">=5.3.2",
+ "guzzle/common": ">=2.8.0"
+ },
+ "autoload": {
+ "psr-0": { "Guzzle\\Iterator": "/" }
+ },
+ "target-dir": "Guzzle/Iterator",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "3.7-dev"
+ }
+ }
+}