abc5bfcccc
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
40 lines
895 B
PHP
40 lines
895 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace KTXC\Service;
|
|
|
|
use KTXC\Models\Firewall\FirewallRuleObject;
|
|
use KTXC\Stores\FirewallStore;
|
|
|
|
final class FirewallRuleCache
|
|
{
|
|
/** @var array<string, FirewallRuleObject[]> */
|
|
private array $tenantRules = [];
|
|
|
|
/** @var FirewallRuleObject[]|null */
|
|
private ?array $systemRules = null;
|
|
|
|
public function __construct(private readonly FirewallStore $store)
|
|
{
|
|
}
|
|
|
|
/** @return FirewallRuleObject[] */
|
|
public function tenant(string $tenantId): array
|
|
{
|
|
return $this->tenantRules[$tenantId] ??= $this->store->listRules($tenantId);
|
|
}
|
|
|
|
/** @return FirewallRuleObject[] */
|
|
public function system(): array
|
|
{
|
|
return $this->systemRules ??= $this->store->listSystemRules();
|
|
}
|
|
|
|
public function invalidate(): void
|
|
{
|
|
$this->tenantRules = [];
|
|
$this->systemRules = null;
|
|
}
|
|
}
|