1 | <?php |
||
6 | class GeneratorContainer |
||
7 | { |
||
8 | /** |
||
9 | * Generator. |
||
10 | * @var \Generator |
||
11 | */ |
||
12 | private $g; |
||
13 | |||
14 | /** |
||
15 | * Generator object hash. |
||
16 | * @var string |
||
17 | */ |
||
18 | private $h; |
||
19 | |||
20 | /** |
||
21 | * Thrown exception. |
||
22 | * @var \RuntimeException |
||
23 | */ |
||
24 | private $e; |
||
25 | |||
26 | /** |
||
27 | * Parent yield key. |
||
28 | * @var mixed |
||
29 | */ |
||
30 | private $yieldKey; |
||
31 | |||
32 | /** |
||
33 | * Constructor. |
||
34 | * @param \Generator $g |
||
35 | */ |
||
36 | 30 | public function __construct(\Generator $g, $yield_key = null) |
|
43 | |||
44 | /** |
||
45 | * Return parent yield key. |
||
46 | * @return mixed |
||
47 | */ |
||
48 | 16 | public function getYieldKey() |
|
52 | |||
53 | /** |
||
54 | * Return generator hash. |
||
55 | * @return string |
||
56 | */ |
||
57 | 19 | public function __toString() |
|
61 | |||
62 | /** |
||
63 | * Return whether generator is actually working. |
||
64 | * @return bool |
||
65 | */ |
||
66 | 30 | public function valid() |
|
76 | |||
77 | /** |
||
78 | * Return current key. |
||
79 | * @return mixed |
||
80 | */ |
||
81 | 20 | public function key() |
|
86 | |||
87 | /** |
||
88 | * Return current value. |
||
89 | * @return mixed |
||
90 | */ |
||
91 | 22 | public function current() |
|
96 | |||
97 | /** |
||
98 | * Send value into generator. |
||
99 | * @param mixed $value |
||
100 | * @NOTE: This method returns nothing, |
||
101 | * while original generator returns something. |
||
102 | */ |
||
103 | 23 | public function send($value) |
|
112 | |||
113 | /** |
||
114 | * Throw exception into generator. |
||
115 | * @param \RuntimeException $e |
||
116 | * @NOTE: This method returns nothing, |
||
117 | * while original generator returns something. |
||
118 | */ |
||
119 | 9 | public function throw_(\RuntimeException $e) |
|
128 | |||
129 | /** |
||
130 | * Return whether exception is thrown. |
||
131 | * @return bool |
||
132 | */ |
||
133 | 19 | public function thrown() |
|
137 | |||
138 | /** |
||
139 | * Return value that generator has returned or thrown. |
||
140 | * @return mixed |
||
141 | */ |
||
142 | 22 | public function getReturnOrThrown() |
|
153 | |||
154 | /** |
||
155 | * Validate that generator has finished running. |
||
156 | * @throws LogicException |
||
157 | */ |
||
158 | 23 | private function validateValidity() |
|
164 | |||
165 | /** |
||
166 | * Validate that generator is still running. |
||
167 | * @throws LogicException |
||
168 | */ |
||
169 | 22 | private function validateInvalidity() |
|
175 | } |
||
176 |