From 43eff7cb681bf8531ba4a57d6c5f76af131241e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Mon, 14 Sep 2020 10:43:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Database/ActiveQuery.php | 10 ++++------ Database/Pagination.php | 8 ++++---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Database/ActiveQuery.php b/Database/ActiveQuery.php index f930a4db..9fdb4dbe 100644 --- a/Database/ActiveQuery.php +++ b/Database/ActiveQuery.php @@ -172,20 +172,18 @@ class ActiveQuery extends Component /** * @param int $size - * @param callable $callback - * @param mixed $param * @param int $offset - * @param int $total + * @param callable $callback + * @return Pagination * @throws Exception */ - public function plunk(int $size, callable $callback, $param = null, $offset = 0, $total = -1) + public function plunk(int $size, int $offset, callable $callback) { $pagination = new Pagination($this); $pagination->setOffset($offset); $pagination->setLimit($size); - $pagination->setMax($total); $pagination->setCallback($callback); - $pagination->search($param); + return $pagination; } /** diff --git a/Database/Pagination.php b/Database/Pagination.php index b1183e57..4e886c37 100644 --- a/Database/Pagination.php +++ b/Database/Pagination.php @@ -99,12 +99,12 @@ class Pagination extends Component /** * @param array $param */ - public function search($param = []) + public function plunk($param = []) { if ($this->_length >= $this->_max) { return; } - [$length, $data] = $this->load(); + [$length, $data] = $this->get(); if ($param !== null) { call_user_func($this->_callback, $data, $param); } else { @@ -114,14 +114,14 @@ class Pagination extends Component if ($length < $this->_limit) { return; } - $this->search($param); + $this->plunk($param); } /** * @return array|Collection */ - private function load() + private function get() { if ($this->_length + $this->_limit > $this->_max) { $this->_limit = $this->_length + $this->_limit - $this->_max;