| 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 | 11 | public function __construct(array $tuples) |
|
| 24 | |||
| 25 | /** {@inheritdoc} */ |
||
| 26 | 7 | public function getResponse(RpcRequestInterface $request) |
|
| 27 | { |
||
| 28 | 7 | foreach ($this->tuples as $tuple) { |
|
| 29 | 7 | if ($tuple['request'] === $request) { |
|
| 30 | 6 | return $tuple['response']; |
|
| 31 | } |
||
| 32 | 3 | } |
|
| 33 | |||
| 34 | 1 | throw new \OutOfBoundsException('Request is not valid'); |
|
| 35 | } |
||
| 36 | |||
| 37 | /** {@inheritdoc} */ |
||
| 38 | 5 | public function getIterator() |
|
| 42 | |||
| 43 | 5 | private function getResponseFromTuple(array $tuple) |
|
| 47 | } |
||
| 48 |