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

Change default tenant model, write more tests, cleanup

This commit is contained in:
Samuel Štancl 2020-05-13 06:23:41 +02:00
parent c32f229dd5
commit de53b81c0e
33 changed files with 210 additions and 90 deletions

View file

@ -2,11 +2,12 @@
namespace App\Providers;
use Stancl\Tenancy\Contracts\Tenant;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;
use Stancl\Tenancy\Contracts\UniqueIdentifierGenerator;
use Stancl\Tenancy\Listeners\JobPipeline;
use Stancl\Tenancy\Listeners\BootstrapTenancy;
use Stancl\Tenancy\Listeners\RevertToCentralContext;
use Stancl\Tenancy\Events\DatabaseCreated;
use Stancl\Tenancy\Events\DatabaseDeleted;
use Stancl\Tenancy\Events\DatabaseMigrated;
@ -20,7 +21,6 @@ use Stancl\Tenancy\Events\RevertedToCentralContext;
use Stancl\Tenancy\Events\TenancyBootstrapped;
use Stancl\Tenancy\Events\TenancyEnded;
use Stancl\Tenancy\Events\TenancyInitialized;
use Stancl\Tenancy\Listeners\JobPipeline;
use Stancl\Tenancy\Events\TenantCreated;
use Stancl\Tenancy\Events\TenantDeleted;
use Stancl\Tenancy\Events\TenantSaved;
@ -29,9 +29,6 @@ use Stancl\Tenancy\Jobs\CreateDatabase;
use Stancl\Tenancy\Jobs\DeleteDatabase;
use Stancl\Tenancy\Jobs\MigrateDatabase;
use Stancl\Tenancy\Jobs\SeedDatabase;
use Stancl\Tenancy\Listeners\BootstrapTenancy;
use Stancl\Tenancy\Listeners\RevertToCentralContext;
use Stancl\Tenancy\Tenancy;
class TenancyServiceProvider extends ServiceProvider
{
@ -49,7 +46,7 @@ class TenancyServiceProvider extends ServiceProvider
])->send(function (TenantCreated $event) {
return $event->tenant;
})->queue(false), // `false` by default, but you probably want to make this `true` for production.
})->shouldBeQueued(false), // `false` by default, but you probably want to make this `true` for production.
],
TenantSaved::class => [],
TenantUpdated::class => [],
@ -58,7 +55,7 @@ class TenancyServiceProvider extends ServiceProvider
DeleteDatabase::class,
])->send(function (TenantDeleted $event) {
return $event->tenant;
})->queue(false), // `false` by default, but you probably want to make this `true` for production.
})->shouldBeQueued(false), // `false` by default, but you probably want to make this `true` for production.
],
DomainCreated::class => [],
@ -87,30 +84,7 @@ class TenancyServiceProvider extends ServiceProvider
public function register()
{
// Make sure Tenancy is stateful.
$this->app->singleton(Tenancy::class);
// Make sure features are bootstrapped as soon as Tenancy is instantiated.
$this->app->extend(Tenancy::class, function (Tenancy $tenancy) {
foreach ($this->app['config']['tenancy.features'] as $feature) {
$this->app[$feature]->bootstrap($tenancy);
}
return $tenancy;
});
// Make it possible to inject the current tenant by typehinting the Tenant contract.
$this->app->bind(Tenant::class, function ($app) {
return $app[Tenancy::class]->tenant;
});
// Make sure bootstrappers are stateful (singletons).
foreach ($this->app['config']['tenancy.bootstrappers'] as $bootstrapper) {
$this->app->singleton($bootstrapper);
}
// Bind the class in the tenancy.id_generator config to the UniqueIdentifierGenerator abstract.
$this->app->bind(UniqueIdentifierGenerator::class, $this->app['config']['tenancy.id_generator']);
//
}
public function boot()
@ -138,8 +112,7 @@ class TenancyServiceProvider extends ServiceProvider
{
$this->app->booted(function () {
if (file_exists(base_path('routes/tenant.php'))) {
Route::middleware(['web'])
->namespace($this->app['config']['tenancy.tenant_route_namespace'] ?? 'App\Http\Controllers')
Route::namespace($this->app['config']['tenancy.tenant_route_namespace'] ?? 'App\Http\Controllers')
->group(base_path('routes/tenant.php'));
}
});