DigiComp.FlowMaintenanceMode/Classes/AllowModules/ByCookieAllowModule.php

36 lines
939 B
PHP
Raw Normal View History

2024-11-28 17:05:22 +01:00
<?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;
}
}