Download the PHP package contenir/errors-mezzio without Composer

On this page you can find all versions of the php package contenir/errors-mezzio. 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 errors-mezzio

contenir/contenir-errors-mezzio

Formerly contenir/errors-mezzio; the old package is abandoned in favour of this one.

Continuous Integration codecov

Mezzio (PSR-15) adapter for contenir/contenir-errors. The sibling of contenir/contenir-errors-laminas-mvc.

Re-renders 4xx/5xx HTML responses with the admin-authored page for their status. Non-invasive on first install — when the admin hasn't authored a page for a given status, the response Mezzio produced passes through unchanged.

Requirements

The 0.x releases remain available from the 0.x branch and v0.* tags; see UPGRADE-2.0.md.

Install

laminas/laminas-component-installer adds the ConfigProvider to config/config.php for you. Without it, add it by hand:

The ConfigProvider registers the ErrorPageMiddleware factory and a contenir-errors template namespace pointing at the bundled templates/ directory.

Pipe it first

Pipe ErrorPageMiddleware as the outermost middleware, before Mezzio's ErrorHandler:

The middleware acts on the response on its way out, so it has to sit outside everything that can produce an error status:

Piped after the ErrorHandler, it would never see the 500: the exception would pass straight through it and be turned into a response further out.

Configure

Every key is optional:

file

The PHP file the Contenir admin writes the pages to, through Contenir\Errors\Repository\FileRepository. Defaults to config/autoload/errors.local.php under the working directory, which is the site root for a Mezzio app served from public/index.php:

The middleware reads this file on each error response rather than taking errors.pages from the merged config. That is deliberate: Mezzio caches the merged config in production (config/autoload/* is aggregated once into data/cache/config-cache.php), so pages read from config would not change until that cache was cleared, and an editor's save in the admin would appear to do nothing. Reading the file costs one include per error response, which opcache serves from memory; the admin's writer invalidates the opcache entry on save. If the site runs in a separate PHP pool from the admin with opcache.validate_timestamps=0, that invalidation does not reach the site's pool, so reset its opcache (or leave timestamp validation on) for saves to show.

To read the pages from somewhere else, register a service for Contenir\Errors\ErrorPageRepositoryInterface. When one is registered it is used instead and file is ignored.

logger

logger may be null or the name of a container service implementing Psr\Log\LoggerInterface. Every 4xx/5xx is logged whether or not a page is configured for it: info() for 4xx, error() for 5xx, with the message HTTP <status> at <uri>. These are the same levels and message as the Laminas MVC adapter. The exception behind a 500 is not available here, because the ErrorHandler inside has already turned it into a response; log exceptions with an ErrorHandler listener if you need them.

debug

debug (default false) is the development escape hatch. When true the middleware still logs, but returns every response untouched, so Whoops (or the ErrorHandler's own exception output) reaches the browser instead of the polite admin page. Set it from the development config alongside Mezzio's own debug flag:

What gets re-rendered

The middleware leaves the response alone when:

Otherwise it renders view_template with the page and returns a response that keeps the original status code and headers, with:

Override the template

The bundled contenir-errors::fault template is a content fragment that renders inside the site's normal layout. It is written for mezzio/mezzio-laminasviewrenderer. To brand the page beyond what the body field allows, or to use another renderer, set errors.view_template to a template of your own:

Your template receives:

Variable Type Notes
$status int HTTP status code (e.g. 404)
$title string Plain text written by the admin — escape it
$body string Sanitized HTML fragment (inline only) — render raw

The body is trusted — sanitization is the writer's responsibility (the admin passes it through an inline-HTML sanitizer before saving). Render it with <?= $body ?>.

Layout

layout controls the layout the template renders in:

Leftover view state

The admin's page usually renders after the site has already rendered its own (the NotFoundHandler's 404, the ErrorHandler's 500) in the same request. laminas-view's head and script helpers keep what that first render added, so the error page would repeat its title, meta tags and scripts. When the container has Laminas\View\HelperPluginManager (any mezzio-laminasviewrenderer site), the factory wires LaminasView\PlaceholderReset, which empties headTitle, headMeta, headLink, headScript, headStyle and inlineScript just before the page renders. Another engine with the same problem can pass its own ViewStateResetInterface to the middleware.

Public API

Class Purpose
ConfigProvider __invoke(), getDependencies() and getTemplates() register the factory and the contenir-errors template namespace (TEMPLATE_NAMESPACE).
Factory\ErrorPageMiddlewareFactory Builds the middleware from config['errors']. DEFAULT_FILE is the pages file relative to the working directory.
ErrorPageMiddleware The PSR-15 middleware. Constructor: (ErrorPageRepositoryInterface $repository, TemplateRendererInterface $renderer, ?LoggerInterface $logger = null, ErrorPageOptions $options = new ErrorPageOptions(), ?ViewStateResetInterface $viewStateReset = null).
ErrorPageOptions viewTemplate, layout and debug. fromConfig(array $errors) reads them from config['errors']; DEFAULT_VIEW_TEMPLATE is contenir-errors::fault.
ViewStateResetInterface reset(): void, called just before the page renders.
LaminasView\PlaceholderReset The laminas-view implementation; HELPERS lists the placeholders it empties.
Exception\InvalidConfigurationException Thrown when the container builds the middleware if a config['errors'] value has the wrong type (for example view_template set to '', debug set to 'yes'), or logger names a service that is not a PSR-3 logger. A misconfigured site fails on its first request, not its first error.

Building the middleware without the factory:

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 errors-mezzio with dependencies

PHP Build Version
Package Version
Requires php Version ~8.3.0 || ~8.4.0 || ~8.5.0
contenir/contenir-config Version ^2.1
contenir/contenir-errors Version ^2.1
laminas/laminas-diactoros Version ^3.0
mezzio/mezzio-template Version ^2.0
psr/container Version ^1.1 || ^2.0
psr/http-message Version ^1.1 || ^2.0
psr/http-server-middleware Version ^1.0
psr/log Version ^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/errors-mezzio contains the following files

Loading the files please wait ...