mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 20:34:03 +00:00
Custom exceptions, fix #91
This commit is contained in:
parent
a8936a4c73
commit
4c676b41e9
6 changed files with 32 additions and 6 deletions
|
|
@ -5,6 +5,7 @@ namespace Stancl\Tenancy;
|
|||
use Stancl\Tenancy\Jobs\QueuedTenantDatabaseCreator;
|
||||
use Stancl\Tenancy\Jobs\QueuedTenantDatabaseDeleter;
|
||||
use Illuminate\Database\DatabaseManager as BaseDatabaseManager;
|
||||
use Stancl\Tenancy\Exceptions\DatabaseManagerNotRegisteredException;
|
||||
|
||||
final class DatabaseManager
|
||||
{
|
||||
|
|
@ -53,7 +54,7 @@ final class DatabaseManager
|
|||
$databaseManagers = config('tenancy.database_managers');
|
||||
|
||||
if (! \array_key_exists($driver, $databaseManagers)) {
|
||||
throw new \Exception("Database could not be created: no database manager for driver $driver is registered.");
|
||||
throw new DatabaseManagerNotRegisteredException("Database could not be created", $driver);
|
||||
}
|
||||
|
||||
if (config('tenancy.queue_database_creation', false)) {
|
||||
|
|
@ -79,7 +80,7 @@ final class DatabaseManager
|
|||
$databaseManagers = config('tenancy.database_managers');
|
||||
|
||||
if (! \array_key_exists($driver, $databaseManagers)) {
|
||||
throw new \Exception("Database could not be deleted: no database manager for driver $driver is registered.");
|
||||
throw new DatabaseManagerNotRegisteredException("Database could not be deleted", $driver);
|
||||
}
|
||||
|
||||
if (config('tenancy.queue_database_deletion', false)) {
|
||||
|
|
|
|||
11
src/Exceptions/DatabaseManagerNotRegisteredException.php
Normal file
11
src/Exceptions/DatabaseManagerNotRegisteredException.php
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Exceptions;
|
||||
|
||||
class DatabaseManagerNotRegisteredException extends \Exception
|
||||
{
|
||||
public function __construct($error, $driver)
|
||||
{
|
||||
$this->message = "$error: no database manager for driver $driver is registered.";
|
||||
}
|
||||
}
|
||||
11
src/Exceptions/TenantCouldNotBeIdentifiedException.php
Normal file
11
src/Exceptions/TenantCouldNotBeIdentifiedException.php
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Exceptions;
|
||||
|
||||
class TenantCouldNotBeIdentifiedException extends \Exception
|
||||
{
|
||||
public function __construct($domain)
|
||||
{
|
||||
$this->message = "Tenant could not be identified on domain $domain";
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Stancl\Tenancy\StorageDrivers;
|
||||
|
||||
use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedException;
|
||||
use Stancl\Tenancy\Tenant;
|
||||
use Stancl\Tenancy\Interfaces\StorageDriver;
|
||||
|
||||
|
|
@ -16,7 +17,7 @@ class DatabaseStorageDriver implements StorageDriver
|
|||
{
|
||||
$id = $this->getTenantIdByDomain($domain);
|
||||
if (! $id) {
|
||||
throw new \Exception("Tenant could not be identified on domain {$domain}");
|
||||
throw new TenantCouldNotBeIdentifiedException($domain);
|
||||
}
|
||||
|
||||
return $this->getTenantById($id);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace Stancl\Tenancy\StorageDrivers;
|
||||
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedException;
|
||||
use Stancl\Tenancy\Interfaces\StorageDriver;
|
||||
|
||||
class RedisStorageDriver implements StorageDriver
|
||||
|
|
@ -18,7 +19,7 @@ class RedisStorageDriver implements StorageDriver
|
|||
{
|
||||
$id = $this->getTenantIdByDomain($domain);
|
||||
if (! $id) {
|
||||
throw new \Exception("Tenant could not be identified on domain {$domain}");
|
||||
throw new TenantCouldNotBeIdentifiedException($domain);
|
||||
}
|
||||
|
||||
return $this->getTenantById($id);
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use Stancl\Tenancy\Interfaces\StorageDriver;
|
|||
use Stancl\Tenancy\Traits\BootstrapsTenancy;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Stancl\Tenancy\Exceptions\CannotChangeUuidOrDomainException;
|
||||
use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedException;
|
||||
|
||||
final class TenantManager
|
||||
{
|
||||
|
|
@ -65,7 +66,7 @@ final class TenantManager
|
|||
$tenant = $this->storage->identifyTenant($domain);
|
||||
|
||||
if (! $tenant || ! \array_key_exists('uuid', $tenant) || ! $tenant['uuid']) {
|
||||
throw new \Exception("Tenant could not be identified on domain {$domain}.");
|
||||
throw new TenantCouldNotBeIdentifiedException($domain);
|
||||
}
|
||||
|
||||
return $tenant;
|
||||
|
|
@ -176,7 +177,7 @@ final class TenantManager
|
|||
$uuid = $this->getIdByDomain($domain);
|
||||
|
||||
if (\is_null($uuid)) {
|
||||
throw new \Exception("Tenant with domain $domain could not be identified.");
|
||||
throw new TenantCouldNotBeIdentifiedException($domain);
|
||||
}
|
||||
|
||||
return $this->find($uuid, $fields);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue