class Paginator implements ArrayableInterface, ArrayAccess, Countable, IteratorAggregate, JsonableInterface (View source)

Properties

protected Factory $factory The pagination factory.
protected array $items The items being paginated.
protected int $total The total number of items.
protected bool $hasMore Indicates if a pagination doing "quick" pagination has more items.
protected int $perPage The amount of items to show per page.
protected int $currentPage Get the current page for the request.
protected $lastPage Get the last available page number.
protected int $from The number of the first item in this range.
protected int $to The number of the last item in this range.
protected array $query All of the additional query string values.
protected string $fragment The fragment to be appended to all URLs.

Methods

void
__construct(Factory $factory, array $items, int $total, int|null $perPage = null)

Create a new Paginator instance.

$this
setupPaginationContext()

Setup the pagination context (current and last page).

void
calculateCurrentAndLastPages()

Calculate the current and last pages for this instance.

void
calculateItemRanges()

Calculate the first and last item number for this instance.

int
calculateCurrentPage(int $lastPage)

Get the current page for the request.

bool
isValidPageNumber(int $page)

Determine if the given value is a valid page number.

links(string $view = null)

Get the pagination links view.

string
getUrl(int $page)

Get a URL for a given page number.

$this|string
fragment(string|null $fragment = null)

Get / set the URL fragment to be appended to URLs.

string
buildFragment()

Build the full fragment portion of a URL.

$this
appends(string $key, string $value = null)

Add a query string value to the paginator.

$this
appendArray(array $keys)

Add an array of query string values.

$this
addQuery(string $key, string $value)

Add a query string value to the paginator.

bool
isQuickPaginating()

Determine if the paginator is doing "quick" pagination.

int
getCurrentPage(int|null $total = null)

Get the current page for the request.

int
getLastPage()

Get the last page that should be available.

int
getFrom()

Get the number of the first item on the paginator.

int
getTo()

Get the number of the last item on the paginator.

int
getPerPage()

Get the number of items to be displayed per page.

getCollection()

Get a collection instance containing the items.

array
getItems()

Get the items being paginated.

void
setItems(mixed $items)

Set the items being paginated.

int
getTotal()

Get the total number of items in the collection.

void
setBaseUrl(string $baseUrl)

Set the base URL in use by the paginator.

getFactory()

Get the pagination factory.

getIterator()

Get an iterator for the items.

bool
isEmpty()

Determine if the list of items is empty or not.

int
count()

Get the number of items for the current page.

bool
offsetExists(mixed $key)

Determine if the given item exists.

mixed
offsetGet(mixed $key)

Get the item at the given offset.

void
offsetSet(mixed $key, mixed $value)

Set the item at the given offset.

void
offsetUnset(mixed $key)

Unset the item at the given key.

array
toArray()

Get the instance as an array.

string
toJson(int $options)

Convert the object to its JSON representation.

mixed
__call(string $method, array $arguments)

Call a method on the underlying Collection

Details

void __construct(Factory $factory, array $items, int $total, int|null $perPage = null)

Create a new Paginator instance.

Parameters

Factory $factory
array $items
int $total
int|null $perPage

Return Value

void

$this setupPaginationContext()

Setup the pagination context (current and last page).

Return Value

$this

protected void calculateCurrentAndLastPages()

Calculate the current and last pages for this instance.

Return Value

void

protected void calculateItemRanges()

Calculate the first and last item number for this instance.

Return Value

void

protected int calculateCurrentPage(int $lastPage)

Get the current page for the request.

Parameters

int $lastPage

Return Value

int

protected bool isValidPageNumber(int $page)

Determine if the given value is a valid page number.

Parameters

int $page

Return Value

bool

Get the pagination links view.

Parameters

string $view

Return Value

View

string getUrl(int $page)

Get a URL for a given page number.

Parameters

int $page

Return Value

string

$this|string fragment(string|null $fragment = null)

Get / set the URL fragment to be appended to URLs.

Parameters

string|null $fragment

Return Value

$this|string

protected string buildFragment()

Build the full fragment portion of a URL.

Return Value

string

$this appends(string $key, string $value = null)

Add a query string value to the paginator.

Parameters

string $key
string $value

Return Value

$this

protected $this appendArray(array $keys)

Add an array of query string values.

Parameters

array $keys

Return Value

$this

$this addQuery(string $key, string $value)

Add a query string value to the paginator.

Parameters

string $key
string $value

Return Value

$this

bool isQuickPaginating()

Determine if the paginator is doing "quick" pagination.

Return Value

bool

int getCurrentPage(int|null $total = null)

Get the current page for the request.

Parameters

int|null $total

Return Value

int

int getLastPage()

Get the last page that should be available.

Return Value

int

int getFrom()

Get the number of the first item on the paginator.

Return Value

int

int getTo()

Get the number of the last item on the paginator.

Return Value

int

int getPerPage()

Get the number of items to be displayed per page.

Return Value

int

Collection getCollection()

Get a collection instance containing the items.

Return Value

Collection

array getItems()

Get the items being paginated.

Return Value

array

void setItems(mixed $items)

Set the items being paginated.

Parameters

mixed $items

Return Value

void

int getTotal()

Get the total number of items in the collection.

Return Value

int

void setBaseUrl(string $baseUrl)

Set the base URL in use by the paginator.

Parameters

string $baseUrl

Return Value

void

Factory getFactory()

Get the pagination factory.

Return Value

Factory

ArrayIterator getIterator()

Get an iterator for the items.

Return Value

ArrayIterator

bool isEmpty()

Determine if the list of items is empty or not.

Return Value

bool

int count()

Get the number of items for the current page.

Return Value

int

bool offsetExists(mixed $key)

Determine if the given item exists.

Parameters

mixed $key

Return Value

bool

mixed offsetGet(mixed $key)

Get the item at the given offset.

Parameters

mixed $key

Return Value

mixed

void offsetSet(mixed $key, mixed $value)

Set the item at the given offset.

Parameters

mixed $key
mixed $value

Return Value

void

void offsetUnset(mixed $key)

Unset the item at the given key.

Parameters

mixed $key

Return Value

void

array toArray()

Get the instance as an array.

Return Value

array

string toJson(int $options)

Convert the object to its JSON representation.

Parameters

int $options

Return Value

string

mixed __call(string $method, array $arguments)

Call a method on the underlying Collection

Parameters

string $method
array $arguments

Return Value

mixed