From 740f38c6145b25857794737534049775771ef705 Mon Sep 17 00:00:00 2001 From: Sammyjo20 <29132017+Sammyjo20@users.noreply.github.com> Date: Thu, 7 Dec 2023 18:39:52 +0000 Subject: [PATCH] Fix | Deprecate Invalid Page Property --- src/Paginator.php | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/Paginator.php b/src/Paginator.php index 04746dc..1829fee 100644 --- a/src/Paginator.php +++ b/src/Paginator.php @@ -33,9 +33,16 @@ abstract class Paginator implements Iterator, Countable /** * Internal Marker For The Current Page + * + * @deprecated Use $currentPage instead */ protected int $page = 1; + /** + * Denotes the current page + */ + protected int $currentPage = 0; + /** * When using async this is the total number of pages */ @@ -165,6 +172,7 @@ public function current(): Response|PromiseInterface public function next(): void { $this->page++; + $this->currentPage++; } /** @@ -172,7 +180,7 @@ public function next(): void */ public function key(): int { - return $this->page - 1; + return $this->currentPage; } /** @@ -180,7 +188,7 @@ public function key(): int */ public function valid(): bool { - if (isset($this->maxPages) && $this->page > $this->maxPages) { + if (isset($this->maxPages) && ($this->currentPage + 1) > $this->maxPages) { return false; } @@ -189,7 +197,7 @@ public function valid(): bool } if ($this->isAsyncPaginationEnabled()) { - return $this->page <= $this->totalPages ??= $this->getTotalPages($this->currentResponse); + return ($this->currentPage + 1) <= $this->totalPages ??= $this->getTotalPages($this->currentResponse); } return $this->isLastPage($this->currentResponse) === false; @@ -201,6 +209,7 @@ public function valid(): bool public function rewind(): void { $this->page = 1; + $this->currentPage = 0; $this->currentResponse = null; $this->totalResults = 0; $this->totalPages = null; @@ -305,12 +314,22 @@ public function getOriginalRequest(): Request /** * Get page + * + * @deprecated Use currentPage() instead */ public function getPage(): int { return $this->page; } + /** + * Get the current page + */ + public function getCurrentPage(): int + { + return $this->currentPage; + } + /** * Count the iterator */