Download the PHP package contenir/contenir-errors-laminas-mvc without Composer
On this page you can find all versions of the php package contenir/contenir-errors-laminas-mvc. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download contenir/contenir-errors-laminas-mvc
More information about contenir/contenir-errors-laminas-mvc
Files in contenir/contenir-errors-laminas-mvc
Package contenir-errors-laminas-mvc
Short Description Laminas MVC adapter for contenir/contenir-errors — swaps the default error rendering with admin-authored per-status pages.
License MIT
Informations about the package contenir-errors-laminas-mvc
contenir/contenir-errors-laminas-mvc
Formerly contenir/errors-laminas-mvc; the old package is abandoned in favour of this one.
Laminas MVC adapter for contenir/contenir-errors.
Replaces the framework's default 4xx/5xx rendering with admin-authored per-status pages, falling back to built-in pages for 403, 404 and 500. Any other status the admin has not authored keeps the framework's default rendering.
Requirements
- PHP 8.3, 8.4 or 8.5
contenir/contenir-errors^2.1laminas/laminas-mvc^3.8,laminas/laminas-view^2.32,laminas/laminas-http^2.19,laminas/laminas-eventmanager^3.11,laminas/laminas-servicemanager^3.22psr/container^1.1 or ^2.0,psr/log^1.0, ^2.0 or ^3.0
The 0.x releases, which support PHP 8.1, remain available from the 0.x
branch and v0.* tags; see UPGRADE-2.0.md. For 2.x to 3.0, see
UPGRADE-3.0.md.
Installation
laminas/laminas-component-installer registers the module
Contenir\Errors\Laminas\Mvc for you. Without it, add that name to your
application's module list.
Configuration
Everything lives under the errors key. All of it is optional.
| Key | Default | Meaning |
|---|---|---|
pages |
[] |
Admin-authored pages, keyed by status: [404 => ['title' => '…', 'body' => '…']] |
view_template |
contenir/errors/fault |
Template rendered for an intercepted error. A missing, null or empty value uses the default. |
logger |
null |
null, a service name resolving to a Psr\Log\LoggerInterface, or a logger instance. Anything else throws a RuntimeException when the listener is built. |
debug |
false |
When true, every 4xx/5xx is still logged but otherwise left to Laminas, so its own 404 and exception output (with the stack trace) render. Set it in development config only. Anything other than a boolean or null throws a RuntimeException when the listener is built. |
Where the pages come from
The admin side of the CMS writes pages with
Contenir\Errors\Repository\FileRepository (from contenir/contenir-errors) to a
file such as config/autoload/errors.local.php:
Laminas merges that file into the application config at boot, and
ErrorListenerFactory builds an in-memory repository from it:
- The built-in pages in
ConfigProvider::DEFAULT_PAGES(403, 404, 500) are seeded first. - Each entry in
errors.pagesreplaces the default for its status. Rows whose key is not an integer, or whose value is not an array, are ignored. A missing or non-scalartitle/bodyreads as''.
To use your own storage instead, register a service named
Contenir\Errors\ErrorPageRepositoryInterface; the factory then uses it
and ignores both the defaults and errors.pages.
How it works
Module::onBootstrap() pulls Listener\ErrorListener from the service
manager and attaches it to two events:
| Event | Priority | Why |
|---|---|---|
MvcEvent::EVENT_RENDER |
Module::RENDER_PRIORITY (100) |
Dispatch-time statuses (404 from the route-not-found strategy, a controller's 403) are already set. |
MvcEvent::EVENT_RENDER_ERROR |
Module::RENDER_ERROR_PRIORITY (-100) |
Runs after Laminas's ExceptionStrategy (priority 1) has set the 500. |
For an HTTP response with a status of 400 or more, the listener:
- Triggers
pagecache.disableon the application's event manager, socontenir/contenir-cache-laminas-mvcdoes not store the error response. Without that package the event is a no-op. - Logs the request through the optional logger:
info()for 4xx,error()for 5xx with the event'sexceptionparameter in the context when there is one. The message isHTTP <status> at <uri>. - In debug mode, stops here and leaves the response to Laminas.
- If the repository has a non-empty page for the status, sets the
template and the variables
status,titleandbodyon the resultViewModel(creating one if the result is not aViewModel), marks it terminal so the layout is skipped, and sets it as the event's view model.
Statuses below 400 and non-HTTP responses are left alone.
You can also wire the listener yourself:
ConfigProvider returns the same configuration as Module::getConfig()
(service_manager, errors defaults and view_manager), split into
getDependencies(), getErrorsDefaults() and getViewManagerConfig().
The view
The shipped contenir/errors/fault template is self-contained: no layout,
inline styles, system fonts, <meta name="robots" content="noindex">, the
.fault BEM block (.fault--<status> on <body>) and a single "Return
home" link. The title is escaped; the body is rendered raw.
To brand the page beyond the body field, point errors.view_template at
your own template. It receives:
| Variable | Type | Notes |
|---|---|---|
$status |
int |
HTTP status code (e.g. 404) |
$title |
string |
Plain text written by the admin |
$body |
string |
Sanitized HTML fragment (inline only); render raw |
The body is trusted: sanitization is the writer's responsibility (see
the admin-side wiring in the consuming CMS). Render it with <?= $body ?>.
Development
The QA toolchain is contenir/contenir-qa-tools.
Mago is a standalone binary, installed
separately (brew install mago).
License
MIT. See LICENSE.
All versions of contenir-errors-laminas-mvc with dependencies
contenir/contenir-errors Version ^2.1
laminas/laminas-eventmanager Version ^3.11
laminas/laminas-http Version ^2.19
laminas/laminas-mvc Version ^3.8
laminas/laminas-servicemanager Version ^3.22
laminas/laminas-view Version ^2.32
psr/container Version ^1.1 || ^2.0
psr/log Version ^1.0 || ^2.0 || ^3.0