| 1 | <?php |
||
| 6 | abstract class CursorResponse extends BaseResponse implements ResponseInterface |
||
| 7 | { |
||
| 8 | use ArrayChecker; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * Set response body |
||
| 12 | * |
||
| 13 | * @param mixed $body Response body |
||
| 14 | * @return void |
||
| 15 | * @throws InvalidResponseException |
||
| 16 | */ |
||
| 17 | public function setBody($body) |
||
| 18 | { |
||
| 19 | if ( |
||
| 20 | !$this->checkFixedArray($body, 2) || |
||
| 21 | !is_numeric($body[0]) || |
||
| 22 | !is_array($body[1]) |
||
| 23 | ) { |
||
| 24 | throw new InvalidResponseException($this->command, $body); |
||
| 25 | } |
||
| 26 | |||
| 27 | parent::setBody($body); |
||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Parse response |
||
| 32 | * |
||
| 33 | * @return array Parsed response. Indexed array with `finished', 'nextCursor`, `queues` |
||
| 34 | */ |
||
| 35 | public function parse() |
||
| 36 | { |
||
| 37 | $nextCursor = (int) $this->body[0]; |
||
| 38 | return array_merge([ |
||
| 39 | 'finished' => (0 === $nextCursor), |
||
| 40 | 'nextCursor' => $nextCursor, |
||
| 41 | ], $this->parseBody((array) $this->body[1])); |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Parse main body |
||
| 46 | * |
||
| 47 | * @param array $body Body |
||
| 48 | * @return array Parsed body |
||
| 49 | */ |
||
| 50 | abstract protected function parseBody(array $body); |
||
| 51 | } |