36 lines
939 B
PHP
36 lines
939 B
PHP
|
<?php
|
||
|
|
||
|
declare(strict_types=1);
|
||
|
|
||
|
namespace DigiComp\FlowMaintenanceMode\AllowModules;
|
||
|
|
||
|
use Psr\Http\Message\ServerRequestInterface;
|
||
|
|
||
|
class ByCookieAllowModule implements AllowModuleInterface
|
||
|
{
|
||
|
protected ?string $cookieName;
|
||
|
protected ?string $cookieValue;
|
||
|
|
||
|
/**
|
||
|
* @param string|null $cookieName
|
||
|
* @param string|null $cookieValue
|
||
|
*/
|
||
|
public function __construct(?string $cookieName, ?string $cookieValue)
|
||
|
{
|
||
|
$this->cookieName = $cookieName;
|
||
|
$this->cookieValue = $cookieValue;
|
||
|
}
|
||
|
|
||
|
public function isRequestAllowed(ServerRequestInterface $request): bool
|
||
|
{
|
||
|
$cookies = $request->getCookieParams();
|
||
|
if ($this->cookieName === null || !isset($cookies[$this->cookieName])) {
|
||
|
return false;
|
||
|
}
|
||
|
if ($this->cookieValue !== null && $cookies[$this->cookieName] !== $this->cookieValue) {
|
||
|
return false;
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
}
|