mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 11:14:04 +00:00
Refactor stub provider, add middleware priority logic
This commit is contained in:
parent
3e337e1ae0
commit
1329356b4b
1 changed files with 59 additions and 75 deletions
|
|
@ -6,41 +6,10 @@ use Illuminate\Support\Facades\Event;
|
|||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Stancl\JobPipeline\JobPipeline;
|
||||
use Stancl\Tenancy\Events\BootstrappingTenancy;
|
||||
use Stancl\Tenancy\Events\CreatingDomain;
|
||||
use Stancl\Tenancy\Events\CreatingTenant;
|
||||
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;
|
||||
use Stancl\Tenancy\Events\DatabaseRolledBack;
|
||||
use Stancl\Tenancy\Events\DatabaseSeeded;
|
||||
use Stancl\Tenancy\Events\DeletingDomain;
|
||||
use Stancl\Tenancy\Events\DeletingTenant;
|
||||
use Stancl\Tenancy\Events\DomainCreated;
|
||||
use Stancl\Tenancy\Events\DomainDeleted;
|
||||
use Stancl\Tenancy\Events\DomainSaved;
|
||||
use Stancl\Tenancy\Events\DomainUpdated;
|
||||
use Stancl\Tenancy\Events\EndingTenancy;
|
||||
use Stancl\Tenancy\Events\InitializingTenancy;
|
||||
use Stancl\Tenancy\Events\RevertedToCentralContext;
|
||||
use Stancl\Tenancy\Events\RevertingToCentralContext;
|
||||
use Stancl\Tenancy\Events\SavingDomain;
|
||||
use Stancl\Tenancy\Events\SavingTenant;
|
||||
use Stancl\Tenancy\Events\TenancyBootstrapped;
|
||||
use Stancl\Tenancy\Events\TenancyEnded;
|
||||
use Stancl\Tenancy\Events\TenancyInitialized;
|
||||
use Stancl\Tenancy\Events\TenantCreated;
|
||||
use Stancl\Tenancy\Events\TenantDeleted;
|
||||
use Stancl\Tenancy\Events\TenantSaved;
|
||||
use Stancl\Tenancy\Events\TenantUpdated;
|
||||
use Stancl\Tenancy\Events\UpdatingDomain;
|
||||
use Stancl\Tenancy\Events\UpdatingTenant;
|
||||
use Stancl\Tenancy\Jobs\CreateDatabase;
|
||||
use Stancl\Tenancy\Jobs\DeleteDatabase;
|
||||
use Stancl\Tenancy\Jobs\MigrateDatabase;
|
||||
use Stancl\Tenancy\Jobs\SeedDatabase;
|
||||
use Stancl\Tenancy\Listeners;
|
||||
use Stancl\Tenancy\Events;
|
||||
use Stancl\Tenancy\Jobs;
|
||||
use Stancl\Tenancy\Middleware;
|
||||
|
||||
class TenancyServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
|
@ -49,67 +18,67 @@ class TenancyServiceProvider extends ServiceProvider
|
|||
return [
|
||||
|
||||
// Tenant events
|
||||
CreatingTenant::class => [],
|
||||
TenantCreated::class => [
|
||||
Events\CreatingTenant::class => [],
|
||||
Events\TenantCreated::class => [
|
||||
JobPipeline::make([
|
||||
CreateDatabase::class,
|
||||
MigrateDatabase::class,
|
||||
SeedDatabase::class,
|
||||
Jobs\CreateDatabase::class,
|
||||
Jobs\MigrateDatabase::class,
|
||||
// Jobs\SeedDatabase::class,
|
||||
|
||||
// Your own jobs to prepare the tenant.
|
||||
// Provision API keys, create S3 buckets, anything you want!
|
||||
|
||||
])->send(function (TenantCreated $event) {
|
||||
])->send(function (Events\TenantCreated $event) {
|
||||
return $event->tenant;
|
||||
})->shouldBeQueued(false), // `false` by default, but you probably want to make this `true` for production.
|
||||
],
|
||||
SavingTenant::class => [],
|
||||
TenantSaved::class => [],
|
||||
UpdatingTenant::class => [],
|
||||
TenantUpdated::class => [],
|
||||
DeletingTenant::class => [],
|
||||
TenantDeleted::class => [
|
||||
Events\SavingTenant::class => [],
|
||||
Events\TenantSaved::class => [],
|
||||
Events\UpdatingTenant::class => [],
|
||||
Events\TenantUpdated::class => [],
|
||||
Events\DeletingTenant::class => [],
|
||||
Events\TenantDeleted::class => [
|
||||
JobPipeline::make([
|
||||
DeleteDatabase::class,
|
||||
])->send(function (TenantDeleted $event) {
|
||||
Jobs\DeleteDatabase::class,
|
||||
])->send(function (Events\TenantDeleted $event) {
|
||||
return $event->tenant;
|
||||
})->shouldBeQueued(false), // `false` by default, but you probably want to make this `true` for production.
|
||||
],
|
||||
|
||||
// Domain events
|
||||
CreatingDomain::class => [],
|
||||
DomainCreated::class => [],
|
||||
SavingDomain::class => [],
|
||||
DomainSaved::class => [],
|
||||
UpdatingDomain::class => [],
|
||||
DomainUpdated::class => [],
|
||||
DeletingDomain::class => [],
|
||||
DomainDeleted::class => [],
|
||||
Events\CreatingDomain::class => [],
|
||||
Events\DomainCreated::class => [],
|
||||
Events\SavingDomain::class => [],
|
||||
Events\DomainSaved::class => [],
|
||||
Events\UpdatingDomain::class => [],
|
||||
Events\DomainUpdated::class => [],
|
||||
Events\DeletingDomain::class => [],
|
||||
Events\DomainDeleted::class => [],
|
||||
|
||||
// Database events
|
||||
// todo: let -ing events cacnel the operations
|
||||
DatabaseCreated::class => [],
|
||||
DatabaseMigrated::class => [],
|
||||
DatabaseSeeded::class => [],
|
||||
DatabaseRolledBack::class => [],
|
||||
DatabaseDeleted::class => [],
|
||||
Events\DatabaseCreated::class => [],
|
||||
Events\DatabaseMigrated::class => [],
|
||||
Events\DatabaseSeeded::class => [],
|
||||
Events\DatabaseRolledBack::class => [],
|
||||
Events\DatabaseDeleted::class => [],
|
||||
|
||||
// Tenancy events
|
||||
// todo: let -ing events cacnel the operations
|
||||
InitializingTenancy::class => [],
|
||||
TenancyInitialized::class => [
|
||||
BootstrapTenancy::class,
|
||||
Events\InitializingTenancy::class => [],
|
||||
Events\TenancyInitialized::class => [
|
||||
Listeners\BootstrapTenancy::class,
|
||||
],
|
||||
|
||||
EndingTenancy::class => [],
|
||||
TenancyEnded::class => [
|
||||
RevertToCentralContext::class,
|
||||
Events\EndingTenancy::class => [],
|
||||
Events\TenancyEnded::class => [
|
||||
Listeners\RevertToCentralContext::class,
|
||||
],
|
||||
|
||||
BootstrappingTenancy::class => [],
|
||||
TenancyBootstrapped::class => [],
|
||||
RevertingToCentralContext::class => [],
|
||||
RevertedToCentralContext::class => [],
|
||||
|
||||
Events\BootstrappingTenancy::class => [],
|
||||
Events\TenancyBootstrapped::class => [],
|
||||
Events\RevertingToCentralContext::class => [],
|
||||
Events\RevertedToCentralContext::class => [],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -117,13 +86,13 @@ class TenancyServiceProvider extends ServiceProvider
|
|||
{
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
public function boot()
|
||||
{
|
||||
$this->bootEvents();
|
||||
$this->mapRoutes();
|
||||
|
||||
//
|
||||
$this->makeTenancyMiddlewareHighestPriority();
|
||||
}
|
||||
|
||||
protected function bootEvents()
|
||||
|
|
@ -146,4 +115,19 @@ class TenancyServiceProvider extends ServiceProvider
|
|||
->group(base_path('routes/tenant.php'));
|
||||
}
|
||||
}
|
||||
|
||||
protected function makeTenancyMiddlewareHighestPriority()
|
||||
{
|
||||
$tenancyMiddleware = [
|
||||
Middleware\InitializeTenancyByDomain::class,
|
||||
Middleware\InitializeTenancyBySubdomain::class,
|
||||
Middleware\InitializeTenancyByDomainOrSubdomain::class,
|
||||
Middleware\InitializeTenancyByPath::class,
|
||||
Middleware\InitializeTenancyByRequestData::class,
|
||||
];
|
||||
|
||||
foreach ($tenancyMiddleware as $middleware) {
|
||||
$this->app[\Illuminate\Contracts\Http\Kernel::class]->prependToMiddlewarePriority($middleware);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue