Download the PHP package webservco/exception without Composer
On this page you can find all versions of the php package webservco/exception. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download webservco/exception
More information about webservco/exception
Files in webservco/exception
Package exception
Short Description A PHP component/library. Exception handlers that log the exception, for both caught exceptions and the ones nothing else catches.
License MIT
Homepage https://webserv.co
Informations about the package exception
webservco/exception
A PHP component/library. Please see webservco/sandbox for an example project using these types of components.
Exception handlers that log the exception, for both caught exceptions and the ones nothing else catches.
- Related:
webservco/middleware(ExceptionHandlerMiddlewareuses a handler from here),webservco/error(turns PHP errors into exceptions)
Installation
Usage
Uncaught exceptions
Set this handler early in the entry point, as soon as the logger exists.
Caught exceptions
Inside the application, log an exception and keep going. The webservco/sandbox project passes this handler to ExceptionHandlerMiddleware, which logs the exception and then renders an error page.
Contracts
| Interface | Implementation | Purpose |
|---|---|---|
Contract\ExceptionHandlerInterface |
Service\DefaultExceptionHandler |
Logs the exception. |
Contract\UncaughtExceptionHandlerInterface |
Service\DefaultUncaughtExceptionHandler |
Logs the exception, sets status 500 and prints a short message. |
Contract\ExceptionHandlerFactoryInterface |
Factory\DefaultExceptionHandlerFactory |
Creates both handlers for a logger. |
Namespaces are relative to WebServCo\Exception\.
Notes
Both handlers log the message at error level, with the exception in the context under throwable, and also send it to PHP's system log with error_log().
The uncaught handler prints only Application exception. and keeps the details in the log. It doesn't set the status code under the cli and cgi-fcgi SAPIs.
To also report errors to an external service, extend Service\AbstractExceptionHandler and call its log() method from your handle().
Development
License
MIT