summaryrefslogtreecommitdiff
path: root/vendor/guzzle/guzzle/src/Guzzle/Iterator/FilterIterator.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/guzzle/guzzle/src/Guzzle/Iterator/FilterIterator.php')
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Iterator/FilterIterator.php36
1 files changed, 36 insertions, 0 deletions
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());
+ }
+}