Completed
Branch master (1449f5)
by Saif Eddin
23:53 queued 08:55
created

CacheResetMiddleware::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Validus\Cache\Middleware;
6
7
use Psr\Cache\CacheItemPoolInterface;
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
use Symfony\Component\Cache\ResettableInterface;
13
14
class CacheResetMiddleware implements MiddlewareInterface
15
{
16
    /** @var CacheItemPoolInterface $itemPool */
17
    protected $itemPool;
18
19
    /**
20
     * CacheResetMiddleware constructor.
21
     *
22
     * @param CacheItemPoolInterface $itemPool
23
     */
24
    public function __construct(CacheItemPoolInterface $itemPool)
25
    {
26
        $this->itemPool = $itemPool;
27
    }
28
29
    /**
30
     * Process an incoming server request and return a response, optionally delegating
31
     * response creation to a handler.
32
     *
33
     * @param ServerRequestInterface  $request
34
     * @param RequestHandlerInterface $handler
35
     *
36
     * @return ResponseInterface
37
     */
38
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
39
    {
40
        if ($this->itemPool instanceof ResettableInterface) {
41
            $this->itemPool->reset();
42
        }
43
44
        return $handler->handle($request);
45
    }
46
}
47