Chris@14: Chris@14: * Chris@14: * For the full copyright and license information, please view the LICENSE Chris@14: * file that was distributed with this source code. Chris@14: */ Chris@14: Chris@14: namespace Symfony\Component\DependencyInjection\Argument; Chris@14: Chris@14: /** Chris@14: * @internal Chris@14: */ Chris@14: class RewindableGenerator implements \IteratorAggregate, \Countable Chris@14: { Chris@14: private $generator; Chris@14: private $count; Chris@14: Chris@14: /** Chris@14: * @param callable $generator Chris@14: * @param int|callable $count Chris@14: */ Chris@14: public function __construct(callable $generator, $count) Chris@14: { Chris@14: $this->generator = $generator; Chris@14: $this->count = $count; Chris@14: } Chris@14: Chris@14: public function getIterator() Chris@14: { Chris@14: $g = $this->generator; Chris@14: Chris@14: return $g(); Chris@14: } Chris@14: Chris@14: public function count() Chris@14: { Chris@17: if (\is_callable($count = $this->count)) { Chris@14: $this->count = $count(); Chris@14: } Chris@14: Chris@14: return $this->count; Chris@14: } Chris@14: }