PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.8.1
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.8.1
2.10.0 2.10.01 2.9.1 2.9.0 2.8.1 2.8.0 2.7.7 2.7.5 2.7.0 2.6.01 2.6.0 2.5.0 2.4.01 trunk 1.0.90 1.0.91 1.0.92 1.0.93 1.0.94 1.0.95 1.0.96 1.0.97 1.0.98 1.0.99 1.1.0 All 77 releases
fluent-community / vendor / wpfluent / framework / src / WPFluent / Container / RewindableGenerator.php

RewindableGenerator.php in FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses 2.8.1, at vendor/wpfluent/framework/src/WPFluent/Container/RewindableGenerator.php

63 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCommunity\Framework\Container;
4
5 use Countable;
6 use IteratorAggregate;
7
8 class RewindableGenerator implements Countable, IteratorAggregate
9 {
10 /**
11 * The generator callback.
12 *
13 * @var callable
14 */
15 protected $generator;
16
17 /**
18 * The number of tagged services.
19 *
20 * @var callable|int
21 */
22 protected $count;
23
24 /**
25 * Create a new generator instance.
26 *
27 * @param callable $generator
28 * @param callable|int $count
29 * @return void
30 */
31 public function __construct(callable $generator, $count)
32 {
33 $this->count = $count;
34 $this->generator = $generator;
35 }
36
37 /**
38 * Get an iterator from the generator.
39 *
40 * @return mixed
41 */
42 #[\ReturnTypeWillChange]
43 public function getIterator()
44 {
45 return ($this->generator)();
46 }
47
48 /**
49 * Get the total number of tagged services.
50 *
51 * @return int
52 */
53 #[\ReturnTypeWillChange]
54 public function count()
55 {
56 if (is_callable($count = $this->count)) {
57 $this->count = $count();
58 }
59
60 return $this->count;
61 }
62 }
63