Completed
Pull Request — 1.2 (#12)
by David
01:10
created

InitRendererFacadeMiddleware   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 22
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A process() 0 5 1
1
<?php
2
3
4
namespace Mouf\Html\Renderer;
5
6
use Psr\Http\Message\ResponseInterface;
7
use Psr\Http\Message\ServerRequestInterface;
8
use Psr\Http\Server\MiddlewareInterface;
9
use Psr\Http\Server\RequestHandlerInterface;
10
11
/**
12
 * Injects the renderer passed in parameter of the constructor into the RendererFacade, making this
13
 * renderer the default renderer of the whole application, accessible globally through the RendererFacade.
14
 * Ugly.
15
 */
16
class InitRendererFacadeMiddleware implements MiddlewareInterface
17
{
18
    /**
19
     * @var RendererInterface
20
     */
21
    private $renderer;
22
23
    public function __construct(RendererInterface $renderer)
24
    {
25
        $this->renderer = $renderer;
26
    }
27
28
    /**
29
     * Process an incoming server request and return a response, optionally delegating
30
     * response creation to a handler.
31
     */
32
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
33
    {
34
        RendererFacade::init($this->renderer);
35
        return $handler->handle($request);
36
    }
37
}
38