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:
parent
b772590479
commit
1a8d150f2c
18 changed files with 26 additions and 26 deletions
39
src/Bootstrappers/DatabaseTenancyBootstrapper.php
Normal file
39
src/Bootstrappers/DatabaseTenancyBootstrapper.php
Normal 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();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue