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

Move DatabaseManager

This commit is contained in:
Samuel Štancl 2020-05-30 15:38:29 +02:00
parent 16a598bb17
commit 579779b88b
9 changed files with 13 additions and 27 deletions

View file

@ -7,7 +7,7 @@ namespace Stancl\Tenancy\Bootstrappers;
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
use Stancl\Tenancy\Contracts\Tenant;
use Stancl\Tenancy\Contracts\TenantWithDatabase;
use Stancl\Tenancy\DatabaseManager;
use Stancl\Tenancy\Database\DatabaseManager;
use Stancl\Tenancy\Exceptions\TenantDatabaseDoesNotExistException;
class DatabaseTenancyBootstrapper implements TenancyBootstrapper

View file

@ -4,12 +4,10 @@ declare(strict_types=1);
namespace Stancl\Tenancy\Commands;
use Illuminate\Console\Command;
use Illuminate\Database\Console\Migrations\MigrateCommand;
use Illuminate\Database\Migrations\Migrator;
use Stancl\Tenancy\Concerns\DealsWithMigrations;
use Stancl\Tenancy\Concerns\HasATenantsOption;
use Stancl\Tenancy\DatabaseManager;
use Stancl\Tenancy\Events\DatabaseMigrated;
use Stancl\Tenancy\Events\MigratingDatabase;
@ -17,8 +15,6 @@ class Migrate extends MigrateCommand
{
use HasATenantsOption, DealsWithMigrations;
protected $database;
/**
* The console command description.
*
@ -31,10 +27,9 @@ class Migrate extends MigrateCommand
*
* @return void
*/
public function __construct(Migrator $migrator, DatabaseManager $database)
public function __construct(Migrator $migrator)
{
parent::__construct($migrator);
$this->database = $database;
$this->setName('tenants:migrate');
$this->specifyParameters();

View file

@ -4,12 +4,10 @@ declare(strict_types=1);
namespace Stancl\Tenancy\Commands;
use Illuminate\Console\Command;
use Illuminate\Database\Console\Migrations\RollbackCommand;
use Illuminate\Database\Migrations\Migrator;
use Stancl\Tenancy\Concerns\DealsWithMigrations;
use Stancl\Tenancy\Concerns\HasATenantsOption;
use Stancl\Tenancy\DatabaseManager;
use Stancl\Tenancy\Events\DatabaseRolledBack;
use Stancl\Tenancy\Events\RollingBackDatabase;
@ -17,8 +15,6 @@ class Rollback extends RollbackCommand
{
use HasATenantsOption, DealsWithMigrations;
protected $database;
/**
* The console command description.
*
@ -31,10 +27,9 @@ class Rollback extends RollbackCommand
*
* @return void
*/
public function __construct(Migrator $migrator, DatabaseManager $database)
public function __construct(Migrator $migrator)
{
parent::__construct($migrator);
$this->database = $database;
$this->setName('tenants:rollback');
$this->specifyParameters();

View file

@ -7,7 +7,6 @@ namespace Stancl\Tenancy\Commands;
use Illuminate\Database\ConnectionResolverInterface;
use Illuminate\Database\Console\Seeds\SeedCommand;
use Stancl\Tenancy\Concerns\HasATenantsOption;
use Stancl\Tenancy\DatabaseManager;
use Stancl\Tenancy\Events\DatabaseSeeded;
use Stancl\Tenancy\Events\SeedingDatabase;
@ -15,8 +14,6 @@ class Seed extends SeedCommand
{
use HasATenantsOption;
protected $database;
/**
* The console command description.
*
@ -29,10 +26,9 @@ class Seed extends SeedCommand
*
* @return void
*/
public function __construct(ConnectionResolverInterface $resolver, DatabaseManager $database)
public function __construct(ConnectionResolverInterface $resolver)
{
parent::__construct($resolver);
$this->database = $database;
$this->setName('tenants:seed');
$this->specifyParameters();

View file

@ -19,11 +19,11 @@ trait GeneratesIds
public function getIncrementing()
{
return ! $this->shouldGenerateId();
return ! app()->bound(UniqueIdentifierGenerator::class);
}
public function shouldGenerateId(): bool
{
return app()->bound(UniqueIdentifierGenerator::class);
return ! $this->getIncrementing();
}
}

View file

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Stancl\Tenancy;
namespace Stancl\Tenancy\Database;
use Illuminate\Config\Repository;
use Illuminate\Database\DatabaseManager as BaseDatabaseManager;

View file

@ -12,7 +12,7 @@ use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Stancl\Tenancy\Contracts\Tenant;
use Stancl\Tenancy\Contracts\TenantWithDatabase;
use Stancl\Tenancy\DatabaseManager;
use Stancl\Tenancy\Database\DatabaseManager;
use Stancl\Tenancy\Events\CreatingDatabase;
use Stancl\Tenancy\Events\DatabaseCreated;

View file

@ -20,7 +20,7 @@ class TenancyServiceProvider extends ServiceProvider
{
$this->mergeConfigFrom(__DIR__ . '/../assets/config.php', 'tenancy');
$this->app->singleton(DatabaseManager::class);
$this->app->singleton(Database\DatabaseManager::class);
// Make sure Tenancy is stateful.
$this->app->singleton(Tenancy::class);
@ -48,13 +48,13 @@ class TenancyServiceProvider extends ServiceProvider
$this->app->bind(Contracts\UniqueIdentifierGenerator::class, $this->app['config']['tenancy.id_generator']);
$this->app->singleton(Commands\Migrate::class, function ($app) {
return new Commands\Migrate($app['migrator'], $app[DatabaseManager::class]);
return new Commands\Migrate($app['migrator']);
});
$this->app->singleton(Commands\Rollback::class, function ($app) {
return new Commands\Rollback($app['migrator'], $app[DatabaseManager::class]);
return new Commands\Rollback($app['migrator']);
});
$this->app->singleton(Commands\Seed::class, function ($app) {
return new Commands\Seed($app['db'], $app[DatabaseManager::class]);
return new Commands\Seed($app['db']);
});
$this->app->bind('globalCache', function ($app) {

View file

@ -9,7 +9,7 @@ use Illuminate\Support\Str;
use PDO;
use Stancl\JobPipeline\JobPipeline;
use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper;
use Stancl\Tenancy\DatabaseManager;
use Stancl\Tenancy\Database\DatabaseManager;
use Stancl\Tenancy\Events\TenancyInitialized;
use Stancl\Tenancy\Events\TenantCreated;
use Stancl\Tenancy\Exceptions\TenantDatabaseAlreadyExistsException;