memran / marwa-error-handler
Framework-agnostic PHP error handling with PSR-3 logging, optional debug reporting, and safe fallback rendering.
Requires
- php: >=8.1
- psr/log: ^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.80
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.0
README
Production-focused, framework-agnostic PHP error handling with PSR-3 logging, optional debug reporting, and safe fallback rendering for HTTP and CLI applications.
Requirements
- PHP 8.1 or newer
- Composer
- Optional: a PSR-3 compatible logger such as Monolog
Installation
composer require memran/marwa-error-handler
Usage
use Marwa\ErrorHandler\ErrorHandler; ErrorHandler::bootstrap( appName: 'MyApp', env: 'production', logger: $logger, debugbar: $debugReporter, // optional callable/object reporter );
For manual wiring:
$handler = new ErrorHandler(appName: 'MyApp', env: 'development'); $handler->setLogger($logger); $handler->setDebugbar($debugReporter); $handler->register();
Configuration
appName: used in logs and fallback pages.env:development,dev,local, anddebugenable detailed dev output.logger: anyPsr\Log\LoggerInterface; logger failures are safely ignored.debugbar: optional callable or object withaddThrowable(),addException(), oraddMessage().renderer: optional customRendererInterfaceimplementation for full control over output.
Safe defaults:
- Production never renders exception details in HTML.
- CLI output stays concise in production.
- Request IDs from headers are validated before being echoed.
Testing
composer install
composer test
composer test:coverage
Static Analysis
composer analyse composer lint composer fix
PHPStan runs at max level against src/. PHP-CS-Fixer enforces PSR-12-oriented formatting.
CI/CD
GitHub Actions runs the package on PHP 8.1, 8.2, and 8.3 using the workflow in .github/workflows/ci.yml. The pipeline executes formatting checks, static analysis, and PHPUnit.
Contributing
Open a focused pull request with a clear summary, test evidence, and notes about any behavior changes. Follow the repository conventions in AGENTS.md, keep examples framework-agnostic, and avoid introducing optional integrations as hard runtime dependencies.