PrepareInt
Prepares a generic integer parameter of a controller request.
This trait is the shared building block reused by the dedicated integer traits (such as
quantity). It resolves the value from the route arguments or the matching controller
property, then lets the request query string override it through filter_var()
with FILTER_VALIDATE_INT (honoring an optional FilterOption::OPTIONS range).
Non-integer results fall back to $defaultValue, and a request-provided value is
recorded in the parameter bag.
Tags
Table of Contents
Methods
- prepareInt() : int|null
- Prepares and returns an integer value for the given parameter name.
Methods
prepareInt()
Prepares and returns an integer value for the given parameter name.
protected
prepareInt(ServerRequestInterface|null $request[, array<string|int, mixed> $args = [] ][, array<string|int, mixed>|null &$params = null ][, int|null $defaultValue = null ][, string|null $name = null ]) : int|null
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 value and validation options.
- $params : array<string|int, mixed>|null = null
-
A reference to the parameter bag updated in place with the prepared integer.
- $defaultValue : int|null = null
-
The fallback value used when no valid integer is resolved.
- $name : string|null = null
-
The name of the integer parameter to read and store.
Return values
int|null —The resolved integer value, or null when none is available.