An open API service indexing awesome lists of open source software.

https://github.com/swoft-cloud/swoft-whoops

[READ ONLY] Swoft errors for cool kids by filp/whoops
https://github.com/swoft-cloud/swoft-whoops

swoft swoft-component swoft-errors swoft-whoops

Last synced: 2 months ago
JSON representation

[READ ONLY] Swoft errors for cool kids by filp/whoops

Awesome Lists containing this project

README

        

# Swoft Whoops

[![Latest Stable Version](http://img.shields.io/packagist/v/swoft/whoops.svg)](https://packagist.org/packages/swoft/whoops)
[![Php Version](https://img.shields.io/badge/php-%3E=7.1-brightgreen.svg?maxAge=2592000)](https://secure.php.net/)
[![Swoft Doc](https://img.shields.io/badge/docs-passing-green.svg?maxAge=2592000)](https://www.swoft.org/docs)
[![Swoft License](https://img.shields.io/hexpm/l/plug.svg?maxAge=2592000)](https://github.com/swoft-cloud/swoft/blob/master/LICENSE)

Swoft http errors for cool kids by [filp/whoops](https://github.com/filp/whoops)

## Install

- composer command

```bash
composer require --dev swoft/whoops
```

## Usage

- Method 1

Use the `Swoft\Whoops\WhoopsMiddleware` as an global middleware(`app/bean.php`):

```php
'httpDispatcher' => [
// Add global http middleware
'middlewares' => [
// Notice: Please add to the first place
\Swoft\Whoops\WhoopsMiddleware::class,
],
],
```

- Method 2

Change the `App\Exception\Handler\HttpExceptionHandler` class:

```php
getRequest();
if ($request->getUriPath() === '/favicon.ico') {
return $response->withStatus(404);
}

// Log
CLog::error($e->getMessage());

// Debug is false
if (!APP_DEBUG) {
return $response
->withStatus(500)
->withContent($e->getMessage());
}

// Debug is true
$whoops = bean(WhoopsHandler::class);
$content = $whoops->run($e, $request);

return $response->withContent($content)->withContentType(ContentType::HTML);;
}
}
```

## LICENSE

The Component is open-sourced software licensed under the [Apache license](LICENSE).