Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix | v1 - Deprecate Invalid Page Property #10

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions src/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -165,22 +172,23 @@ public function current(): Response|PromiseInterface
public function next(): void
{
$this->page++;
$this->currentPage++;
}

/**
* Get the key of the paginator
*/
public function key(): int
{
return $this->page - 1;
return $this->currentPage;
}

/**
* Check if the paginator has another page to retrieve
*/
public function valid(): bool
{
if (isset($this->maxPages) && $this->page > $this->maxPages) {
if (isset($this->maxPages) && ($this->currentPage + 1) > $this->maxPages) {
return false;
}

Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
*/
Expand Down