| @@ 65-86 (lines=22) @@ | ||
| 62 | * @param RequestHandlerInterface $handler Request handler |
|
| 63 | * @return ResponseInterface |
|
| 64 | */ |
|
| 65 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface |
|
| 66 | { |
|
| 67 | try { |
|
| 68 | $response = $handler->handle($request); |
|
| 69 | return $response; |
|
| 70 | } |
|
| 71 | // Executed only in PHP 7, will not match in PHP 5.x |
|
| 72 | catch (\Throwable $e) { |
|
| 73 | $this->handleThrowable($e); |
|
| 74 | throw $e; |
|
| 75 | } |
|
| 76 | ||
| 77 | // Executed only in PHP 5.x, will not be reached in PHP 7 |
|
| 78 | catch (\Exception $e) { |
|
| 79 | $this->handleThrowable($e); |
|
| 80 | throw $e; |
|
| 81 | } |
|
| 82 | } |
|
| 83 | ||
| 84 | ||
| 85 | ||
| 86 | /** |
|
| 87 | * PSR-7 Double Pass |
|
| 88 | * |
|
| 89 | * Wrap $next callable in a try-catch block. |
|
| @@ 98-121 (lines=24) @@ | ||
| 95 | * |
|
| 96 | * @return ResponseInterface |
|
| 97 | */ |
|
| 98 | public function __invoke(RequestInterface $request, ResponseInterface $response, callable $next) |
|
| 99 | { |
|
| 100 | try { |
|
| 101 | // Try to do business as usual... |
|
| 102 | return $next($request, $response); |
|
| 103 | } |
|
| 104 | ||
| 105 | // Executed only in PHP 7, will not match in PHP 5.x |
|
| 106 | catch (\Throwable $e) { |
|
| 107 | $this->handleThrowable($e); |
|
| 108 | throw $e; |
|
| 109 | } |
|
| 110 | ||
| 111 | // Executed only in PHP 5.x, will not be reached in PHP 7 |
|
| 112 | catch (\Exception $e) { |
|
| 113 | $this->handleThrowable($e); |
|
| 114 | throw $e; |
|
| 115 | } |
|
| 116 | ||
| 117 | // Anything else NOT caught here will bubble up. |
|
| 118 | } |
|
| 119 | ||
| 120 | ||
| 121 | /** |
|
| 122 | * @param \Exception|\Throwable $e |
|
| 123 | */ |
|
| 124 | public function handleThrowable($e) |
|
| @@ 36-57 (lines=22) @@ | ||
| 33 | * @param RequestHandlerInterface $handler Request handler |
|
| 34 | * @return ResponseInterface |
|
| 35 | */ |
|
| 36 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface |
|
| 37 | { |
|
| 38 | try { |
|
| 39 | $response = $handler->handle($request); |
|
| 40 | return $response; |
|
| 41 | } |
|
| 42 | // Executed only in PHP 7, will not match in PHP 5.x |
|
| 43 | catch (\Throwable $e) { |
|
| 44 | $this->handleThrowable($e); |
|
| 45 | throw $e; |
|
| 46 | } |
|
| 47 | ||
| 48 | // Executed only in PHP 5.x, will not be reached in PHP 7 |
|
| 49 | catch (\Exception $e) { |
|
| 50 | $this->handleThrowable($e); |
|
| 51 | throw $e; |
|
| 52 | } |
|
| 53 | } |
|
| 54 | ||
| 55 | ||
| 56 | ||
| 57 | /** |
|
| 58 | * PSR-7 Double Pass |
|
| 59 | * |
|
| 60 | * @param RequestInterface $request Request instance |
|
| @@ 66-87 (lines=22) @@ | ||
| 63 | * |
|
| 64 | * @return ResponseInterface |
|
| 65 | */ |
|
| 66 | public function __invoke(RequestInterface $request, ResponseInterface $response, callable $next) |
|
| 67 | { |
|
| 68 | try { |
|
| 69 | // Try to do business as usual... |
|
| 70 | return $next($request, $response); |
|
| 71 | } |
|
| 72 | ||
| 73 | // Executed only in PHP 7, will not match in PHP 5.x |
|
| 74 | catch (\Throwable $e) { |
|
| 75 | $this->handleThrowable($e); |
|
| 76 | throw $e; |
|
| 77 | } |
|
| 78 | ||
| 79 | // Executed only in PHP 5.x, will not be reached in PHP 7 |
|
| 80 | catch (\Exception $e) { |
|
| 81 | $this->handleThrowable($e); |
|
| 82 | throw $e; |
|
| 83 | } |
|
| 84 | } |
|
| 85 | ||
| 86 | ||
| 87 | /** |
|
| 88 | * @param \Exception|\Throwable $e |
|
| 89 | */ |
|
| 90 | public function handleThrowable($e) |
|