| 1 | <?php |
||
| 7 | abstract class DatabaseOperation |
||
| 8 | { |
||
| 9 | protected $client; |
||
| 10 | protected $lastEvaluatedKey; |
||
| 11 | protected $query; |
||
| 12 | protected $result; |
||
| 13 | protected $first = true; |
||
| 14 | |||
| 15 | public function __construct(DynamoDbClient $client, $query) |
||
| 16 | { |
||
| 17 | $this->client = $client; |
||
| 18 | $this->query = $query; |
||
| 19 | } |
||
| 20 | |||
| 21 | public function next() |
||
| 22 | { |
||
| 23 | if (!$this->first && $this->lastEvaluatedKey === null) { |
||
| 24 | return null; |
||
| 25 | } |
||
| 26 | $this->first = false; |
||
| 27 | $query = $this->setExclusiveStartKey($this->query); |
||
| 28 | $result = $this->execute($query); |
||
| 29 | $this->setLastEvaluatedKey($result); |
||
| 30 | return $result; |
||
| 31 | } |
||
| 32 | |||
| 33 | abstract protected function execute($query); |
||
| 34 | |||
| 35 | protected function setExclusiveStartKey($query) |
||
| 36 | { |
||
| 42 | |||
| 43 | protected function setLastEvaluatedKey($result) |
||
| 50 | } |
||
| 51 |