mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-13 00:34:03 +00:00
Clean up TenantCannotBeCreatedException
This commit is contained in:
parent
2657df5a88
commit
15a7db9e71
5 changed files with 12 additions and 18 deletions
|
|
@ -43,12 +43,13 @@ interface StorageDriver
|
||||||
public function all(array $ids = []): array;
|
public function all(array $ids = []): array;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a tenant can be created.
|
* Ensure a tenant can be created.
|
||||||
*
|
*
|
||||||
* @param Tenant $tenant
|
* @param Tenant $tenant
|
||||||
* @return true|TenantCannotBeCreatedException
|
* @return void
|
||||||
|
* @throws TenantCannotBeCreatedException
|
||||||
*/
|
*/
|
||||||
public function canCreateTenant(Tenant $tenant);
|
public function ensureTenantCanBeCreated(Tenant $tenant): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a value from storage.
|
* Get a value from storage.
|
||||||
|
|
|
||||||
|
|
@ -92,15 +92,14 @@ class DatabaseManager
|
||||||
* Check if a tenant can be created.
|
* Check if a tenant can be created.
|
||||||
*
|
*
|
||||||
* @param Tenant $tenant
|
* @param Tenant $tenant
|
||||||
* @return true|TenantCannotBeCreatedException
|
* @return void
|
||||||
|
* @throws TenantCannotBeCreatedException
|
||||||
*/
|
*/
|
||||||
public function canCreate(Tenant $tenant)
|
public function ensureTenantCanBeCreated(Tenant $tenant): void
|
||||||
{
|
{
|
||||||
if ($this->getTenantDatabaseManager($tenant)->databaseExists($database = $tenant->getDatabaseName())) {
|
if ($this->getTenantDatabaseManager($tenant)->databaseExists($database = $tenant->getDatabaseName())) {
|
||||||
return new TenantDatabaseAlreadyExistsException($database);
|
throw new TenantDatabaseAlreadyExistsException($database);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createDatabase(Tenant $tenant)
|
public function createDatabase(Tenant $tenant)
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ class DatabaseStorageDriver implements StorageDriver
|
||||||
->withDomains(Domains::where('tenant_id', $id)->all()->only('domain')->toArray());
|
->withDomains(Domains::where('tenant_id', $id)->all()->only('domain')->toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function canCreateTenant(Tenant $tenant)
|
public function ensureTEnantCanBeCreated(Tenant $tenant)
|
||||||
{
|
{
|
||||||
// todo
|
// todo
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ class RedisStorageDriver implements StorageDriver
|
||||||
return $this->app[Tenant::class];
|
return $this->app[Tenant::class];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function canCreateTenant(Tenant $tenant)
|
public function ensureTenantCanBeCreated(Tenant $tenant)
|
||||||
{
|
{
|
||||||
// todo
|
// todo
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -83,14 +83,8 @@ class TenantManager
|
||||||
*/
|
*/
|
||||||
public function ensureTenantCanBeCreated(Tenant $tenant): void
|
public function ensureTenantCanBeCreated(Tenant $tenant): void
|
||||||
{
|
{
|
||||||
// todo move the "throw" responsibility to the canCreateTenant methods?
|
$this->storage->ensureTenantCanBeCreated($tenant);
|
||||||
if (($e = $this->storage->canCreateTenant($tenant)) instanceof TenantCannotBeCreatedException) {
|
$this->database->ensureTenantCanBeCreated($tenant);
|
||||||
throw new $e;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (($e = $this->database->canCreateTenant($tenant)) instanceof TenantCannotBeCreatedException) {
|
|
||||||
throw new $e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateTenant(Tenant $tenant): self
|
public function updateTenant(Tenant $tenant): self
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue