Skip to content

Commit

Permalink
feat: add new helper methods to the page numbers trait
Browse files Browse the repository at this point in the history
  • Loading branch information
lindyhopchris committed Mar 29, 2024
1 parent 1158d50 commit 552d37f
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions src/Core/Pagination/Concerns/HasPageNumbers.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ trait HasPageNumbers
*/
private ?int $defaultPerPage = null;

/**
* @var int
*/
private int $maxPerPage = 0;

/**
* @var bool
*/
private bool $required = false;

/**
* Get the keys expected in the `page` query parameter for this paginator.
*
Expand All @@ -48,7 +58,7 @@ public function keys(): array
* @param string $key
* @return $this
*/
public function withPageKey(string $key): self
public function withPageKey(string $key): static
{
$this->pageKey = $key;

Expand All @@ -61,7 +71,7 @@ public function withPageKey(string $key): self
* @param string $key
* @return $this
*/
public function withPerPageKey(string $key): self
public function withPerPageKey(string $key): static
{
$this->perPageKey = $key;

Expand All @@ -74,11 +84,37 @@ public function withPerPageKey(string $key): self
* @param int|null $perPage
* @return $this
*/
public function withDefaultPerPage(?int $perPage): self
public function withDefaultPerPage(?int $perPage): static
{
$this->defaultPerPage = $perPage;

return $this;
}

/**
* Set the maximum number of records per-page.
*
* @param int $max
* @return $this
*/
public function withMaxPerPage(int $max): static
{
assert($max > 0, 'Expecting max per page to be greater than zero.');

$this->maxPerPage = $max;

return $this;
}

/**
* Force the client to always provided a page number.
*
* @return $this
*/
public function required(): static
{
$this->required = true;

return $this;
}
}

0 comments on commit 552d37f

Please sign in to comment.