mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 18:44: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;
|
||||
|
||||
use Illuminate\Foundation\Application;
|
||||
use Illuminate\Config\Repository;
|
||||
use Stancl\Tenancy\Contracts\Feature;
|
||||
use Stancl\Tenancy\Tenant;
|
||||
use Stancl\Tenancy\TenantManager;
|
||||
|
||||
class TenantConfig implements Feature
|
||||
{
|
||||
/** @var Application */
|
||||
protected $app;
|
||||
/** @var Repository */
|
||||
protected $config;
|
||||
|
||||
/** @var array */
|
||||
public $originalConfig = [];
|
||||
|
||||
public function __construct(Application $app)
|
||||
public function __construct(Repository $config)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->config = $config;
|
||||
|
||||
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
|
||||
{
|
||||
foreach ($this->getStorageToConfigMap() as $storageKey => $configKey) {
|
||||
$this->app['config'][$configKey] = $tenant->get($storageKey);
|
||||
$this->config[$configKey] = $tenant->get($storageKey);
|
||||
}
|
||||
}
|
||||
|
||||
public function unsetTenantConfig(): void
|
||||
{
|
||||
foreach ($this->getStorageToConfigMap() as $configKey) {
|
||||
$this->app['config'][$configKey] = $this->originalConfig[$configKey];
|
||||
$this->config[$configKey] = $this->originalConfig[$configKey];
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
use Illuminate\Foundation\Application;
|
||||
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
||||
use Stancl\Tenancy\DatabaseManager;
|
||||
use Stancl\Tenancy\Tenant;
|
||||
|
||||
class DatabaseTenancyBootstrapper implements TenancyBootstrapper
|
||||
{
|
||||
/** @var Application */
|
||||
protected $app;
|
||||
|
||||
/** @var DatabaseManager */
|
||||
protected $database;
|
||||
|
||||
public function __construct(Application $app, DatabaseManager $database)
|
||||
public function __construct(DatabaseManager $database)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->database = $database;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Stancl\Tenancy\TenancyBootstrappers;
|
||||
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Config\Repository;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
||||
use Stancl\Tenancy\Tenant;
|
||||
|
|
@ -14,18 +14,18 @@ class RedisTenancyBootstrapper implements TenancyBootstrapper
|
|||
/** @var array<string, string> Original prefixes of connections */
|
||||
public $originalPrefixes = [];
|
||||
|
||||
/** @var Application */
|
||||
protected $app;
|
||||
/** @var Repository */
|
||||
protected $config;
|
||||
|
||||
public function __construct(Application $app)
|
||||
public function __construct(Repository $config)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function start(Tenant $tenant)
|
||||
{
|
||||
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();
|
||||
|
||||
$this->originalPrefixes[$connection] = $client->getOption($client::OPT_PREFIX);
|
||||
|
|
@ -46,6 +46,6 @@ class RedisTenancyBootstrapper implements TenancyBootstrapper
|
|||
|
||||
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;
|
||||
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Config\Repository;
|
||||
use Illuminate\Database\DatabaseManager as IlluminateDatabaseManager;
|
||||
use Stancl\Tenancy\Contracts\TenantDatabaseManager;
|
||||
|
||||
|
|
@ -13,9 +13,9 @@ class MySQLDatabaseManager implements TenantDatabaseManager
|
|||
/** @var \Illuminate\Database\Connection */
|
||||
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
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Stancl\Tenancy\TenantDatabaseManagers;
|
||||
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Config\Repository;
|
||||
use Illuminate\Database\DatabaseManager as IlluminateDatabaseManager;
|
||||
use Stancl\Tenancy\Contracts\TenantDatabaseManager;
|
||||
|
||||
|
|
@ -13,9 +13,9 @@ class PostgreSQLDatabaseManager implements TenantDatabaseManager
|
|||
/** @var \Illuminate\Database\Connection */
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue