Skip to content

Commit 4a2b8df

Browse files
authoredMay 11, 2020
v2.0.0 (#1)
2 parents 3c76436 + c5bf8ce commit 4a2b8df

32 files changed

+1841
-638
lines changed
 

‎.gitattributes

+7
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
# Auto detect text files and perform LF normalization
22
* text=auto
3+
4+
/.gitattributes export-ignore
5+
/.gitignore export-ignore
6+
/.travis.yml export-ignore
7+
/phpunit.xml export-ignore
8+
/phpstan.neon export-ignore
9+
/test export-ignore

‎.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/vendor/
2+
/.idea
3+
.DS_Store
4+
*.cache
5+
composer.lock

‎.travis.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
cache:
2+
apt: true
3+
directories:
4+
- $HOME/.composer/cache/files
5+
6+
language: php
7+
8+
php:
9+
- 7.4.0
10+
11+
before_script:
12+
- travis_retry composer install --no-interaction --no-suggest --prefer-source
13+
14+
script:
15+
- vendor/bin/phpunit --configuration phpunit.xml --coverage-clover=coverage.xml
16+
17+
after_success:
18+
- bash <(curl -s https://codecov.io/bash)

‎LICENSE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Portions of the "BitFrame Whoops Middleware" incorporates the work by (as provid
55

66
All other copyright for the "BitFrame Whoops Middleware" are held by:
77

8-
* Copyright (c) 2017-2018 Daniyal Hamid (https://designcise.com)
8+
* Copyright (c) 2017-2020 Daniyal Hamid (https://designcise.com)
99

1010
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
1111

‎README.md

+96-21
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,121 @@
1-
# BitFrame\ErrorHandler\Whoops
1+
# BitFrame\Whoops
2+
3+
[![codecov](https://codecov.io/gh/designcise/bitframe-whoops/branch/2.x/graph/badge.svg)](https://codecov.io/gh/designcise/bitframe-whoops)
4+
[![Build Status](https://travis-ci.org/designcise/bitframe-whoops.svg?branch=2.x)](https://travis-ci.org/designcise/bitframe-whoops)
25

36
Whoops error handler middleware to handle application or middleware specific errors.
47

5-
### Installation
8+
## Installation
9+
10+
```
11+
$ composer require "designcise/bitframe-whoops"
12+
```
13+
14+
Please note that this package requires PHP 7.4.0 or newer.
15+
16+
## Quickstart
17+
18+
### Instantiating
19+
20+
The constructor has the following signature:
21+
22+
```php
23+
new ErrorHandler(
24+
\Psr\Http\Message\ResponseFactoryInterface,
25+
\BitFrame\Whoops\Provider\HandlerProviderNegotiator::class
26+
[options]
27+
);
28+
```
29+
30+
1. The first argument to the constructor must be an instance of `Psr\Http\Message\ResponseFactoryInterface`;
31+
1. The second argument to the constructor must be the name of the handler provider class (which extends `\BitFrame\Whoops\Provider\AbstractProvider`)
32+
1. The third argument to the constructor is an optional array of options to specify the following:
33+
1. `catchGlobalErrors`: When set to `true` errors will be handled outside of current batch of middleware set.
34+
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.
35+
36+
As a shortcut, you can also use the static method `ErrorHandler::fromNegotiator($factory, $options)`. This would use the `\BitFrame\Whoops\Provider\HandlerProviderNegotiator` by default.
637

7-
See [installation docs](https://www.bitframephp.com/middleware/error-handler/whoops) for instructions on installing and using this middleware.
38+
### How to Run the Middleware
839

9-
### Usage Example
40+
To run the middleware, simply pass in a `BitFrame\Whoops\ErrorHandler` instance to your middleware runner / dispatcher.
1041

42+
For example, to handle middleware-specific errors with `BitFrame\App` (or other PSR-15 dispatchers) it would look something like this:
43+
44+
```php
45+
use BitFrame\App;
46+
use BitFrame\Emitter\SapiEmitter;
47+
use BitFrame\Whoops\ErrorHandler;
48+
use \BitFrame\Whoops\Provider\HandlerProviderNegotiator;
49+
use BitFrame\Factory\HttpFactory;
50+
51+
$app = new App();
52+
53+
$middleware = function () {
54+
throw new \Exception('hello world!');
55+
};
56+
57+
$app->use([
58+
SapiEmitter::class,
59+
new ErrorHandler(HttpFactory::getFactory(), HandlerProviderNegotiator::class, [
60+
'addTraceToOutput' => true,
61+
'setJsonApi' => false,
62+
]),
63+
$middleware,
64+
]);
65+
66+
$app->run();
1167
```
12-
use \BitFrame\ErrorHandler\WhoopsErrorHandler;
1368

14-
require 'vendor/autoload.php';
69+
To handle global errors with `BitFrame\App` (or other PSR-15 dispatchers) it would look something like this:
1570

16-
$app = new \BitFrame\Application;
71+
```php
72+
use BitFrame\App;
73+
use BitFrame\Whoops\ErrorHandler;
74+
use BitFrame\Factory\HttpFactory;
1775

18-
$format = 'auto';
19-
$handler = new WhoopsErrorHandler($format);
76+
$app = new App();
2077

2178
$app->run([
22-
/* In order to output response from the whoops error handler,
23-
* make sure you include a response emitter middleware, for example:
24-
* \BitFrame\Message\DiactorosResponseEmitter::class, */
25-
$handler
79+
ErrorHandler::fromNegotiator(HttpFactory::getFactory(), [
80+
'catchGlobalErrors' => true,
81+
'addTraceToOutput' => true,
82+
'setJsonApi' => false,
83+
]),
2684
]);
85+
86+
throw new \Exception('hello world!');
2787
```
2888

29-
### Tests
89+
### How Does It Work?
90+
91+
The error handler middleware automatically determines the error handler to use based on the `Accept` header. The following error handler provders are included:
92+
93+
1. `BitFrame\Whoops\Provider\HtmlHandlerProvider` for `Whoops\Handler\PrettyPageHandler`;
94+
1. `BitFrame\Whoops\Provider\JsonHandlerProvider` for `Whoops\Handler\JsonResponseHandler`;
95+
1. `BitFrame\Whoops\Provider\JsonpHandlerProvider` for `BitFrame\Whoops\Handler\JsonpResponseHandler`;
96+
1. `BitFrame\Whoops\Provider\TextHandlerProvider` for `Whoops\Handler\PlainTextHandler`;
97+
1. `BitFrame\Whoops\Provider\XmlHandlerProvider` for `Whoops\Handler\XmlResponseHandler`;
3098

31-
To execute the test suite, you will need [PHPUnit](https://phpunit.de/).
99+
## Tests
32100

33-
### Contributing
101+
To run the tests you can use the following commands:
102+
103+
| Command | Type |
104+
| ---------------- |:---------------:|
105+
| `composer test` | PHPUnit tests |
106+
| `composer style` | CodeSniffer |
107+
| `composer md` | MessDetector |
108+
| `composer check` | PHPStan |
109+
110+
## Contributing
34111

35112
* File issues at https://github.com/designcise/bitframe-whoops/issues
36113
* Issue patches to https://github.com/designcise/bitframe-whoops/pulls
37114

38-
### Documentation
39-
40-
Documentation is available at:
115+
## Documentation
41116

42-
* https://www.bitframephp.com/middleware/error-handler/whoops/
117+
Complete documentation for v2.0 will be available soon.
43118

44-
### License
119+
## License
45120

46121
Please see [License File](LICENSE.md) for licensing information.

‎composer.json

+19-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "designcise/bitframe-whoops",
3-
"version": "1.0.1",
3+
"version": "2.0.0",
44
"type": "library",
5-
"description": "Whoops error handler middleware for BitFrame microframework",
5+
"description": "Whoops error handler middleware",
66
"license": "MIT",
77
"authors": [
88
{
@@ -11,25 +11,33 @@
1111
}
1212
],
1313
"require": {
14-
"php": ">=7.1.0",
15-
"designcise/bitframe": "^1.0.0",
16-
"filp/whoops": "~2.1",
14+
"php": ">=7.4.0",
15+
"filp/whoops": "~2.7",
16+
"psr/http-factory": "~1.0",
1717
"psr/http-server-handler": "~1.0",
18-
"psr/http-server-middleware": "~1.0",
19-
"symfony/var-dumper": "^2.6 || ^3.0",
20-
"zendframework/zend-diactoros": "^1.1.0"
18+
"psr/http-server-middleware": "~1.0"
2119
},
2220
"require-dev": {
23-
"phpunit/phpunit": "^6.4"
21+
"phpunit/phpunit": "^8.5",
22+
"phpspec/prophecy": "~1.0",
23+
"squizlabs/php_codesniffer": "3.*",
24+
"phpmd/phpmd": "@stable",
25+
"phpstan/phpstan": "*"
26+
},
27+
"scripts": {
28+
"style": "vendor/bin/phpcs --standard=PSR12 src",
29+
"check": "vendor/bin/phpstan analyse src --level=5 -c phpstan.neon",
30+
"md": "vendor/bin/phpmd src text cleancode,unusedcode,codesize,design,naming",
31+
"test": "vendor/bin/phpunit --configuration phpunit.xml --testsuite bitframe_whoops"
2432
},
2533
"autoload": {
2634
"psr-4": {
27-
"BitFrame\\ErrorHandler\\": "src/"
35+
"BitFrame\\Whoops\\": "src/"
2836
}
2937
},
3038
"autoload-dev": {
3139
"psr-4": {
32-
"BitFrame\\Test\\": "test/"
40+
"BitFrame\\Whoops\\Test\\": "test/"
3341
}
3442
}
3543
}

‎phpstan.neon

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
parameters:
2+
treatPhpDocTypesAsCertain: false
3+
reportStaticMethodSignatures: false

‎phpunit.xml

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<phpunit bootstrap="vendor/autoload.php"
4-
backupGlobals="false"
3+
<phpunit backupGlobals="false"
54
backupStaticAttributes="false"
65
colors="true"
76
convertErrorsToExceptions="true"
87
convertNoticesToExceptions="true"
98
convertWarningsToExceptions="true"
109
processIsolation="false"
11-
syntaxCheck="false"
12-
>
10+
>
1311
<testsuites>
14-
<testsuite name="BitFrame Tests">
15-
<directory>./test/</directory>
12+
<testsuite name="bitframe_whoops">
13+
<directory suffix="Test.php">./test</directory>
1614
</testsuite>
1715
</testsuites>
1816

1917
<filter>
2018
<whitelist>
2119
<directory>./src/</directory>
20+
<exclude>
21+
<file>./src/Provider/AbstractProvider.php</file>
22+
</exclude>
2223
</whitelist>
2324
</filter>
2425
</phpunit>

0 commit comments

Comments
 (0)