Alpha ZealPHP is early-stage and under active development. APIs may change between minor versions until v1.0. Feedback and bug reports welcome on GitHub.
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

$resolver  : MimeResolver

Methods

__construct()  : mixed
process()  : ResponseInterface

Properties

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
Return values
ResponseInterface
On this page