LocaleSelectorMiddleware
in package
implements
MiddlewareInterface
Sets the runtime default locale for the request based on the Accept-Language header. The default will only be set if it matches the list of passed valid locales.
Table of Contents
Interfaces
- MiddlewareInterface
- Participant in processing a server request and response.
Properties
- $locales : array<string|int, mixed>
- List of valid locales for the request
Methods
- __construct() : mixed
- Constructor.
- process() : ResponseInterface
- Set locale based on request headers.
Properties
$locales
List of valid locales for the request
protected
array<string|int, mixed>
$locales
= []
Methods
__construct()
Constructor.
public
__construct([array<string|int, mixed> $locales = [] ]) : mixed
Parameters
- $locales : array<string|int, mixed> = []
-
A list of accepted locales, or ['*'] to accept any locale header value.
process()
Set locale based on request headers.
public
process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface
Parameters
- $request : ServerRequestInterface
-
The request.
- $handler : RequestHandlerInterface
-
The request handler.
Return values
ResponseInterface —A response.