1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-13 17:24:03 +00:00

Automatic mode

This commit is contained in:
Samuel Štancl 2020-05-10 23:47:11 +02:00
parent 2492345280
commit 73fc525126
16 changed files with 154 additions and 40 deletions

View file

@ -7,7 +7,7 @@ namespace Stancl\Tenancy\TenancyBootstrappers;
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
use Stancl\Tenancy\DatabaseManager;
use Stancl\Tenancy\Exceptions\TenantDatabaseDoesNotExistException;
use Stancl\Tenancy\Tenant;
use Stancl\Tenancy\Contracts\TenantWithDatabase;
class DatabaseTenancyBootstrapper implements TenancyBootstrapper
{
@ -19,18 +19,18 @@ class DatabaseTenancyBootstrapper implements TenancyBootstrapper
$this->database = $database;
}
public function start(Tenant $tenant)
public function start(TenantWithDatabase $tenant)
{
$database = $tenant->database()->getName();
if (! $tenant->database()->manager()->databaseExists($database)) {
throw new TenantDatabaseDoesNotExistException($database);
}
$this->database->connect($tenant);
$this->database->connectToTenant($tenant);
}
public function end()
{
$this->database->reconnect();
$this->database->revertToCentral();
}
}