1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 09:54:05 +00:00

TenantDatabaseDoesNotExistException

This commit is contained in:
Samuel Štancl 2019-10-21 20:32:58 +02:00
parent d899dcfcce
commit d4d6c747d2
3 changed files with 20 additions and 1 deletions

View file

@ -182,7 +182,7 @@ class DatabaseManager
* @param Tenant $tenant * @param Tenant $tenant
* @return TenantDatabaseManager * @return TenantDatabaseManager
*/ */
protected function getTenantDatabaseManager(Tenant $tenant): TenantDatabaseManager public function getTenantDatabaseManager(Tenant $tenant): TenantDatabaseManager
{ {
$driver = $this->getDriver($this->getBaseConnection($tenant->getConnectionName())); $driver = $this->getDriver($this->getBaseConnection($tenant->getConnectionName()));

View file

@ -0,0 +1,13 @@
<?php
namespace Stancl\Tenancy\Exceptions;
use Exception;
class TenantDatabaseDoesNotExistException extends Exception
{
public function __construct($database)
{
parent::__construct("Database $database does not exist.");
}
}

View file

@ -6,6 +6,7 @@ namespace Stancl\Tenancy\TenancyBootstrappers;
use Stancl\Tenancy\Contracts\TenancyBootstrapper; use Stancl\Tenancy\Contracts\TenancyBootstrapper;
use Stancl\Tenancy\DatabaseManager; use Stancl\Tenancy\DatabaseManager;
use Stancl\Tenancy\Exceptions\TenantDatabaseDoesNotExistException;
use Stancl\Tenancy\Tenant; use Stancl\Tenancy\Tenant;
class DatabaseTenancyBootstrapper implements TenancyBootstrapper class DatabaseTenancyBootstrapper implements TenancyBootstrapper
@ -20,6 +21,11 @@ class DatabaseTenancyBootstrapper implements TenancyBootstrapper
public function start(Tenant $tenant) public function start(Tenant $tenant)
{ {
$database = $tenant->getDatabaseName();
if (! $this->database->getTenantDatabaseManager($tenant)->databaseExists($database)) {
throw new TenantDatabaseDoesNotExistException($database);
}
$this->database->connect($tenant); $this->database->connect($tenant);
} }