https://github.com/zeuxisoo/php-slim-whoops
PHP whoops error on slim framework
https://github.com/zeuxisoo/php-slim-whoops
middleware php php-slim-whoops slim-framework whoops whoops-errors
Last synced: about 1 year ago
JSON representation
PHP whoops error on slim framework
- Host: GitHub
- URL: https://github.com/zeuxisoo/php-slim-whoops
- Owner: zeuxisoo
- Created: 2013-04-15T07:51:49.000Z (about 13 years ago)
- Default Branch: 0.7.x
- Last Pushed: 2024-04-22T15:18:04.000Z (about 2 years ago)
- Last Synced: 2025-03-31T13:03:06.387Z (about 1 year ago)
- Topics: middleware, php, php-slim-whoops, slim-framework, whoops, whoops-errors
- Language: PHP
- Size: 215 KB
- Stars: 132
- Watchers: 4
- Forks: 10
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-slim - 3.x - Whoops errors on Slim (Packages and Middleware / Videos)
- awesome-slim - Slim Whoops - PHP whoops error on slim framework. (Middlewares)
README
# Slim whoops
PHP whoops error on slim framework
## Status
[](https://github.com/zeuxisoo/php-slim-whoops/actions?query=branch:0.7.x)
[](https://coveralls.io/github/zeuxisoo/php-slim-whoops)
[](https://packagist.org/packages/zeuxisoo/slim-whoops)
[](https://github.com/zeuxisoo/php-slim-whoops/releases)
## Installation
Install the composer
```console
curl -sS https://getcomposer.org/installer | php
```
Edit `composer.json`
| Slim | Whoops | Version | Global Mode | PHP DI |
| ---- | --------- | ------- | ----------- | ------ |
| 1 | n/a | 0.1.* | no | no |
| 2 | 1.* | 0.3.* | no | no |
| 3 | <= 1.* | 0.4.* | no | no |
| 3 | >= 2.* | 0.5.* | no | no |
| 3 | >= 2.* | 0.6.* | yes | yes |
| 4 | >= 2.* | 0.7.* | no | no |
For `Slim framework 4`, The `composer.json` will looks like
```json
{
"require": {
"zeuxisoo/slim-whoops": "0.7.*"
}
}
```
Now, `install` or `update` the dependencies
```console
composer install
```
## Basic Usage
Add to middleware with default settings
```php
$app->add(new Zeuxisoo\Whoops\Slim\WhoopsMiddleware());
```
Or you can pass more settings to the `WhoopsMiddleware`
```php
$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][2], you can custom it like
```php
$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:
```php
$simplyErrorHandler = function($exception, $inspector, $run) {
$message = $exception->getMessage();
$title = $inspector->getExceptionName();
echo "{$title} -> {$message}";
exit;
};
```
And then pass it to the `WhoopsMiddleware`:
```php
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][1]
Version `0.2.0`
- You must to install the `whoops` library manually.
[1]: https://github.com/filp/whoops/blob/master/docs/Framework%20Integration.md#contributing-an-integration-with-a-framework "Whoops Framework Integration Document"
[2]: https://github.com/filp/whoops/blob/master/docs/Open%20Files%20In%20An%20Editor.md#open-files-in-an-editor "Whoops Framework Open Files In An Editor"