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

Initial commit

This commit is contained in:
Samuel Štancl 2019-01-17 22:24:12 +01:00
commit deb3ad77f5
19 changed files with 1283 additions and 0 deletions

View file

@ -0,0 +1,46 @@
<?php
namespace Stancl\Tenancy;
trait BootstrapsTenancy
{
public function bootstrap()
{
$this->switchDatabaseConnection();
$this->setPhpRedisPrefix($this->app['config']['tenancy.redis.prefixed_connections']);
$this->tagCache();
$this->suffixFilesystemRootPaths();
}
public function switchDatabaseConnection()
{
$this->database->connect($this->getDatabaseName());
}
public function setPhpRedisPrefix($connections = ['default'])
{
return;
foreach ($connections as $connection) {
$prefix = config('tenancy.redis.prefix_base') . $this->tenant['uuid'];
$client = Redis::connection($connection)->client();
$client->setOption($client::OPT_PREFIX, $prefix);
}
}
public function tagCache()
{
$this->app->extend('cache', function () {
return new CacheManager($this->app);
});
}
public function suffixFilesystemRootPaths()
{
$suffix = $this->app['config']['tenancy.filesystem.suffix_base'] . tenant('uuid');
foreach ($this->app['config']['tenancy.filesystem.disks'] as $disk) {
\Storage::disk($disk)->getAdapter()->setPathPrefix(
$this->app['config']["filesystems.disks.{$disk}.root"] . "/{$suffix}"
);
}
}
}