Download the PHP package componenta/error-handler without Composer
On this page you can find all versions of the php package componenta/error-handler. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download componenta/error-handler
More information about componenta/error-handler
Files in componenta/error-handler
Package error-handler
Short Description HTTP and CLI error handling for Componenta
License MIT
Informations about the package error-handler
Componenta Error Handler
HTTP and CLI error handling for PHP 8.4+ applications.
The package contains the reusable error handling layer. It does not choose a concrete PSR-7/PSR-17 implementation. HTTP applications must register Psr\Http\Message\ResponseFactoryInterface through one of the componenta/http-psr-* integration packages or provide a custom HttpErrorResponseGeneratorInterface.
Installation
The package declares Componenta\Error\ConfigProvider in extra.componenta.config-providers.
When componenta/composer-plugin is installed, the provider is added to the generated provider list automatically.
Related Packages
| Package | Why it matters here |
|---|---|
componenta/http |
Provides HTTP exception types; PSR request/response integration is implemented by the HTTP error handler and app packages. |
componenta/pipeline |
Usually runs ErrorHandlerMiddleware as the outermost HTTP middleware. |
componenta/event |
Can be used for error reporting listeners. |
psr/log |
Fits logging listeners and reporters. |
componenta/config |
Registers default HTTP/CLI handlers, renderers, and reporters. |
componenta/http-psr-nyholm, componenta/http-psr-diactoros, componenta/http-psr-guzzle, or componenta/http-psr-slim |
Registers the concrete PSR-17 factories used by HTTP response generation. |
What It Provides
- HTTP and CLI aggregate error handlers.
- Fallback response generator for exceptions not handled by a specialized generator. The generator still requires an explicit PSR-17
ResponseFactoryInterface. - Error renderers for safe HTML/JSON, JSON, HTML, plain text, null output, and composite rendering.
- Error reporting listeners for logging, monitoring, and notifications.
- Immutable HTTP and CLI contexts.
- PSR-15 middleware for HTTP applications.
- Config provider for framework integration.
HTTP Usage
Register specialized generators with priorities:
Higher priority generators are checked first.
Custom generators implement HttpErrorResponseGeneratorInterface:
HttpErrorResponseGenerator resolves the response status once through HttpStatusResolver and writes it to the context as ErrorContextAttribute::HTTP_STATUS_CODE before rendering. The default resolver uses HttpStatusAwareInterface, then an exception code in the 400..599 range, then 500.
CLI Usage
Renderers
Built-in renderers:
SafeRendererJsonRendererHtmlRendererPrettyPageRendererPlainTextRendererConsoleErrorRendererNullRendererCompositeErrorRenderer
Fallback generators use safe defaults: HTTP uses SafeRenderer, CLI uses PlainTextRenderer.
Additional renderer integrations live in separate packages:
| Package | Renderer | Typical use |
|---|---|---|
componenta/error-renderer-plates |
PlatesRenderer |
Safe or custom HTML error pages rendered with League Plates templates. |
componenta/error-renderer-whoops |
WhoopsRenderer |
Detailed development error pages through Whoops. |
componenta/error-renderer-symfony |
SymfonyRenderer |
Symfony error page rendering adapted to ErrorRendererInterface. |
componenta/error-renderer-ignition |
IgnitionRenderer |
Spatie Ignition development error pages. |
componenta/error-renderer-collision |
CollisionRenderer |
Rich CLI error output through Collision. |
Contexts
Contexts carry request or command-line information plus arbitrary attributes.
Context objects are immutable: withAttribute() and withAttributes() return a new instance.
HttpContext::fromGlobals() does not create PSR-17 factories by itself. Pass a Nyholm\Psr7Server\ServerRequestCreatorInterface when a context must be built from PHP superglobals:
Reporting
Register listeners for logging or monitoring:
Specific exceptions can be excluded from reporting by class name or predicate.
ErrorReporter accepts a ListenerExceptionPolicy. The default policy swallows listener failures and writes them through error_log(), so error reporting cannot replace the original application exception with a logging failure.
DI Registration
ConfigProvider registers the HTTP/CLI handlers, renderers, reporter, and middleware dependencies needed by Componenta applications.
Important config keys:
| Key | Purpose |
|---|---|
ConfigKey::HTTP_FALLBACK_GENERATOR |
Service id for the fallback HttpErrorResponseGeneratorInterface. |
ConfigKey::HTTP_RENDERER |
Renderer used by the default HTTP response generator. |
ConfigKey::HTTP_GENERATORS |
Ordered service ids for specialized HTTP response generators. |
ConfigKey::HTTP_LISTENERS |
HTTP error listeners. |
ConfigKey::CLI_FALLBACK_HANDLER |
CLI fallback renderer/handler. |
ConfigKey::CLI_RENDERER |
CLI renderer. |
ConfigKey::CLI_LISTENERS |
CLI error listeners. |
ConfigKey::ERROR_REPORTER |
Reporter service. |
ConfigKey::ERROR_ID_GENERATOR |
Error id generator service. |
ConfigKey::ERROR_LEVEL |
Error level handled by ErrorHandlerMiddleware. |
If no ConfigKey::HTTP_FALLBACK_GENERATOR is configured, the default HTTP handler requires Psr\Http\Message\ResponseFactoryInterface in the container.
All versions of error-handler with dependencies
ext-mbstring Version *
componenta/config Version ^1.0
nyholm/psr7-server Version ^1.1
psr/container Version ^2.0
psr/http-factory Version ^1.1
psr/http-message Version ^2.0
psr/http-server-middleware Version ^1.0
symfony/console Version ^7.4 || ^8.0