PrepareBoolean
Prepares a generic boolean parameter of a controller request.
This trait is the shared building block reused by the dedicated boolean traits
(bench, margin, mock, hasTotal, …). 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_BOOLEAN. When the
request provides a value, the normalized boolean is written back into the parameter
bag as the Boolean::TRUE / Boolean::FALSE string convention.
Only the query string is inspected (the request body is ignored).
Tags
Table of Contents
Methods
- prepareBoolean() : bool|null
- Prepares and returns a boolean value for the given parameter name.
Methods
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.