mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 20:34:03 +00:00
Replace Foundation\Application dependencies with Cache\Repository wherever possible (#149)
This commit is contained in:
parent
d0b1729258
commit
eabac3d09f
5 changed files with 23 additions and 28 deletions
|
|
@ -4,25 +4,25 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Stancl\Tenancy\Features;
|
namespace Stancl\Tenancy\Features;
|
||||||
|
|
||||||
use Illuminate\Foundation\Application;
|
use Illuminate\Config\Repository;
|
||||||
use Stancl\Tenancy\Contracts\Feature;
|
use Stancl\Tenancy\Contracts\Feature;
|
||||||
use Stancl\Tenancy\Tenant;
|
use Stancl\Tenancy\Tenant;
|
||||||
use Stancl\Tenancy\TenantManager;
|
use Stancl\Tenancy\TenantManager;
|
||||||
|
|
||||||
class TenantConfig implements Feature
|
class TenantConfig implements Feature
|
||||||
{
|
{
|
||||||
/** @var Application */
|
/** @var Repository */
|
||||||
protected $app;
|
protected $config;
|
||||||
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
public $originalConfig = [];
|
public $originalConfig = [];
|
||||||
|
|
||||||
public function __construct(Application $app)
|
public function __construct(Repository $config)
|
||||||
{
|
{
|
||||||
$this->app = $app;
|
$this->config = $config;
|
||||||
|
|
||||||
foreach ($this->getStorageToConfigMap() as $configKey) {
|
foreach ($this->getStorageToConfigMap() as $configKey) {
|
||||||
$this->originalConfig[$configKey] = $this->app['config'][$configKey];
|
$this->originalConfig[$configKey] = $this->config[$configKey];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,19 +40,19 @@ class TenantConfig implements Feature
|
||||||
public function setTenantConfig(Tenant $tenant): void
|
public function setTenantConfig(Tenant $tenant): void
|
||||||
{
|
{
|
||||||
foreach ($this->getStorageToConfigMap() as $storageKey => $configKey) {
|
foreach ($this->getStorageToConfigMap() as $storageKey => $configKey) {
|
||||||
$this->app['config'][$configKey] = $tenant->get($storageKey);
|
$this->config[$configKey] = $tenant->get($storageKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function unsetTenantConfig(): void
|
public function unsetTenantConfig(): void
|
||||||
{
|
{
|
||||||
foreach ($this->getStorageToConfigMap() as $configKey) {
|
foreach ($this->getStorageToConfigMap() as $configKey) {
|
||||||
$this->app['config'][$configKey] = $this->originalConfig[$configKey];
|
$this->config[$configKey] = $this->originalConfig[$configKey];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getStorageToConfigMap(): array
|
public function getStorageToConfigMap(): array
|
||||||
{
|
{
|
||||||
return $this->app['config']['tenancy.storage_to_config_map'] ?? [];
|
return $this->config['tenancy.storage_to_config_map'] ?? [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,22 +4,17 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Stancl\Tenancy\TenancyBootstrappers;
|
namespace Stancl\Tenancy\TenancyBootstrappers;
|
||||||
|
|
||||||
use Illuminate\Foundation\Application;
|
|
||||||
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
||||||
use Stancl\Tenancy\DatabaseManager;
|
use Stancl\Tenancy\DatabaseManager;
|
||||||
use Stancl\Tenancy\Tenant;
|
use Stancl\Tenancy\Tenant;
|
||||||
|
|
||||||
class DatabaseTenancyBootstrapper implements TenancyBootstrapper
|
class DatabaseTenancyBootstrapper implements TenancyBootstrapper
|
||||||
{
|
{
|
||||||
/** @var Application */
|
|
||||||
protected $app;
|
|
||||||
|
|
||||||
/** @var DatabaseManager */
|
/** @var DatabaseManager */
|
||||||
protected $database;
|
protected $database;
|
||||||
|
|
||||||
public function __construct(Application $app, DatabaseManager $database)
|
public function __construct(DatabaseManager $database)
|
||||||
{
|
{
|
||||||
$this->app = $app;
|
|
||||||
$this->database = $database;
|
$this->database = $database;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Stancl\Tenancy\TenancyBootstrappers;
|
namespace Stancl\Tenancy\TenancyBootstrappers;
|
||||||
|
|
||||||
use Illuminate\Contracts\Foundation\Application;
|
use Illuminate\Config\Repository;
|
||||||
use Illuminate\Support\Facades\Redis;
|
use Illuminate\Support\Facades\Redis;
|
||||||
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
||||||
use Stancl\Tenancy\Tenant;
|
use Stancl\Tenancy\Tenant;
|
||||||
|
|
@ -14,18 +14,18 @@ class RedisTenancyBootstrapper implements TenancyBootstrapper
|
||||||
/** @var array<string, string> Original prefixes of connections */
|
/** @var array<string, string> Original prefixes of connections */
|
||||||
public $originalPrefixes = [];
|
public $originalPrefixes = [];
|
||||||
|
|
||||||
/** @var Application */
|
/** @var Repository */
|
||||||
protected $app;
|
protected $config;
|
||||||
|
|
||||||
public function __construct(Application $app)
|
public function __construct(Repository $config)
|
||||||
{
|
{
|
||||||
$this->app = $app;
|
$this->config = $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function start(Tenant $tenant)
|
public function start(Tenant $tenant)
|
||||||
{
|
{
|
||||||
foreach ($this->prefixedConnections() as $connection) {
|
foreach ($this->prefixedConnections() as $connection) {
|
||||||
$prefix = $this->app['config']['tenancy.redis.prefix_base'] . $tenant['id'];
|
$prefix = $this->config['tenancy.redis.prefix_base'] . $tenant['id'];
|
||||||
$client = Redis::connection($connection)->client();
|
$client = Redis::connection($connection)->client();
|
||||||
|
|
||||||
$this->originalPrefixes[$connection] = $client->getOption($client::OPT_PREFIX);
|
$this->originalPrefixes[$connection] = $client->getOption($client::OPT_PREFIX);
|
||||||
|
|
@ -46,6 +46,6 @@ class RedisTenancyBootstrapper implements TenancyBootstrapper
|
||||||
|
|
||||||
protected function prefixedConnections()
|
protected function prefixedConnections()
|
||||||
{
|
{
|
||||||
return $this->app['config']['tenancy.redis.prefixed_connections'];
|
return $this->config['tenancy.redis.prefixed_connections'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Stancl\Tenancy\TenantDatabaseManagers;
|
namespace Stancl\Tenancy\TenantDatabaseManagers;
|
||||||
|
|
||||||
use Illuminate\Contracts\Foundation\Application;
|
use Illuminate\Config\Repository;
|
||||||
use Illuminate\Database\DatabaseManager as IlluminateDatabaseManager;
|
use Illuminate\Database\DatabaseManager as IlluminateDatabaseManager;
|
||||||
use Stancl\Tenancy\Contracts\TenantDatabaseManager;
|
use Stancl\Tenancy\Contracts\TenantDatabaseManager;
|
||||||
|
|
||||||
|
|
@ -13,9 +13,9 @@ class MySQLDatabaseManager implements TenantDatabaseManager
|
||||||
/** @var \Illuminate\Database\Connection */
|
/** @var \Illuminate\Database\Connection */
|
||||||
protected $database;
|
protected $database;
|
||||||
|
|
||||||
public function __construct(Application $app, IlluminateDatabaseManager $databaseManager)
|
public function __construct(Repository $config, IlluminateDatabaseManager $databaseManager)
|
||||||
{
|
{
|
||||||
$this->database = $databaseManager->connection($app['config']['tenancy.database_manager_connections.mysql']);
|
$this->database = $databaseManager->connection($config['tenancy.database_manager_connections.mysql']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createDatabase(string $name): bool
|
public function createDatabase(string $name): bool
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Stancl\Tenancy\TenantDatabaseManagers;
|
namespace Stancl\Tenancy\TenantDatabaseManagers;
|
||||||
|
|
||||||
use Illuminate\Contracts\Foundation\Application;
|
use Illuminate\Config\Repository;
|
||||||
use Illuminate\Database\DatabaseManager as IlluminateDatabaseManager;
|
use Illuminate\Database\DatabaseManager as IlluminateDatabaseManager;
|
||||||
use Stancl\Tenancy\Contracts\TenantDatabaseManager;
|
use Stancl\Tenancy\Contracts\TenantDatabaseManager;
|
||||||
|
|
||||||
|
|
@ -13,9 +13,9 @@ class PostgreSQLDatabaseManager implements TenantDatabaseManager
|
||||||
/** @var \Illuminate\Database\Connection */
|
/** @var \Illuminate\Database\Connection */
|
||||||
protected $database;
|
protected $database;
|
||||||
|
|
||||||
public function __construct(Application $app, IlluminateDatabaseManager $databaseManager)
|
public function __construct(Repository $config, IlluminateDatabaseManager $databaseManager)
|
||||||
{
|
{
|
||||||
$this->database = $databaseManager->connection($app['config']['tenancy.database_manager_connections.pgsql']);
|
$this->database = $databaseManager->connection($config['tenancy.database_manager_connections.pgsql']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createDatabase(string $name): bool
|
public function createDatabase(string $name): bool
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue