1 | <?php |
||
11 | final class TupleCollection implements \IteratorAggregate, ResponseCollectionInterface |
||
12 | { |
||
13 | private $tuples = []; |
||
14 | |||
15 | /** |
||
16 | * TypleCollection constructor. |
||
17 | * |
||
18 | * @param array $tuples |
||
19 | */ |
||
20 | 4 | public function __construct(array $tuples) |
|
24 | |||
25 | /** {@inheritdoc} */ |
||
26 | 4 | public function getResponse(RpcRequestInterface $request) |
|
27 | { |
||
28 | 4 | foreach ($this->tuples as $tuple) { |
|
29 | 4 | if ($tuple['request'] === $request) { |
|
30 | 3 | return $tuple['response']; |
|
31 | } |
||
32 | 2 | } |
|
33 | |||
34 | 1 | throw new \OutOfBoundsException('Request is not valid'); |
|
35 | } |
||
36 | |||
37 | /** {@inheritdoc} */ |
||
38 | 1 | public function getIterator() |
|
42 | |||
43 | 1 | private function getResponseFromTuple(array $tuple) |
|
47 | } |
||
48 |