- What does phphd/exception-handler do?
- phphd/exception-handler is a Composer package that adds a configurable exception handling layer to Laravel and PHP applications. It centralizes exception capture, reporting, and response rendering so errors are handled consistently. The implementation uses the Symfony Messenger component to process exceptions.
- How do I install phphd/exception-handler in Laravel?
- Install it with Composer by running composer require phphd/exception-handler. Laravel's package discovery should register the service provider automatically; if it does not, add the provider to your application's providers configuration. Check the README for any configuration file you need to publish.
- Which Laravel and PHP versions are supported?
- The exact Laravel and PHP version constraints are defined in the package's composer.json and README, so check those before installing. Because it relies on Symfony Messenger, confirm that the required Symfony components are compatible with your framework version. Testing in a staging copy of your app is the safest way to verify support.
- How does Symfony Messenger relate to this exception handler?
- The package is described as implementing exception handling via the Symfony Messenger component. That means Messenger's buses and middleware are used to dispatch and process exceptions, decoupling capture and reporting from controllers. You should be familiar with Messenger concepts if you plan to customize the pipeline.
- Does it replace Laravel's default exception handler?
- It is better thought of as a configurable layer that works alongside Laravel's exception handling rather than a forced replacement. You can integrate it so rendering and reporting are delegated to the package while Laravel still boots the application. Review the README for the recommended integration approach.
- How do I customize which exceptions are captured or ignored?
- The package is configurable, so exception capture and handling behavior is typically controlled through a published config file. Look for options that map exception classes to handlers or reporters and adjust them to your app. The README should list the exact configuration keys and defaults.
- Can I customize the response rendered for exceptions, such as JSON for APIs?
- Yes. Since the package includes response rendering as part of its purpose, you can tailor the output for HTML pages or JSON API responses. Configuration or custom handlers are usually where you define that behavior. Consult the README for the exact rendering hooks and config keys.
- Can I report exceptions to third-party services like Sentry?
- The package centralizes reporting, and its Messenger-based design lets you route exceptions to custom handlers or external services. Direct built-in integrations with specific providers are not confirmed by the provided context, so check the README. In many cases you would write a custom reporter that forwards exceptions to Sentry or a similar service.
- How should I test exception handling with this package?
- Test by throwing exceptions in Laravel feature tests and asserting both the rendered response and any reported side effects. Use the sync Messenger transport or fake the relevant bus so exceptions are processed immediately during tests. You can also mock custom reporters to verify they receive the expected exception.
- Is phphd/exception-handler safe for production, and what are the alternatives?
- Before using it in production, review the package's maintenance activity, test coverage, open issues, and security posture. Make sure exception responses do not leak sensitive details and that reporting transports are configured safely. Common alternatives include Laravel's built-in exception handler, Sentry, Flare, and Bugsnag; this package stands out for its Symfony Messenger-based approach.