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

Tenant contract, Tenancy bootstrappers, drop predis

This commit is contained in:
Samuel Štancl 2019-09-06 18:51:34 +02:00
parent 98cb49b1c0
commit f04ca349bd
13 changed files with 158 additions and 47 deletions

View file

@ -0,0 +1,44 @@
<?php
namespace Stancl\Tenancy\TenantDatabaseManagers;
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
class RedisTenancyBootstrapper implements TenancyBootstrapper
{
/** @var string[string] Original prefixes of connections */
protected $originalPrefixes = [];
/** @var Application */
protected $app;
public function __construct(Application $app)
{
$this->app = $app;
}
public function start()
{
foreach ($this->prefixedConnections() as $connection) {
$prefix = $this->app['config']['tenancy.redis.prefix_base'] . $this->tenant['uuid'];
$client = Redis::connection($connection)->client();
$this->originalPrefixes[$connection] = $client->getOption($client::OPT_PREFIX);
$client->setOption($client::OPT_PREFIX, $prefix);
}
}
public function end()
{
foreach ($this->prefixedConnections() as $connection) {
$client = Redis::connection($connection)->client();
$client->setOption($client::OPT_PREFIX, $this->originalPrefixes[$connection]);
}
}
protected function prefixedConnections()
{
return config('tenancy.redis.prefixed_connections');
}
}