mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 15:34:03 +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\Facades\Route;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
use Stancl\JobPipeline\JobPipeline;
|
use Stancl\JobPipeline\JobPipeline;
|
||||||
use Stancl\Tenancy\Events\BootstrappingTenancy;
|
use Stancl\Tenancy\Listeners;
|
||||||
use Stancl\Tenancy\Events\CreatingDomain;
|
use Stancl\Tenancy\Events;
|
||||||
use Stancl\Tenancy\Events\CreatingTenant;
|
use Stancl\Tenancy\Jobs;
|
||||||
use Stancl\Tenancy\Listeners\BootstrapTenancy;
|
use Stancl\Tenancy\Middleware;
|
||||||
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;
|
|
||||||
|
|
||||||
class TenancyServiceProvider extends ServiceProvider
|
class TenancyServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
|
|
@ -49,67 +18,67 @@ class TenancyServiceProvider extends ServiceProvider
|
||||||
return [
|
return [
|
||||||
|
|
||||||
// Tenant events
|
// Tenant events
|
||||||
CreatingTenant::class => [],
|
Events\CreatingTenant::class => [],
|
||||||
TenantCreated::class => [
|
Events\TenantCreated::class => [
|
||||||
JobPipeline::make([
|
JobPipeline::make([
|
||||||
CreateDatabase::class,
|
Jobs\CreateDatabase::class,
|
||||||
MigrateDatabase::class,
|
Jobs\MigrateDatabase::class,
|
||||||
SeedDatabase::class,
|
// Jobs\SeedDatabase::class,
|
||||||
|
|
||||||
// Your own jobs to prepare the tenant.
|
// Your own jobs to prepare the tenant.
|
||||||
// Provision API keys, create S3 buckets, anything you want!
|
// Provision API keys, create S3 buckets, anything you want!
|
||||||
|
|
||||||
])->send(function (TenantCreated $event) {
|
])->send(function (Events\TenantCreated $event) {
|
||||||
return $event->tenant;
|
return $event->tenant;
|
||||||
})->shouldBeQueued(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.
|
||||||
],
|
],
|
||||||
SavingTenant::class => [],
|
Events\SavingTenant::class => [],
|
||||||
TenantSaved::class => [],
|
Events\TenantSaved::class => [],
|
||||||
UpdatingTenant::class => [],
|
Events\UpdatingTenant::class => [],
|
||||||
TenantUpdated::class => [],
|
Events\TenantUpdated::class => [],
|
||||||
DeletingTenant::class => [],
|
Events\DeletingTenant::class => [],
|
||||||
TenantDeleted::class => [
|
Events\TenantDeleted::class => [
|
||||||
JobPipeline::make([
|
JobPipeline::make([
|
||||||
DeleteDatabase::class,
|
Jobs\DeleteDatabase::class,
|
||||||
])->send(function (TenantDeleted $event) {
|
])->send(function (Events\TenantDeleted $event) {
|
||||||
return $event->tenant;
|
return $event->tenant;
|
||||||
})->shouldBeQueued(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.
|
||||||
],
|
],
|
||||||
|
|
||||||
// Domain events
|
// Domain events
|
||||||
CreatingDomain::class => [],
|
Events\CreatingDomain::class => [],
|
||||||
DomainCreated::class => [],
|
Events\DomainCreated::class => [],
|
||||||
SavingDomain::class => [],
|
Events\SavingDomain::class => [],
|
||||||
DomainSaved::class => [],
|
Events\DomainSaved::class => [],
|
||||||
UpdatingDomain::class => [],
|
Events\UpdatingDomain::class => [],
|
||||||
DomainUpdated::class => [],
|
Events\DomainUpdated::class => [],
|
||||||
DeletingDomain::class => [],
|
Events\DeletingDomain::class => [],
|
||||||
DomainDeleted::class => [],
|
Events\DomainDeleted::class => [],
|
||||||
|
|
||||||
// Database events
|
// Database events
|
||||||
// todo: let -ing events cacnel the operations
|
// todo: let -ing events cacnel the operations
|
||||||
DatabaseCreated::class => [],
|
Events\DatabaseCreated::class => [],
|
||||||
DatabaseMigrated::class => [],
|
Events\DatabaseMigrated::class => [],
|
||||||
DatabaseSeeded::class => [],
|
Events\DatabaseSeeded::class => [],
|
||||||
DatabaseRolledBack::class => [],
|
Events\DatabaseRolledBack::class => [],
|
||||||
DatabaseDeleted::class => [],
|
Events\DatabaseDeleted::class => [],
|
||||||
|
|
||||||
// Tenancy events
|
// Tenancy events
|
||||||
// todo: let -ing events cacnel the operations
|
// todo: let -ing events cacnel the operations
|
||||||
InitializingTenancy::class => [],
|
Events\InitializingTenancy::class => [],
|
||||||
TenancyInitialized::class => [
|
Events\TenancyInitialized::class => [
|
||||||
BootstrapTenancy::class,
|
Listeners\BootstrapTenancy::class,
|
||||||
],
|
],
|
||||||
|
|
||||||
EndingTenancy::class => [],
|
Events\EndingTenancy::class => [],
|
||||||
TenancyEnded::class => [
|
Events\TenancyEnded::class => [
|
||||||
RevertToCentralContext::class,
|
Listeners\RevertToCentralContext::class,
|
||||||
],
|
],
|
||||||
|
|
||||||
BootstrappingTenancy::class => [],
|
Events\BootstrappingTenancy::class => [],
|
||||||
TenancyBootstrapped::class => [],
|
Events\TenancyBootstrapped::class => [],
|
||||||
RevertingToCentralContext::class => [],
|
Events\RevertingToCentralContext::class => [],
|
||||||
RevertedToCentralContext::class => [],
|
Events\RevertedToCentralContext::class => [],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -123,7 +92,7 @@ class TenancyServiceProvider extends ServiceProvider
|
||||||
$this->bootEvents();
|
$this->bootEvents();
|
||||||
$this->mapRoutes();
|
$this->mapRoutes();
|
||||||
|
|
||||||
//
|
$this->makeTenancyMiddlewareHighestPriority();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function bootEvents()
|
protected function bootEvents()
|
||||||
|
|
@ -146,4 +115,19 @@ class TenancyServiceProvider extends ServiceProvider
|
||||||
->group(base_path('routes/tenant.php'));
|
->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