diff --git a/assets/TenancyServiceProvider.stub.php b/assets/TenancyServiceProvider.stub.php index 981a5df7..c25ff30d 100644 --- a/assets/TenancyServiceProvider.stub.php +++ b/assets/TenancyServiceProvider.stub.php @@ -6,6 +6,9 @@ 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; @@ -13,11 +16,18 @@ 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; @@ -25,6 +35,8 @@ 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; @@ -35,6 +47,9 @@ class TenancyServiceProvider extends ServiceProvider public function events() { return [ + + // Tenant events + CreatingTenant::class => [], TenantCreated::class => [ JobPipeline::make([ CreateDatabase::class, @@ -48,8 +63,11 @@ class TenancyServiceProvider extends ServiceProvider 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 => [ JobPipeline::make([ DeleteDatabase::class, @@ -58,26 +76,39 @@ class TenancyServiceProvider extends ServiceProvider })->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 => [], - + // Database events + // todo: let -ing events cacnel the operations DatabaseCreated::class => [], DatabaseMigrated::class => [], DatabaseSeeded::class => [], DatabaseRolledBack::class => [], DatabaseDeleted::class => [], - + + // Tenancy events + // todo: let -ing events cacnel the operations + InitializingTenancy::class => [], TenancyInitialized::class => [ BootstrapTenancy::class, ], + + EndingTenancy::class => [], TenancyEnded::class => [ RevertToCentralContext::class, ], + BootstrappingTenancy::class => [], TenancyBootstrapped::class => [], + RevertingToCentralContext::class => [], RevertedToCentralContext::class => [], ]; } diff --git a/src/Database/Models/Domain.php b/src/Database/Models/Domain.php index 3b3fe3bb..ad3a2013 100644 --- a/src/Database/Models/Domain.php +++ b/src/Database/Models/Domain.php @@ -4,10 +4,7 @@ namespace Stancl\Tenancy\Database\Models; use Illuminate\Database\Eloquent\Model; use Stancl\Tenancy\Contracts\Tenant; -use Stancl\Tenancy\Events\DomainCreated; -use Stancl\Tenancy\Events\DomainDeleted; -use Stancl\Tenancy\Events\DomainSaved; -use Stancl\Tenancy\Events\DomainUpdated; +use Stancl\Tenancy\Events; use Stancl\Tenancy\Exceptions\DomainOccupiedByOtherTenantException; use Stancl\Tenancy\Contracts; use Stancl\Tenancy\Database\Concerns\CentralConnection; @@ -42,10 +39,14 @@ class Domain extends Model implements Contracts\Domain return $this->belongsTo(config('tenancy.tenant_model')); } - public $dispatchEvents = [ - 'saved' => DomainSaved::class, - 'created' => DomainCreated::class, - 'updated' => DomainUpdated::class, - 'deleted' => DomainDeleted::class, + public $dispatchesEvents = [ + 'saved' => Events\DomainSaved::class, + 'saving' => Events\SavingDomain::class, + 'created' => Events\DomainCreated::class, + 'creating' => Events\CreatingDomain::class, + 'updated' => Events\DomainUpdated::class, + 'updating' => Events\UpdatingDomain::class, + 'deleted' => Events\DomainDeleted::class, + 'deleting' => Events\DeletingDomain::class, ]; } diff --git a/src/Database/Models/Tenant.php b/src/Database/Models/Tenant.php index f4534369..5fc7fe68 100644 --- a/src/Database/Models/Tenant.php +++ b/src/Database/Models/Tenant.php @@ -83,8 +83,12 @@ class Tenant extends Model implements Contracts\Tenant public $dispatchesEvents = [ 'saved' => Events\TenantSaved::class, + 'saving' => Events\SavingTenant::class, 'created' => Events\TenantCreated::class, + 'creating' => Events\CreatingTenant::class, 'updated' => Events\TenantUpdated::class, + 'updating' => Events\UpdatingTenant::class, 'deleted' => Events\TenantDeleted::class, + 'deleting' => Events\DeletingTenant::class, ]; } diff --git a/src/Events/BootstrappingTenancy.php b/src/Events/BootstrappingTenancy.php new file mode 100644 index 00000000..e7bc98c1 --- /dev/null +++ b/src/Events/BootstrappingTenancy.php @@ -0,0 +1,7 @@ +tenancy = $tenancy; + } +} \ No newline at end of file diff --git a/src/Events/CreatingDomain.php b/src/Events/CreatingDomain.php new file mode 100644 index 00000000..cc15e660 --- /dev/null +++ b/src/Events/CreatingDomain.php @@ -0,0 +1,7 @@ +tenancy = $tenancy; - } } diff --git a/src/Events/RevertingToCentralContext.php b/src/Events/RevertingToCentralContext.php new file mode 100644 index 00000000..48ac2f5c --- /dev/null +++ b/src/Events/RevertingToCentralContext.php @@ -0,0 +1,7 @@ +tenancy = $tenancy; - } } diff --git a/src/Events/TenancyEnded.php b/src/Events/TenancyEnded.php index 8e4323b7..a5dfc25c 100644 --- a/src/Events/TenancyEnded.php +++ b/src/Events/TenancyEnded.php @@ -2,15 +2,6 @@ namespace Stancl\Tenancy\Events; -use Stancl\Tenancy\Tenancy; - -class TenancyEnded +class TenancyEnded extends Contracts\TenancyEvent { - /** @var Tenancy */ - public $tenancy; - - public function __construct(Tenancy $tenancy) - { - $this->tenancy = $tenancy; - } -} +} \ No newline at end of file diff --git a/src/Events/TenancyInitialized.php b/src/Events/TenancyInitialized.php index 904323d2..017ad7be 100644 --- a/src/Events/TenancyInitialized.php +++ b/src/Events/TenancyInitialized.php @@ -2,15 +2,6 @@ namespace Stancl\Tenancy\Events; -use Stancl\Tenancy\Tenancy; - -class TenancyInitialized +class TenancyInitialized extends Contracts\TenancyEvent { - /** @var Tenancy */ - public $tenancy; - - public function __construct(Tenancy $tenancy) - { - $this->tenancy = $tenancy; - } } diff --git a/src/Events/UpdatingDomain.php b/src/Events/UpdatingDomain.php new file mode 100644 index 00000000..fafa795e --- /dev/null +++ b/src/Events/UpdatingDomain.php @@ -0,0 +1,7 @@ +