934fb24217
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
77 lines
2.0 KiB
PHP
77 lines
2.0 KiB
PHP
<?php
|
||
|
||
namespace KTXC\Service;
|
||
|
||
use KTXC\Models\Tenant\TenantObject;
|
||
use KTXC\Stores\TenantStore;
|
||
|
||
class TenantService
|
||
{
|
||
public function __construct(
|
||
protected readonly TenantStore $store,
|
||
) {}
|
||
|
||
public function fetchByDomain(string $domain): ?TenantObject
|
||
{
|
||
return $this->store->fetchByDomain($domain);
|
||
}
|
||
|
||
public function fetchById(string $identifier): ?TenantObject
|
||
{
|
||
return $this->store->fetch($identifier);
|
||
}
|
||
|
||
/**
|
||
* List all tenants keyed by id
|
||
*
|
||
* @return array<string, TenantObject>
|
||
*/
|
||
public function list(): array
|
||
{
|
||
return $this->store->list();
|
||
}
|
||
|
||
public function deposit(TenantObject $tenant): ?TenantObject
|
||
{
|
||
$domains = $tenant->getDomains();
|
||
if ($domains === null || count($domains) === 0) {
|
||
throw new \InvalidArgumentException('A tenant must have at least one domain.');
|
||
}
|
||
|
||
return $this->store->deposit($tenant);
|
||
}
|
||
|
||
public function destroy(TenantObject $tenant): void
|
||
{
|
||
$this->store->destroy($tenant);
|
||
}
|
||
|
||
// =========================================================================
|
||
// Settings
|
||
// =========================================================================
|
||
|
||
/**
|
||
* Fetch all – or a filtered subset of – a tenant's settings.
|
||
*
|
||
* @param string $identifier Tenant identifier
|
||
* @param string[] $keys Optional list of keys to return; empty = all
|
||
*
|
||
* @return array<string, mixed>
|
||
*/
|
||
public function fetchSettings(string $identifier, array $keys = []): array
|
||
{
|
||
return $this->store->fetchSettings($identifier, $keys);
|
||
}
|
||
|
||
/**
|
||
* Merge-update settings for a tenant.
|
||
*
|
||
* @param string $identifier Tenant identifier
|
||
* @param array<string, mixed> $settings Key-value pairs to persist
|
||
*/
|
||
public function storeSettings(string $identifier, array $settings): bool
|
||
{
|
||
return $this->store->storeSettings($identifier, $settings);
|
||
}
|
||
}
|