getParamBool.php
Table of Contents
Functions
- getParamBool() : bool|null
- Retrieves a parameter from the HTTP request and ensures it is a boolean.
Functions
getParamBool()
Retrieves a parameter from the HTTP request and ensures it is a boolean.
getParamBool(ServerRequestInterface|null $request, string $name[, array<string|int, mixed> $args = [] ][, bool|null $defaultValue = null ][, string $strategy = HttpParamStrategy::BOTH ][, bool $throwable = false ]) : bool|null
This helper calls getParam() and interprets the value according to Boolean::TRUE and Boolean::FALSE:
- If the value matches
Boolean::TRUEorBoolean::FALSE, it is converted to a PHP boolean. - Otherwise, the
$defaultValueis returned. - If
$throwableis true, a NotFoundException may be thrown bygetParam().
Parameters
- $request : ServerRequestInterface|null
-
The PSR-7 server request instance.
- $name : string
-
The parameter name or dot-notated path.
- $args : array<string|int, mixed> = []
-
Optional default values passed to
getParam(). - $defaultValue : bool|null = null
-
Value returned if the parameter is missing or not a boolean. Default is null.
- $strategy : string = HttpParamStrategy::BOTH
-
Which source to search:
HttpParamStrategy::BOTH|QUERY|BODY. Default is BOTH. - $throwable : bool = false
-
Whether to throw a
NotFoundExceptionif parameter is missing. Default false.
Tags
Return values
bool|null —The parameter value if it is a boolean, otherwise $defaultValue or null.