mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-04 19:24:02 +00:00
functions to add an alias domain for a tenant
This commit is contained in:
parent
13cdc03103
commit
a7a019b148
3 changed files with 27 additions and 0 deletions
|
|
@ -9,6 +9,7 @@ interface StorageDriver
|
|||
public function getTenantById(string $uuid, array $fields = []): array;
|
||||
public function getTenantIdByDomain(string $domain): ?string;
|
||||
public function createTenant(string $domain, string $uuid): array;
|
||||
public function aliasTenant(string $aliasDomain, string $uuid): array;
|
||||
public function deleteTenant(string $uuid): bool;
|
||||
public function get(string $uuid, string $key);
|
||||
public function getMany(string $uuid, array $keys): array;
|
||||
|
|
|
|||
|
|
@ -53,6 +53,12 @@ class RedisStorageDriver implements StorageDriver
|
|||
return $this->redis->hgetall("tenants:$uuid");
|
||||
}
|
||||
|
||||
public function aliasTenant(string $aliasDomain, string $uuid): array
|
||||
{
|
||||
$this->redis->hmset("domains:$aliasDomain", 'tenant_id', $uuid);
|
||||
return $this->redis->hgetall("tenants:$uuid");
|
||||
}
|
||||
|
||||
public function deleteTenant(string $id): bool
|
||||
{
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -83,6 +83,26 @@ class TenantManager
|
|||
return $tenant;
|
||||
}
|
||||
|
||||
public function alias(string $domain, string $alias): array
|
||||
{
|
||||
$domain = $domain ?: $this->currentDomain();
|
||||
|
||||
$uuid = $this->storage->getTenantIdByDomain($domain);
|
||||
|
||||
if (!$uuid) {
|
||||
throw new \Exception("Domain $domain does not exists.");
|
||||
}
|
||||
|
||||
if ($aliasUuid = $this->storage->getTenantIdByDomain($alias)) {
|
||||
throw new \Exception("Domain Alias $domain is already occupied in use.");
|
||||
}
|
||||
|
||||
$tenant = $this->jsonDecodeArrayValues($this->storage->aliasTenant($alias, $uuid));
|
||||
|
||||
|
||||
return $tenant;
|
||||
}
|
||||
|
||||
public function delete(string $uuid): bool
|
||||
{
|
||||
return $this->storage->deleteTenant($uuid);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue