CachingRequestHandlerDecorator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chinstrap\Core\Kernel;
6
7
use Laminas\Diactoros\StreamFactory;
8
use Psr\Cache\CacheItemPoolInterface;
9
use Psr\Http\Message\ResponseInterface;
10
use Psr\Http\Message\ServerRequestInterface;
11
use Psr\Http\Server\RequestHandlerInterface;
12
use PublishingKit\HttpProxy\Client;
13
use PublishingKit\HttpProxy\Proxy;
14
15
final class CachingRequestHandlerDecorator implements RequestHandlerInterface
16
{
17
    private RequestHandlerInterface $handler;
18
19
    private CacheItemPoolInterface $cache;
20
21
    public function __construct(RequestHandlerInterface $handler, CacheItemPoolInterface $cache)
22
    {
23
        $this->handler = $handler;
24
        $this->cache = $cache;
25
    }
26
27
    /**
28
     * {@inheritDoc}
29
     */
30
    public function handle(ServerRequestInterface $request): ResponseInterface
31
    {
32
        $client = new Client(function (ServerRequestInterface $request): ResponseInterface {
33
            return $this->handler->handle($request);
34
        });
35
        $proxy = new Proxy($client, $this->cache, new StreamFactory());
36
        return $proxy->handle($request);
37
    }
38
}
39