1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bone\View\Middleware; |
4
|
|
|
|
5
|
|
|
use Bone\View\ViewEngineInterface; |
6
|
|
|
use Exception; |
7
|
|
|
use Laminas\Diactoros\Response\HtmlResponse; |
|
|
|
|
8
|
|
|
use Psr\Http\Message\ResponseInterface; |
9
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
10
|
|
|
use Psr\Http\Server\MiddlewareInterface; |
|
|
|
|
11
|
|
|
use Psr\Http\Server\RequestHandlerInterface; |
|
|
|
|
12
|
|
|
|
13
|
|
|
class ExceptionMiddleware extends AbstractViewMiddleware implements MiddlewareInterface |
14
|
|
|
{ |
15
|
|
|
/** @var ViewEngineInterface $viewEngine */ |
16
|
|
|
private $viewEngine; |
17
|
|
|
|
18
|
|
|
/** @var array $errorPages\ */ |
19
|
|
|
private $errorPages; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* LayoutMiddleware constructor. |
23
|
|
|
* @param ViewEngineInterface $viewEngine |
24
|
|
|
*/ |
25
|
|
|
public function __construct(ViewEngineInterface $viewEngine, array $errorPages) |
26
|
|
|
{ |
27
|
|
|
$this->viewEngine = $viewEngine; |
28
|
|
|
$this->errorPages = $errorPages; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param ServerRequestInterface $request |
33
|
|
|
* @param RequestHandlerInterface $handler |
34
|
|
|
* @return ResponseInterface |
35
|
|
|
*/ |
36
|
|
|
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
37
|
|
|
{ |
38
|
|
|
try { |
39
|
|
|
$response = $handler->handle($request); |
40
|
|
|
} catch (Exception $e) { |
41
|
|
|
$code = $e->getStatusCode(); |
|
|
|
|
42
|
|
|
$status = ($code >= 100 && $code < 600) ? $code : 500; |
43
|
|
|
$layout = array_key_exists($status, $this->errorPages) ? $this->errorPages[$status] : $this->errorPages['exception']; |
44
|
|
|
|
45
|
|
|
$body = $this->viewEngine->render($layout, [ |
46
|
|
|
'message' => $e->getMessage(), |
47
|
|
|
'code' => $status, |
48
|
|
|
'trace' => $e->getTrace(), |
49
|
|
|
]); |
50
|
|
|
|
51
|
|
|
$response = new HtmlResponse($body, $status); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return $response; |
55
|
|
|
} |
56
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths