Download the PHP package samuelgfeller/slim-error-renderer without Composer

On this page you can find all versions of the php package samuelgfeller/slim-error-renderer. 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 slim-error-renderer

Slim Error Renderer

Latest Version on Packagist Build Status Total Downloads

This package provides an alternative to the default Slim error handler and renderer.
It renders a styled error details page with the stack trace and the error message or a generic error page for production.

Custom error page renderers can be created to change the design of the error pages by implementing the ErrorDetailsPageRendererInterface or GenericErrorPageRendererInterface.

It also provides a middleware to make the project "exception-heavy", which means that it will throw exceptions with a stack trace for notices and warnings during development and testing like other frameworks such as Laravel or Symfony.

Preview

Exception Warning and Notice Generic error page

Requirements

Installation

Install the package with composer

Open a terminal in your project's root directory and run the following command:

Configuration

The following configuration values are required in the settings. Modify accordingly in the development, production, and testing configuration files.

File: config/defaults.php

Add the error handling middleware to the Slim app

Container instantiation

If you're using Dependency Injection, add the error handling middleware to the container definitions (e.g. in the config/container.php) file. The ExceptionHandlingMiddleware constructor accepts the following parameters:

  1. Required: instance of a response factory object implementing the Psr\Http\Message\ResponseFactoryInterface (see here for a default implementation of a response factory)
  2. Optional: instance of a PSR 3 logger to log the error
  3. Optional: boolean to display error details (documentation: Error Handling)
  4. Optional: contact email for the "report error" button on the error page
  5. Optional: A custom generic error page renderer that implements SlimErrorRenderer\Interfaces\ProdErrorPageRendererInterface
  6. Optional: A custom error details page renderer that implements SlimErrorRenderer\Interfaces\ErrorDetailsPageRendererInterface

Middleware stack

The middleware can now be added to the middleware stack in the config/middleware.php file.
It should be the very last middleware in the stack to catch all exceptions (Slim middlewares are executed in the reverse order they are added).
This replaces the default slim error middleware.

"Exception-heavy" middleware

The NonFatalErrorHandlingMiddleware promotes warnings and notices to exceptions when the display_error_details setting is set to true in the configuration.
This means that the error details for notices and warnings will be displayed with the stack trace and error message.

Container instantiation

The NonFatalErrorHandlingMiddleware also needs to be instantiated in the container.

The constructor takes three parameters:

  1. Required: bool to display error details
  2. Required: bool to log the warning / notice
  3. Optional: instance of a PSR 3 logger to log the warning / notice

Add to middleware stack

The middleware should be added right above the ExceptionHandlingMiddleware in the stack.

File: config/middleware.php

Conclusion

Have a look a the slim-starter for a default implementation of this package and the slim-example-project for a custom prod error page with layout.

Why use this package?

A reason this small library exists instead of using the default Slim error handler and a custom error renderer, is to provide the "exception-heavy" feature and better-looking error pages.
But these things can be achieved with a custom error renderer and middleware located in the project as well.

The issue with the default Slim\Handlers\ErrorHandler is that while testing, the $contentType in the error handler is null and instead of using any custom error renderer its hardcoded to use the Slim\Error\Renderers\HtmlErrorRenderer. This has two consequences:

  1. The error is not thrown while integration testing, which means debugging is harder.
  2. Tests where an exception is expected, fail with the PHPUnit 11 warning Test code or tested code did not remove its own error handlers. A fix for this message is calling restore_error_handler() but this can't be done as the error handler doesn't allow for custom error renderers when testing.

So a custom handler is required anyway, and with the custom renderers and the handling of non-fatal errors, it made sense to put that in a separate small library.

License

This project is licensed under the MIT license — see the LICENSE file for details.


All versions of slim-error-renderer with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
ext-json Version *
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 samuelgfeller/slim-error-renderer contains the following files

Loading the files please wait ....