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

Add changes to PR to Laravel

This commit is contained in:
lukinovec 2022-12-16 11:12:33 +01:00
parent 7092f4c856
commit fa00fc7a28

View file

@ -4,8 +4,16 @@ declare(strict_types=1);
namespace Stancl\Tenancy; namespace Stancl\Tenancy;
use Illuminate\Cache\CacheManager as BaseCacheManager; use Illuminate\Cache\ApcStore;
use Illuminate\Cache\FileStore;
use Illuminate\Cache\NullStore;
use Illuminate\Cache\ApcWrapper;
use Illuminate\Cache\ArrayStore;
use Illuminate\Cache\RedisStore;
use Illuminate\Cache\Repository; use Illuminate\Cache\Repository;
use Illuminate\Cache\MemcachedStore;
use Illuminate\Contracts\Cache\Store;
use Illuminate\Cache\CacheManager as BaseCacheManager;
// todo move to Cache namespace? // todo move to Cache namespace?
@ -49,8 +57,54 @@ class CacheManager extends BaseCacheManager
$this->store = $store; $this->store = $store;
}); });
$newStore = $this->resolve($repository ?? $this->getDefaultDriver())->getStore(); $this->driver($repository)->setStore($this->createStore($repository ?? $this->getDefaultDriver()));
}
$this->driver($repository)->setStore($newStore); protected function createApcStore(array $config): ApcStore
{
return new ApcStore(new ApcWrapper, $this->getPrefix($config));
}
protected function createArrayStore(array $config): ArrayStore
{
return new ArrayStore($config['serialize'] ?? false);
}
protected function createFileStore(array $config): FileStore
{
return new FileStore($this->app['files'], $config['path'], $config['permission'] ?? null);
}
protected function createMemcachedStore(array $config): MemcachedStore
{
$memcached = $this->app['memcached.connector']->connect(
$config['servers'],
$config['persistent_id'] ?? null,
$config['options'] ?? [],
array_filter($config['sasl'] ?? [])
);
return new MemcachedStore($memcached, $this->getPrefix($config));
}
protected function createRedisStore(array $config): RedisStore
{
$connection = $config['connection'] ?? 'default';
$store = new RedisStore($this->app['redis'], $this->getPrefix($config), $connection);
return $store->setLockConnection($config['lock_connection'] ?? $connection);
}
protected function createNullStore(): NullStore
{
return new NullStore;
}
public function createStore(string|null $name, array|null $config = null): Store
{
$name ??= 'null';
$storeCreationMethod = 'create' . ucfirst($name) . 'Store';
return $this->{$storeCreationMethod}($config ?? $this->getConfig($name));
} }
} }