1: <?php
2:
3: namespace Guzzle\Iterator;
4:
5: use Guzzle\Common\Exception\InvalidArgumentException;
6:
7: /**
8: * Maps values before yielding
9: */
10: class MapIterator extends \IteratorIterator
11: {
12: /**
13: * @var mixed Callback
14: */
15: protected $callback;
16:
17: /**
18: * @param \Traversable $iterator Traversable iterator
19: * @param array|\Closure $callback Callback used for iterating
20: *
21: * @throws InvalidArgumentException if the callback if not callable
22: */
23: public function __construct(\Traversable $iterator, $callback)
24: {
25: parent::__construct($iterator);
26: if (!is_callable($callback)) {
27: throw new InvalidArgumentException('The callback must be callable');
28: }
29: $this->callback = $callback;
30: }
31:
32: /**
33: * {@inheritdoc}
34: */
35: public function current()
36: {
37: return call_user_func($this->callback, parent::current());
38: }
39: }
40: