PrepareLimit uses trait:short, trait:short
Prepares the pagination `limit` and `offset` parameters of a controller request.
This trait resolves an integer pagination value from the route arguments and lets the
request query string override it, clamped between the controller/pagination minLimit
and maxLimit bounds. Non-integer results fall back to the controller property, the
pagination object, then $defaultValue, and a request-provided value is recorded in the
parameter bag. The same logic serves both Pagination::LIMIT and
Pagination::OFFSET.
Tags
Table of Contents
Properties
- $limit : int|null
- The default limit value.
- $maxLimit : int|null
- The maximum limit value.
- $minLimit : int|null
- The minimum limit value.
- $offset : int|null
- The default offset value.
- $pagination : Pagination|null
- The pagination definition.
Methods
- initializeLimit() : static
- Initializes the limit, offset and min/max limit range from an array.
- initializePagination() : static
- Initializes the `pagination` property.
- prepareLimit() : int
- Prepare and returns the 'limit' value.
- prepareOffset() : int
- Prepare and returns the 'offset' value.
Properties
$limit
The default limit value.
public
int|null
$limit
= null
$maxLimit
The maximum limit value.
public
int|null
$maxLimit
= null
$minLimit
The minimum limit value.
public
int|null
$minLimit
= null
$offset
The default offset value.
public
int|null
$offset
= null
$pagination
The pagination definition.
public
Pagination|null
$pagination
= null
Methods
initializeLimit()
Initializes the limit, offset and min/max limit range from an array.
public
initializeLimit([array<string|int, mixed> $init = [] ]) : static
Parameters
- $init : array<string|int, mixed> = []
-
Initialization array, read from the Pagination keys (LIMIT, MAX_LIMIT, MIN_LIMIT, OFFSET).
Return values
static —Returns the current instance for method chaining.
initializePagination()
Initializes the `pagination` property.
public
initializePagination([array<string|int, mixed> $init = [] ][, ContainerInterface|null $container = null ]) : static
This method retrieves the default pagination settings for the application, either from the provided initialization array or from the dependency injection container.
Parameters
- $init : array<string|int, mixed> = []
-
Optional initialization array (e.g., ['pagination' => Pagination instance]).
- $container : ContainerInterface|null = null
-
Optional DI container used to retrieve the default pagination definition.
Tags
Return values
static —Returns the current instance for method chaining.
prepareLimit()
Prepare and returns the 'limit' value.
protected
prepareLimit(ServerRequestInterface|null $request[, array<string|int, mixed> $args = [] ][, array<string|int, mixed>|null &$params = null ][, int $defaultValue = 0 ][, string $property = Pagination::LIMIT ]) : int
Parameters
- $request : ServerRequestInterface|null
-
The incoming PSR-7 server request, or null when no request context is available.
- $args : array<string|int, mixed> = []
-
The route/controller arguments that may carry an initial pagination value.
- $params : array<string|int, mixed>|null = null
-
A reference to the parameter bag updated in place with the prepared value.
- $defaultValue : int = 0
-
The fallback value used when no valid integer is resolved.
- $property : string = Pagination::LIMIT
-
The pagination property to read and store (defaults to Pagination::LIMIT).
Return values
int —The resolved, range-clamped pagination value.
prepareOffset()
Prepare and returns the 'offset' value.
protected
prepareOffset(ServerRequestInterface|null $request[, array<string|int, mixed> $args = [] ][, array<string|int, mixed>|null &$params = null ][, int $defaultValue = 0 ]) : int
Parameters
- $request : ServerRequestInterface|null
-
The incoming PSR-7 server request, or null when no request context is available.
- $args : array<string|int, mixed> = []
-
The route/controller arguments that may carry an initial offset value.
- $params : array<string|int, mixed>|null = null
-
A reference to the parameter bag updated in place with the prepared value.
- $defaultValue : int = 0
-
The fallback value used when no valid integer is resolved.
Return values
int —The resolved, range-clamped offset value.