feat(core): add tenant system store contracts and configuration
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -12,12 +12,14 @@ class TenantConfiguration extends JsonSerializableObject
|
||||
protected TenantAuthentication $authentication;
|
||||
protected TenantSecurity $security;
|
||||
protected TenantFirewall $firewall;
|
||||
protected TenantStores $stores;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->authentication = new TenantAuthentication();
|
||||
$this->security = new TenantSecurity();
|
||||
$this->firewall = new TenantFirewall();
|
||||
$this->stores = new TenantStores();
|
||||
}
|
||||
|
||||
public function authentication(): TenantAuthentication {
|
||||
@@ -32,4 +34,8 @@ class TenantConfiguration extends JsonSerializableObject
|
||||
return $this->firewall;
|
||||
}
|
||||
|
||||
public function stores(): TenantStores {
|
||||
return $this->stores;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace KTXC\Models\Tenant;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use KTXF\Json\JsonSerializableObject;
|
||||
use KTXF\SystemStore\StoreReference;
|
||||
|
||||
/**
|
||||
* Logical system stores configured for a tenant.
|
||||
*/
|
||||
final class TenantStores extends JsonSerializableObject
|
||||
{
|
||||
/** @var array<string, StoreReference> */
|
||||
private array $entries = [];
|
||||
|
||||
public function jsonDeserialize(array|string $data): static
|
||||
{
|
||||
if (is_string($data)) {
|
||||
$data = json_decode($data, true);
|
||||
}
|
||||
|
||||
$this->entries = [];
|
||||
foreach ($data as $name => $store) {
|
||||
if (!is_string($name) || preg_match('/^[a-z][a-z0-9-]*$/', $name) !== 1) {
|
||||
throw new InvalidArgumentException('Invalid logical system-store name');
|
||||
}
|
||||
if (!is_array($store)) {
|
||||
throw new InvalidArgumentException('Invalid tenant store configuration entry');
|
||||
}
|
||||
$this->entries[$name] = StoreReference::fromArray($store);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
return array_map(
|
||||
static fn(StoreReference $store): array => $store->toArray(),
|
||||
$this->entries,
|
||||
);
|
||||
}
|
||||
|
||||
public function store(string $name): ?StoreReference
|
||||
{
|
||||
return $this->entries[$name] ?? null;
|
||||
}
|
||||
|
||||
/** @return array<string, StoreReference> */
|
||||
public function all(): array
|
||||
{
|
||||
return $this->entries;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user