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

DB manager now doesn't depend on DB storage driver

This commit is contained in:
Samuel Štancl 2019-09-30 18:41:51 +02:00
parent c965ca5c93
commit ae6cf5c1ab
3 changed files with 18 additions and 21 deletions

View file

@ -4,10 +4,8 @@ declare(strict_types=1);
namespace Stancl\Tenancy;
use Illuminate\Database\Connection;
use Illuminate\Database\DatabaseManager as BaseDatabaseManager;
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\DB;
use Stancl\Tenancy\Contracts\TenantDatabaseManager;
use Stancl\Tenancy\Exceptions\DatabaseManagerNotRegisteredException;
use Stancl\Tenancy\Exceptions\TenantDatabaseAlreadyExistsException;
@ -178,20 +176,4 @@ class DatabaseManager
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;
}
}

View file

@ -10,6 +10,6 @@ trait CentralConnection
{
public function getConnectionName()
{
return app(DatabaseManager::class)->getCentralConnectionName();
return app(DatabaseStorageDriver::class)->getCentralConnectionName();
}
}

View file

@ -5,8 +5,8 @@ declare(strict_types=1);
namespace Stancl\Tenancy\StorageDrivers\Database;
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\DB;
use Stancl\Tenancy\Contracts\StorageDriver;
use Stancl\Tenancy\DatabaseManager;
use Stancl\Tenancy\Exceptions\DomainsOccupiedByOtherTenantException;
use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedException;
use Stancl\Tenancy\Exceptions\TenantWithThisIdAlreadyExistsException;
@ -28,7 +28,22 @@ class DatabaseStorageDriver implements StorageDriver
public function __construct(Application $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