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.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

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.

Continuous Integration codecov

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

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:

  1. The built-in pages in ConfigProvider::DEFAULT_PAGES (403, 404, 500) are seeded first.
  2. Each entry in errors.pages replaces 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-scalar title/body reads 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:

  1. Triggers pagecache.disable on the application's event manager, so contenir/contenir-cache-laminas-mvc does not store the error response. Without that package the event is a no-op.
  2. Logs the request through the optional logger: info() for 4xx, error() for 5xx with the event's exception parameter in the context when there is one. The message is HTTP <status> at <uri>.
  3. In debug mode, stops here and leaves the response to Laminas.
  4. If the repository has a non-empty page for the status, sets the template and the variables status, title and body on the result ViewModel (creating one if the result is not a ViewModel), 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

PHP Build Version
Package Version
Requires php Version ~8.3.0 || ~8.4.0 || ~8.5.0
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
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package contenir/contenir-errors-laminas-mvc contains the following files

Loading the files please wait ...