1717use function restore_error_handler ;
1818use function set_error_handler ;
1919
20- /**
21- * Error handler middleware.
22- *
23- * Use this middleware as the outermost (or close to outermost) middleware
24- * layer, and use it to intercept PHP errors and exceptions.
25- *
26- * The class offers two extension points:
27- *
28- * - Error response generators.
29- * - Listeners.
30- *
31- * Error response generators are callables with the following signature:
32- *
33- * <code>
34- * function (
35- * Throwable $e,
36- * ServerRequestInterface $request,
37- * ResponseInterface $response
38- * ) : ResponseInterface
39- * </code>
40- *
41- * These are provided the error, and the request responsible; the response
42- * provided is the response prototype provided to the ErrorHandler instance
43- * itself, and can be used as the basis for returning an error response.
44- *
45- * An error response generator must be provided as a constructor argument;
46- * if not provided, an instance of Laminas\Stratigility\Middleware\ErrorResponseGenerator
47- * will be used.
48- *
49- * Listeners use the following signature:
50- *
51- * <code>
52- * function (
53- * Throwable $e,
54- * ServerRequestInterface $request,
55- * ResponseInterface $response
56- * ) : void
57- * </code>
58- *
59- * Listeners are given the error, the request responsible, and the generated
60- * error response, and can then react to them. They are best suited for
61- * logging and monitoring purposes.
62- *
63- * Listeners are attached using the attachListener() method, and triggered
64- * in the order attached.
65- */
6620class ErrorHandler implements MiddlewareInterface, ErrorHandlerInterface
6721{
6822 /** @var callable[] */
@@ -87,19 +41,6 @@ public function __construct(callable $responseFactory, ?callable $responseGenera
8741 $ this ->responseGenerator = $ responseGenerator ?: new ErrorResponseGenerator ();
8842 }
8943
90- /**
91- * Attach an error listener.
92- *
93- * Each listener receives the following three arguments:
94- *
95- * - Throwable $error
96- * - ServerRequestInterface $request
97- * - ResponseInterface $response
98- *
99- * These instances are all immutable, and the return values of
100- * listeners are ignored; use listeners for reporting purposes
101- * only.
102- */
10344 public function attachListener (callable $ listener ): void
10445 {
10546 if (in_array ($ listener , $ this ->listeners , true )) {
@@ -109,19 +50,6 @@ public function attachListener(callable $listener): void
10950 $ this ->listeners [] = $ listener ;
11051 }
11152
112- /**
113- * Middleware to handle errors and exceptions in layers it wraps.
114- *
115- * Adds an error handler that will convert PHP errors to ErrorException
116- * instances.
117- *
118- * Internally, wraps the call to $next() in a try/catch block, catching
119- * all PHP Throwables.
120- *
121- * When an exception is caught, an appropriate error response is created
122- * and returned instead; otherwise, the response returned by $next is
123- * used.
124- */
12553 public function process (ServerRequestInterface $ request , RequestHandlerInterface $ handler ): ResponseInterface
12654 {
12755 set_error_handler ($ this ->createErrorHandler ());
0 commit comments