| 1 | <?php |
||
| 12 | trait LimitMethod |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @param int $limit |
||
| 16 | * @param int $offset |
||
| 17 | * |
||
| 18 | * @return static |
||
| 19 | * |
||
| 20 | * @throws LogicException |
||
| 21 | */ |
||
| 22 | 1 | public function limit($limit, $offset = 0) |
|
| 23 | { |
||
| 24 | 1 | if (!isset($this->query)) { |
|
| 25 | throw new LogicException("limit() called before select()"); |
||
| 26 | } |
||
| 27 | |||
| 28 | 1 | $query = clone $this->query; |
|
| 29 | 1 | $query->limit($limit); |
|
| 30 | 1 | $query->offset($offset); |
|
| 31 | |||
| 32 | 1 | return $this->cloneWith("query", $query); |
|
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @param string $key |
||
| 37 | * @param mixed $value |
||
| 38 | * |
||
| 39 | * @return static |
||
| 40 | */ |
||
| 41 | abstract protected function cloneWith($key, $value); |
||
| 42 | } |
||
| 43 |