PrepareHasTotal uses trait:short
Prepares the `hasTotal` flag of a controller request.
This boolean flag controls whether a list endpoint also computes and returns the total
number of matching elements. The trait exposes a $hasTotal property (with an
initializeHasTotal() initializer) and delegates the request-driven resolution to
PrepareBoolean::prepareBoolean() bound to the ControllerParam::HAS_TOTAL
parameter.
Tags
Table of Contents
Properties
- $hasTotal : bool
- Indicates if the list method return the total number of elements.
Methods
- initializeHasTotal() : static
- Initialize the hasTotal property with an associative array definition.
- prepareHasTotal() : bool
- Prepare and returns the 'hasTotal' value.
- prepareBoolean() : bool|null
- Prepares and returns a boolean value for the given parameter name.
Properties
$hasTotal
Indicates if the list method return the total number of elements.
public
bool
$hasTotal
= true
Methods
initializeHasTotal()
Initialize the hasTotal property with an associative array definition.
public
initializeHasTotal([array<string|int, mixed> $init = [] ]) : static
Parameters
- $init : array<string|int, mixed> = []
-
The configuration array, optionally carrying a ControllerParam::HAS_TOTAL entry.
Return values
static —The current instance for chaining.
prepareHasTotal()
Prepare and returns the 'hasTotal' value.
public
prepareHasTotal(ServerRequestInterface|null $request[, array<string|int, mixed> $args = [] ][, array<string|int, mixed>|null &$params = null ]) : bool
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
hasTotalvalue. - $params : array<string|int, mixed>|null = null
-
A reference to the parameter bag updated in place with the prepared value.
Return values
bool —The resolved hasTotal flag.
prepareBoolean()
Prepares and returns a boolean value for the given parameter name.
protected
prepareBoolean(ServerRequestInterface|null $request[, array<string|int, mixed> $args = [] ][, array<string|int, mixed>|null &$params = null ][, string|null $name = null ]) : bool|null
The value defaults to $args[$name], then to the $name property of the current
instance, then to false. When the request carries a $name query parameter, it
is parsed with FILTER_VALIDATE_BOOLEAN and, on success, both the returned value
and the Boolean::TRUE/Boolean::FALSE entry stored in $params are
updated.
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 for
$name. - $params : array<string|int, mixed>|null = null
-
A reference to the parameter bag updated in place with the normalized boolean string.
- $name : string|null = null
-
The name of the boolean parameter to read and store.
Return values
bool|null —The resolved boolean value.