getParamI18n.php
Table of Contents
Functions
- getParamI18n() : array<string|int, mixed>|null
- Retrieves an i18n parameter from the HTTP request, optionally filtered by allowed languages.
Functions
getParamI18n()
Retrieves an i18n parameter from the HTTP request, optionally filtered by allowed languages.
getParamI18n(ServerRequestInterface|null $request, string $name[, array<string|int, mixed> $default = [] ][, array<string|int, string>|null $languages = null ][, callable|null $sanitize = null ][, string|null $strategy = HttpParamStrategy::BOTH ][, bool $throwable = false ]) : array<string|int, mixed>|null
This helper retrieves a parameter $name from the PSR-7 $request, supporting query string,
body, or both (HttpParamStrategy). The parameter can be an array or object of translations
(e.g., ['fr' => 'Bonjour', 'en' => 'Hello']). It then filters the values according to $languages
and optionally applies a $sanitize callback on each value.
Nested keys in the request are supported via dot notation (e.g., 'user.profile.email').
If the parameter is not found:
- Returns
$default[$name]if present. - Returns
nullif no default is provided. - Throws
NotFoundExceptionif$throwableis true.
Parameters
- $request : ServerRequestInterface|null
-
The PSR-7 server request instance.
- $name : string
-
The parameter name or dot-notated path.
- $default : array<string|int, mixed> = []
-
Optional default values as an associative array.
- $languages : array<string|int, string>|null = null
-
Optional array of languages to filter the i18n definitions. If null, no filtering is applied.
- $sanitize : callable|null = null
-
Optional callback to transform or sanitize each value. Signature:
fn(string|null $value, string $lang): string|null - $strategy : string|null = HttpParamStrategy::BOTH
-
One of
HttpParamStrategy::QUERY|BODY|BOTH. Default: BOTH. - $throwable : bool = false
-
Whether to throw a
NotFoundExceptionif parameter is missing. Default: false.
Tags
Return values
array<string|int, mixed>|null —The i18n value if found, otherwise the default value or null.