4
4
* BitFrame Framework (https://www.bitframephp.com)
5
5
*
6
6
* @author Daniyal Hamid
7
- * @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
7
+ * @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
8
8
* @license https://bitframephp.com/about/license MIT License
9
9
*/
10
10
@@ -37,11 +37,6 @@ class ErrorHandler implements MiddlewareInterface
37
37
38
38
private RunInterface $ whoops ;
39
39
40
- private ResponseFactoryInterface $ responseFactory ;
41
-
42
- /** @var ProviderInterface|string */
43
- private $ handlerProvider ;
44
-
45
40
private array $ options ;
46
41
47
42
private bool $ catchGlobalErrors ;
@@ -50,7 +45,7 @@ class ErrorHandler implements MiddlewareInterface
50
45
51
46
public static function fromNegotiator (
52
47
ResponseFactoryInterface $ responseFactory ,
53
- array $ options = []
48
+ array $ options = [],
54
49
): self {
55
50
return new self (
56
51
$ responseFactory ,
@@ -59,19 +54,11 @@ public static function fromNegotiator(
59
54
);
60
55
}
61
56
62
- /**
63
- * @param ResponseFactoryInterface $responseFactory
64
- * @param string|ProviderInterface $handlerProvider
65
- * @param array $options
66
- */
67
57
public function __construct (
68
- ResponseFactoryInterface $ responseFactory ,
69
- $ handlerProvider = HandlerProviderNegotiator::class,
70
- array $ options = []
58
+ private ResponseFactoryInterface $ responseFactory ,
59
+ private ProviderInterface | string $ handlerProvider = HandlerProviderNegotiator::class,
60
+ array $ options = [],
71
61
) {
72
- $ this ->responseFactory = $ responseFactory ;
73
- $ this ->handlerProvider = $ handlerProvider ;
74
-
75
62
if (! is_a ($ this ->handlerProvider , ProviderInterface::class, true )) {
76
63
throw new InvalidArgumentException (
77
64
'Handler provider must be instance of ' . ProviderInterface::class
@@ -91,7 +78,7 @@ public function __construct(
91
78
*/
92
79
public function process (
93
80
ServerRequestInterface $ request ,
94
- RequestHandlerInterface $ handler
81
+ RequestHandlerInterface $ handler,
95
82
): ResponseInterface {
96
83
$ this ->whoops ->allowQuit (false );
97
84
$ this ->whoops ->writeToOutput ($ this ->catchGlobalErrors );
@@ -131,7 +118,6 @@ public function handleException(Throwable $exception): string
131
118
132
119
$ this ->system ->startOutputBuffering ();
133
120
134
- $ handlerResponse = null ;
135
121
$ handlerContentType = null ;
136
122
$ handlerStack = array_reverse ($ this ->whoops ->getHandlers ());
137
123
@@ -147,7 +133,7 @@ public function handleException(Throwable $exception): string
147
133
? $ handler ->contentType ()
148
134
: null ;
149
135
150
- if (in_array ($ handlerResponse , [Handler::LAST_HANDLER , Handler::QUIT ])) {
136
+ if (in_array ($ handlerResponse , [Handler::LAST_HANDLER , Handler::QUIT ], true )) {
151
137
break ;
152
138
}
153
139
}
@@ -156,7 +142,7 @@ public function handleException(Throwable $exception): string
156
142
}
157
143
158
144
if ($ this ->whoops ->writeToOutput ()) {
159
- if (Misc::canSendHeaders () && $ handlerContentType ) {
145
+ if ($ handlerContentType && Misc::canSendHeaders ()) {
160
146
header ("Content-Type: {$ handlerContentType }" , true , $ this ->getStatusCode ());
161
147
}
162
148
0 commit comments