-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
1,841 additions
and
638 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto | ||
|
||
/.gitattributes export-ignore | ||
/.gitignore export-ignore | ||
/.travis.yml export-ignore | ||
/phpunit.xml export-ignore | ||
/phpstan.neon export-ignore | ||
/test export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/vendor/ | ||
/.idea | ||
.DS_Store | ||
*.cache | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
cache: | ||
apt: true | ||
directories: | ||
- $HOME/.composer/cache/files | ||
|
||
language: php | ||
|
||
php: | ||
- 7.4.0 | ||
|
||
before_script: | ||
- travis_retry composer install --no-interaction --no-suggest --prefer-source | ||
|
||
script: | ||
- vendor/bin/phpunit --configuration phpunit.xml --coverage-clover=coverage.xml | ||
|
||
after_success: | ||
- bash <(curl -s https://codecov.io/bash) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,121 @@ | ||
# BitFrame\ErrorHandler\Whoops | ||
# BitFrame\Whoops | ||
|
||
[![codecov](https://codecov.io/gh/designcise/bitframe-whoops/branch/2.x/graph/badge.svg)](https://codecov.io/gh/designcise/bitframe-whoops) | ||
[![Build Status](https://travis-ci.org/designcise/bitframe-whoops.svg?branch=2.x)](https://travis-ci.org/designcise/bitframe-whoops) | ||
|
||
Whoops error handler middleware to handle application or middleware specific errors. | ||
|
||
### Installation | ||
## Installation | ||
|
||
``` | ||
$ composer require "designcise/bitframe-whoops" | ||
``` | ||
|
||
Please note that this package requires PHP 7.4.0 or newer. | ||
|
||
## Quickstart | ||
|
||
### Instantiating | ||
|
||
The constructor has the following signature: | ||
|
||
```php | ||
new ErrorHandler( | ||
\Psr\Http\Message\ResponseFactoryInterface, | ||
\BitFrame\Whoops\Provider\HandlerProviderNegotiator::class | ||
[options] | ||
); | ||
``` | ||
|
||
1. The first argument to the constructor must be an instance of `Psr\Http\Message\ResponseFactoryInterface`; | ||
1. The second argument to the constructor must be the name of the handler provider class (which extends `\BitFrame\Whoops\Provider\AbstractProvider`) | ||
1. The third argument to the constructor is an optional array of options to specify the following: | ||
1. `catchGlobalErrors`: When set to `true` errors will be handled outside of current batch of middleware set. | ||
1. Other options are simply method names in `Whoops\Handler\*Handler.php` and `BitFrame\Whoops\Handler\*Handler.php`. For example, to set `Whoops\Handler\JsonResponseHandler::setJsonApi()` you would pass in: `['setJsonApi' => false]`, etc. | ||
|
||
As a shortcut, you can also use the static method `ErrorHandler::fromNegotiator($factory, $options)`. This would use the `\BitFrame\Whoops\Provider\HandlerProviderNegotiator` by default. | ||
|
||
See [installation docs](https://www.bitframephp.com/middleware/error-handler/whoops) for instructions on installing and using this middleware. | ||
### How to Run the Middleware | ||
|
||
### Usage Example | ||
To run the middleware, simply pass in a `BitFrame\Whoops\ErrorHandler` instance to your middleware runner / dispatcher. | ||
|
||
For example, to handle middleware-specific errors with `BitFrame\App` (or other PSR-15 dispatchers) it would look something like this: | ||
|
||
```php | ||
use BitFrame\App; | ||
use BitFrame\Emitter\SapiEmitter; | ||
use BitFrame\Whoops\ErrorHandler; | ||
use \BitFrame\Whoops\Provider\HandlerProviderNegotiator; | ||
use BitFrame\Factory\HttpFactory; | ||
|
||
$app = new App(); | ||
|
||
$middleware = function () { | ||
throw new \Exception('hello world!'); | ||
}; | ||
|
||
$app->use([ | ||
SapiEmitter::class, | ||
new ErrorHandler(HttpFactory::getFactory(), HandlerProviderNegotiator::class, [ | ||
'addTraceToOutput' => true, | ||
'setJsonApi' => false, | ||
]), | ||
$middleware, | ||
]); | ||
|
||
$app->run(); | ||
``` | ||
use \BitFrame\ErrorHandler\WhoopsErrorHandler; | ||
|
||
require 'vendor/autoload.php'; | ||
To handle global errors with `BitFrame\App` (or other PSR-15 dispatchers) it would look something like this: | ||
|
||
$app = new \BitFrame\Application; | ||
```php | ||
use BitFrame\App; | ||
use BitFrame\Whoops\ErrorHandler; | ||
use BitFrame\Factory\HttpFactory; | ||
|
||
$format = 'auto'; | ||
$handler = new WhoopsErrorHandler($format); | ||
$app = new App(); | ||
|
||
$app->run([ | ||
/* In order to output response from the whoops error handler, | ||
* make sure you include a response emitter middleware, for example: | ||
* \BitFrame\Message\DiactorosResponseEmitter::class, */ | ||
$handler | ||
ErrorHandler::fromNegotiator(HttpFactory::getFactory(), [ | ||
'catchGlobalErrors' => true, | ||
'addTraceToOutput' => true, | ||
'setJsonApi' => false, | ||
]), | ||
]); | ||
|
||
throw new \Exception('hello world!'); | ||
``` | ||
|
||
### Tests | ||
### How Does It Work? | ||
|
||
The error handler middleware automatically determines the error handler to use based on the `Accept` header. The following error handler provders are included: | ||
|
||
1. `BitFrame\Whoops\Provider\HtmlHandlerProvider` for `Whoops\Handler\PrettyPageHandler`; | ||
1. `BitFrame\Whoops\Provider\JsonHandlerProvider` for `Whoops\Handler\JsonResponseHandler`; | ||
1. `BitFrame\Whoops\Provider\JsonpHandlerProvider` for `BitFrame\Whoops\Handler\JsonpResponseHandler`; | ||
1. `BitFrame\Whoops\Provider\TextHandlerProvider` for `Whoops\Handler\PlainTextHandler`; | ||
1. `BitFrame\Whoops\Provider\XmlHandlerProvider` for `Whoops\Handler\XmlResponseHandler`; | ||
|
||
To execute the test suite, you will need [PHPUnit](https://phpunit.de/). | ||
## Tests | ||
|
||
### Contributing | ||
To run the tests you can use the following commands: | ||
|
||
| Command | Type | | ||
| ---------------- |:---------------:| | ||
| `composer test` | PHPUnit tests | | ||
| `composer style` | CodeSniffer | | ||
| `composer md` | MessDetector | | ||
| `composer check` | PHPStan | | ||
|
||
## Contributing | ||
|
||
* File issues at https://github.com/designcise/bitframe-whoops/issues | ||
* Issue patches to https://github.com/designcise/bitframe-whoops/pulls | ||
|
||
### Documentation | ||
|
||
Documentation is available at: | ||
## Documentation | ||
|
||
* https://www.bitframephp.com/middleware/error-handler/whoops/ | ||
Complete documentation for v2.0 will be available soon. | ||
|
||
### License | ||
## License | ||
|
||
Please see [License File](LICENSE.md) for licensing information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
parameters: | ||
treatPhpDocTypesAsCertain: false | ||
reportStaticMethodSignatures: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit bootstrap="vendor/autoload.php" | ||
backupGlobals="false" | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
syntaxCheck="false" | ||
> | ||
> | ||
<testsuites> | ||
<testsuite name="BitFrame Tests"> | ||
<directory>./test/</directory> | ||
<testsuite name="bitframe_whoops"> | ||
<directory suffix="Test.php">./test</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist> | ||
<directory>./src/</directory> | ||
<exclude> | ||
<file>./src/Provider/AbstractProvider.php</file> | ||
</exclude> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
Oops, something went wrong.