zeuxisoo / slim-whoops
PHP whoops error on slim framework
Installs: 930 379
Dependents: 42
Suggesters: 0
Security: 0
Stars: 132
Watchers: 4
Forks: 10
Open Issues: 2
Requires
- php: ^7.2 || ^8.0
- filp/whoops: ^2.9
Requires (Dev)
- equip/dispatch: ^2.0
- phpunit/phpunit: ^8.5 || ^9.3
- slim/http: 1.2.*
- slim/psr7: 1.3.*
- slim/slim: 4.7.*
- slim/twig-view: 3.2.*
README
PHP whoops error on slim framework
Status
Installation
Install the composer
curl -sS https://getcomposer.org/installer | php
Edit composer.json
For Slim framework 4
, The composer.json
will looks like
{ "require": { "zeuxisoo/slim-whoops": "0.7.*" } }
Now, install
or update
the dependencies
composer install
Basic Usage
Add to middleware with default settings
$app->add(new Zeuxisoo\Whoops\Slim\WhoopsMiddleware());
Or you can pass more settings to the WhoopsMiddleware
$app->add(new Zeuxisoo\Whoops\Slim\WhoopsMiddleware([ 'enable' => true, 'editor' => 'sublime', 'title' => 'Custom whoops page title', ]));
Custom Editor String
If your editor do not included in default editor list, you can custom it like
$app->add(new Zeuxisoo\Whoops\Slim\WhoopsMiddleware([ 'editor' => function($file, $line) { return "http://localhost:8091?message=%file:%line"; } ]));
Custom Handler Usage
In this usage, you can make your own handler for whoops, like:
$simplyErrorHandler = function($exception, $inspector, $run) { $message = $exception->getMessage(); $title = $inspector->getExceptionName(); echo "{$title} -> {$message}"; exit; };
And then pass it to the WhoopsMiddleware
:
new Zeuxisoo\Whoops\Slim\WhoopsMiddleware([], [$simplyErrorHandler]);
Important Note
Version 0.3.0
or above version
- The
whoops
library is installed by default base on the Whoops Framework Integration Document
Version 0.2.0
- You must to install the
whoops
library manually.