API Index — Namespaces, Packages, Reports, Indices
ContentLanguageMiddleware
in package
implements
MiddlewareInterface
Content-Language Middleware — Apache mod_mime AddLanguage parity.
Sets the response Content-Language header from the request URL's file
suffixes. Apache find_ct (mod_mime.c:938–946) accumulates a language list
across suffixes — page.en.html with AddLanguage en .en yields
Content-Language: en. Multiple language suffixes accumulate in order and
are emitted comma-joined (RFC 9110 §8.5 allows a list). The multi-suffix
walk is delegated to MimeResolver.
This middleware is ADDITIVE and OPT-IN: with the default empty map it never
touches the response, and it only sets Content-Language when the response
doesn't already declare one (an explicit handler value wins).
Apache equivalent:
AddLanguage en .en
AddLanguage fr .fr
AddLanguage de .de
Usage in app.php:
$app->addMiddleware(new \ZealPHP\Middleware\ContentLanguageMiddleware([
'en' => 'en',
'fr' => 'fr',
'de' => 'de',
]));
Table of Contents
Interfaces
- MiddlewareInterface
Properties
Methods
- __construct() : mixed
- process() : ResponseInterface
Properties
$resolver
private
MimeResolver
$resolver
Methods
__construct()
public
__construct([array<string, string|int> $map = [] ]) : mixed
Parameters
- $map : array<string, string|int> = []
-
ext => content-language (e.g. fr => fr)
process()
public
process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface
Parameters
- $request : ServerRequestInterface
- $handler : RequestHandlerInterface