1 | <?php |
||
9 | final class LazyResponseCollection implements \IteratorAggregate, ResponseCollectionInterface |
||
10 | { |
||
11 | /** @var bool */ |
||
12 | private $initialized = false; |
||
13 | /** @var RpcRequestInterface[] */ |
||
14 | private $requests = []; |
||
15 | /** @var RpcClientInterface */ |
||
16 | private $client; |
||
17 | /** @var ResponseCollectionInterface */ |
||
18 | private $collection; |
||
19 | |||
20 | /** |
||
21 | * LazyResponseCollection constructor. |
||
22 | * |
||
23 | * @param RpcClientInterface $client |
||
24 | */ |
||
25 | 8 | public function __construct(RpcClientInterface $client) |
|
29 | |||
30 | /** {@inheritdoc} */ |
||
31 | 4 | public function getResponse(RpcRequestInterface $request) |
|
39 | |||
40 | 8 | public function append(RpcRequestInterface $request) |
|
41 | { |
||
42 | 8 | if ($this->isFrozen()) { |
|
43 | 1 | throw new \LogicException('Cannot add request to frozen lazy collection'); |
|
44 | } |
||
45 | |||
46 | 8 | $this->requests[] = $request; |
|
47 | 8 | } |
|
48 | |||
49 | 8 | public function isFrozen() |
|
53 | |||
54 | /** {@inheritdoc} */ |
||
55 | 3 | public function getIterator() |
|
56 | { |
||
57 | 3 | if (!$this->isFrozen()) { |
|
58 | 3 | $this->init(); |
|
59 | 3 | } |
|
60 | |||
61 | 3 | return $this->collection; |
|
62 | } |
||
63 | |||
64 | 7 | private function init() |
|
70 | } |
||
71 |