1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-04 21:24:04 +00:00

refactor TenantDatabaseManagers

This commit is contained in:
Samuel Štancl 2022-08-27 22:29:08 +02:00
parent 824292e6df
commit d2e1ce0a1e
10 changed files with 52 additions and 126 deletions

View file

@ -0,0 +1,35 @@
<?php
namespace Stancl\Tenancy\Database\TenantDatabaseManagers;
use Illuminate\Database\Connection;
use Illuminate\Support\Facades\DB;
use Stancl\Tenancy\Database\Contracts\TenantDatabaseManager as Contract;
use Stancl\Tenancy\Database\Exceptions\NoConnectionSetException;
abstract class TenantDatabaseManager implements Contract // todo better naming?
{
/** The database connection to the server. */
protected string $connection;
protected function database(): Connection
{
if (! isset($this->connection)) {
throw new NoConnectionSetException(static::class);
}
return DB::connection($this->connection);
}
public function setConnection(string $connection): void
{
$this->connection = $connection;
}
public function makeConnectionConfig(array $baseConfig, string $databaseName): array
{
$baseConfig['database'] = $databaseName;
return $baseConfig;
}
}