wordpress-seo
/
vendor_prefixed
/
symfony
/
dependency-injection
/
Argument
/
RewindableGenerator.php
RewindableGenerator.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.2, at vendor_prefixed/symfony/dependency-injection/Argument/RewindableGenerator.php
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This file is part of the Symfony package. |
| 5 | * |
| 6 | * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | * |
| 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | * file that was distributed with this source code. |
| 10 | */ |
| 11 | namespace YoastSEO_Vendor\Symfony\Component\DependencyInjection\Argument; |
| 12 | |
| 13 | /** |
| 14 | * @internal |
| 15 | */ |
| 16 | class RewindableGenerator implements \IteratorAggregate, \Countable |
| 17 | { |
| 18 | private $generator; |
| 19 | private $count; |
| 20 | /** |
| 21 | * @param int|callable $count |
| 22 | */ |
| 23 | public function __construct(callable $generator, $count) |
| 24 | { |
| 25 | $this->generator = $generator; |
| 26 | $this->count = $count; |
| 27 | } |
| 28 | public function getIterator() |
| 29 | { |
| 30 | $g = $this->generator; |
| 31 | return $g(); |
| 32 | } |
| 33 | public function count() |
| 34 | { |
| 35 | if (\is_callable($count = $this->count)) { |
| 36 | $this->count = $count(); |
| 37 | } |
| 38 | return $this->count; |
| 39 | } |
| 40 | } |
| 41 |