1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 16:14:02 +00:00

Change bootstrappers namespace

This commit is contained in:
Samuel Štancl 2020-05-13 18:19:59 +02:00
parent b772590479
commit 1a8d150f2c
18 changed files with 26 additions and 26 deletions

View file

@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Bootstrappers;
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
use Stancl\Tenancy\DatabaseManager;
use Stancl\Tenancy\Exceptions\TenantDatabaseDoesNotExistException;
use Stancl\Tenancy\Contracts\TenantWithDatabase;
use Stancl\Tenancy\Contracts\Tenant;
class DatabaseTenancyBootstrapper implements TenancyBootstrapper
{
/** @var DatabaseManager */
protected $database;
public function __construct(DatabaseManager $database)
{
$this->database = $database;
}
public function bootstrap(Tenant $tenant)
{
/** @var TenantWithDatabase $tenant */
$database = $tenant->database()->getName();
if (! $tenant->database()->manager()->databaseExists($database)) {
throw new TenantDatabaseDoesNotExistException($database);
}
$this->database->connectToTenant($tenant);
}
public function revert()
{
$this->database->reconnectToCentral();
}
}