mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 23:14:03 +00:00
DB manager now doesn't depend on DB storage driver
This commit is contained in:
parent
c965ca5c93
commit
ae6cf5c1ab
3 changed files with 18 additions and 21 deletions
|
|
@ -4,10 +4,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Stancl\Tenancy;
|
namespace Stancl\Tenancy;
|
||||||
|
|
||||||
use Illuminate\Database\Connection;
|
|
||||||
use Illuminate\Database\DatabaseManager as BaseDatabaseManager;
|
use Illuminate\Database\DatabaseManager as BaseDatabaseManager;
|
||||||
use Illuminate\Foundation\Application;
|
use Illuminate\Foundation\Application;
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use Stancl\Tenancy\Contracts\TenantDatabaseManager;
|
use Stancl\Tenancy\Contracts\TenantDatabaseManager;
|
||||||
use Stancl\Tenancy\Exceptions\DatabaseManagerNotRegisteredException;
|
use Stancl\Tenancy\Exceptions\DatabaseManagerNotRegisteredException;
|
||||||
use Stancl\Tenancy\Exceptions\TenantDatabaseAlreadyExistsException;
|
use Stancl\Tenancy\Exceptions\TenantDatabaseAlreadyExistsException;
|
||||||
|
|
@ -178,20 +176,4 @@ class DatabaseManager
|
||||||
|
|
||||||
return $this->app[$databaseManagers[$driver]];
|
return $this->app[$databaseManagers[$driver]];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the central database connection.
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Database\Connection
|
|
||||||
*/
|
|
||||||
public function getCentralConnection(): \Illuminate\Database\Connection
|
|
||||||
{
|
|
||||||
return DB::connection($this->getCentralConnectionName());
|
|
||||||
}
|
|
||||||
|
|
||||||
// todo this should not depend on the storage driver
|
|
||||||
public function getCentralConnectionName(): string
|
|
||||||
{
|
|
||||||
return $this->app['config']['tenancy.storage_drivers.db.connection'] ?? $this->originalDefaultConnectionName;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,6 @@ trait CentralConnection
|
||||||
{
|
{
|
||||||
public function getConnectionName()
|
public function getConnectionName()
|
||||||
{
|
{
|
||||||
return app(DatabaseManager::class)->getCentralConnectionName();
|
return app(DatabaseStorageDriver::class)->getCentralConnectionName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@ declare(strict_types=1);
|
||||||
namespace Stancl\Tenancy\StorageDrivers\Database;
|
namespace Stancl\Tenancy\StorageDrivers\Database;
|
||||||
|
|
||||||
use Illuminate\Foundation\Application;
|
use Illuminate\Foundation\Application;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
use Stancl\Tenancy\Contracts\StorageDriver;
|
use Stancl\Tenancy\Contracts\StorageDriver;
|
||||||
use Stancl\Tenancy\DatabaseManager;
|
|
||||||
use Stancl\Tenancy\Exceptions\DomainsOccupiedByOtherTenantException;
|
use Stancl\Tenancy\Exceptions\DomainsOccupiedByOtherTenantException;
|
||||||
use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedException;
|
use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedException;
|
||||||
use Stancl\Tenancy\Exceptions\TenantWithThisIdAlreadyExistsException;
|
use Stancl\Tenancy\Exceptions\TenantWithThisIdAlreadyExistsException;
|
||||||
|
|
@ -28,7 +28,22 @@ class DatabaseStorageDriver implements StorageDriver
|
||||||
public function __construct(Application $app)
|
public function __construct(Application $app)
|
||||||
{
|
{
|
||||||
$this->app = $app;
|
$this->app = $app;
|
||||||
$this->centralDatabase = $app->make(DatabaseManager::class)->getCentralConnection();
|
$this->centralDatabase = $this->getCentralConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the central database connection.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Database\Connection
|
||||||
|
*/
|
||||||
|
public function getCentralConnection(): \Illuminate\Database\Connection
|
||||||
|
{
|
||||||
|
return DB::connection($this->getCentralConnectionName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCentralConnectionName(): string
|
||||||
|
{
|
||||||
|
return $this->app['config']['tenancy.storage_drivers.db.connection'] ?? $this->originalDefaultConnectionName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function findByDomain(string $domain): Tenant
|
public function findByDomain(string $domain): Tenant
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue