Download the PHP package snicco/psr7-error-handler without Composer

On this page you can find all versions of the php package snicco/psr7-error-handler. 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 psr7-error-handler

A powerful and customizable error handler for PSR-7/PSR-15 applications

codecov Psalm Type-Coverage Psalm level PhpMetrics - Static Analysis PHP-Versions

The ErrorHandler component of the Snicco project is a standalone error handler for PHP applications that use PSR-7 requests.

Table of contents

  1. Installation
  2. Needed collaborators
    1. RequestAwareLogger
    2. ExceptionInformationProvider
    3. ExceptionDisplayer
  3. Full example
  4. Exception utilities
  5. Contributing
  6. Issues and PR's
  7. Security

Installation

Collaborators for the HTTP error handler

On a high level, the HttpErrorHandler interface is responsible for transforming instances of Throwable into instances of Psr\Http\Message\ResponseInterface.

This package provides a TestErrorHandler, which just re-throws exceptions and a ProductionErrorHandler, which is the main focus of this documentation.

To instantiate the ProductionErrorHandler, we need the following collaborators:


The RequestAwareLogger

The RequestAwareLogger is a simple wrapper class around a PSR-3 logger.

It allows you to add log context to each log entry depending on the caught exception, the current request, etc.

The last argument passed to RequestAwareLogger::__construct() is variadic and accepts instances of RequestLogContext.

This is how you use it:

(Monolog is just an example, you can use any PSR-3 logger.)


The ExceptionInformationProvider

The ExceptionInformationProvider is responsible for converting instances of Throwable to an instance of ExceptionInformation.

ExceptionInformation is a value object that consist of:

This package comes with a InformationProviderWithTransformation implementation of that interface.

You can instantiate this class like so:

As its class name suggests, the InformationProviderWithTransformation allows you to transform exceptions into other kinds of exceptions.

This is done by using ExceptionTransformers.

An example on how to transform custom exception classes to an instance of HttpException.

If you provide no ExceptionTransformers every exception will be converted to a HttpException)


The ExceptionDisplayer

An ExceptionDisplayer is responsible for displaying ExceptionInformation.

An ExceptionDisplayer has one content-type that it supports.

The ProductionExceptionHandler accepts one or more ExceptionDisplayers and will determine the best displayer for the current request.

This package comes with two default displayers that will be used as a fallback:

The best displayer for the combination of exception/request is determined by using DisplayerFilters.

Out of the box this package comes with the following filters:

Full working example

This is a working example of how you would instantiate the ProductionErrorHandler, preferably in your dependency-injection container.

Then use the instantiated error handler in a middleware like so:

Exception utilities

User-facing exceptions

This package comes with a UserFacing interface, which your custom exceptions can implement.

If an exception that implements UserFacing is thrown, the return values of UserFacing::safeTitle() and UserFacing::safeMessage() will be used to create the ExceptionInformation, instead of the default HTTP error messages that might not make sense to your users.

The original exception message will be logged while your users get to see something they can relate (a little more) to.

HTTP exceptions

This packages comes with a generic HTTPException class that you can throw in your HTTP related code (mostly middleware).

This allows you to dictate the HTTP response code and optionally additional response headers.

The difference between using the HTTPException class and using an ExceptionTransformer is that the latter is intended for your domain exceptions while HTTPExceptions should be thrown only in HTTP related code (like middleware and Controllers).

Contributing

This repository is a read-only split of the development repo of the Snicco project.

This is how you can contribute.

Reporting issues and sending pull requests

Please report issues in the Snicco monorepo.

Security

If you discover a security vulnerability, please follow our disclosure procedure.


All versions of psr7-error-handler with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4|^8.0
psr/log Version ^1.1.1
psr/http-message Version ^1.0.0
psr/http-factory Version ^1.0.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 snicco/psr7-error-handler contains the following files

Loading the files please wait ....