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

Automatic mode

This commit is contained in:
Samuel Štancl 2020-05-10 23:47:11 +02:00
parent 2492345280
commit 73fc525126
16 changed files with 154 additions and 40 deletions

View file

@ -8,7 +8,7 @@ use Illuminate\Cache\CacheManager;
use Illuminate\Contracts\Foundation\Application;
use Stancl\Tenancy\CacheManager as TenantCacheManager;
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
use Stancl\Tenancy\Tenant;
use Stancl\Tenancy\Contracts\Tenant;
class CacheTenancyBootstrapper implements TenancyBootstrapper
{

View file

@ -7,7 +7,7 @@ namespace Stancl\Tenancy\TenancyBootstrappers;
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
use Stancl\Tenancy\DatabaseManager;
use Stancl\Tenancy\Exceptions\TenantDatabaseDoesNotExistException;
use Stancl\Tenancy\Tenant;
use Stancl\Tenancy\Contracts\TenantWithDatabase;
class DatabaseTenancyBootstrapper implements TenancyBootstrapper
{
@ -19,18 +19,18 @@ class DatabaseTenancyBootstrapper implements TenancyBootstrapper
$this->database = $database;
}
public function start(Tenant $tenant)
public function start(TenantWithDatabase $tenant)
{
$database = $tenant->database()->getName();
if (! $tenant->database()->manager()->databaseExists($database)) {
throw new TenantDatabaseDoesNotExistException($database);
}
$this->database->connect($tenant);
$this->database->connectToTenant($tenant);
}
public function end()
{
$this->database->reconnect();
$this->database->revertToCentral();
}
}

View file

@ -8,7 +8,7 @@ use Illuminate\Filesystem\FilesystemAdapter;
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\Storage;
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
use Stancl\Tenancy\Tenant;
use Stancl\Tenancy\Contracts\Tenant;
class FilesystemTenancyBootstrapper implements TenancyBootstrapper
{
@ -36,7 +36,7 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
public function start(Tenant $tenant)
{
$suffix = $this->app['config']['tenancy.filesystem.suffix_base'] . $tenant->id;
$suffix = $this->app['config']['tenancy.filesystem.suffix_base'] . $tenant->getTenantKey();
// storage_path()
if ($this->app['config']['tenancy.filesystem.suffix_storage_path'] ?? true) {

View file

@ -8,8 +8,9 @@ use Illuminate\Config\Repository;
use Illuminate\Queue\QueueManager;
use Illuminate\Support\Testing\Fakes\QueueFake;
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
use Stancl\Tenancy\Tenant;
use Stancl\Tenancy\Contracts\Tenant;
// todo rewrite this
class QueueTenancyBootstrapper implements TenancyBootstrapper
{
/** @var bool Has tenancy been started. */

View file

@ -7,7 +7,7 @@ namespace Stancl\Tenancy\TenancyBootstrappers;
use Illuminate\Contracts\Config\Repository;
use Illuminate\Support\Facades\Redis;
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
use Stancl\Tenancy\Tenant;
use Stancl\Tenancy\Contracts\Tenant;
class RedisTenancyBootstrapper implements TenancyBootstrapper
{
@ -25,7 +25,7 @@ class RedisTenancyBootstrapper implements TenancyBootstrapper
public function start(Tenant $tenant)
{
foreach ($this->prefixedConnections() as $connection) {
$prefix = $this->config['tenancy.redis.prefix_base'] . $tenant['id'];
$prefix = $this->config['tenancy.redis.prefix_base'] . $tenant->getTenantKey();
$client = Redis::connection($connection)->client();
$this->originalPrefixes[$connection] = $client->getOption($client::OPT_PREFIX);