Completed
Push — master ( 753e69...36642f )
by Derek Stephen
02:06 queued 13s
created

NotFoundDecorator::setView()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Bone\Mvc\Router\Decorator;
4
5
use Bone\Mvc\View\ViewEngine;
6
use Bone\Traits\HasLayoutTrait;
7
use Psr\Http\Message\ResponseInterface;
8
use Psr\Http\Message\ServerRequestInterface;
9
use Psr\Http\Server\MiddlewareInterface;
10
use Psr\Http\Server\RequestHandlerInterface;
11
use Zend\Diactoros\Response;
12
use Zend\Diactoros\Stream;
13
14
class NotFoundDecorator extends ExceptionDecorator implements MiddlewareInterface
15
{
16
    /**
17
     * @param ServerRequestInterface $request
18
     * @param RequestHandlerInterface $handler
19
     * @return ResponseInterface
20
     */
21
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
22
    {
23
        $body = $this->viewEngine->render('error/not-found');
24
        $body = $this->viewEngine->render($this->getLayout(), [
25
            'content' => $body,
26
        ]);
27
28
        $stream = new Stream('php://memory', 'r+');
29
        $stream->write($body);
30
        $response = (new Response())->withStatus(404)->withBody($stream);
31
32
        return $response;
33
    }
34
}