Files
DesignPatternsPHP/Behavioral/ChainOfResponsibilities/Responsible/HttpInMemoryCacheHandler.php
2019-12-14 13:41:03 +01:00

34 lines
812 B
PHP

<?php declare(strict_types=1);
namespace DesignPatterns\Behavioral\ChainOfResponsibilities\Responsible;
use DesignPatterns\Behavioral\ChainOfResponsibilities\Handler;
use Psr\Http\Message\RequestInterface;
class HttpInMemoryCacheHandler extends Handler
{
private array $data;
public function __construct(array $data, ?Handler $successor = null)
{
parent::__construct($successor);
$this->data = $data;
}
protected function processing(RequestInterface $request): ?string
{
$key = sprintf(
'%s?%s',
$request->getUri()->getPath(),
$request->getUri()->getQuery()
);
if ($request->getMethod() == 'GET' && isset($this->data[$key])) {
return $this->data[$key];
}
return null;
}
}