mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 17:44:04 +00:00
Add more events
This commit is contained in:
parent
ed96aee669
commit
b87c0bc9d2
22 changed files with 165 additions and 52 deletions
|
|
@ -6,6 +6,9 @@ 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\Events\CreatingDomain;
|
||||||
|
use Stancl\Tenancy\Events\CreatingTenant;
|
||||||
use Stancl\Tenancy\Listeners\BootstrapTenancy;
|
use Stancl\Tenancy\Listeners\BootstrapTenancy;
|
||||||
use Stancl\Tenancy\Listeners\RevertToCentralContext;
|
use Stancl\Tenancy\Listeners\RevertToCentralContext;
|
||||||
use Stancl\Tenancy\Events\DatabaseCreated;
|
use Stancl\Tenancy\Events\DatabaseCreated;
|
||||||
|
|
@ -13,11 +16,18 @@ use Stancl\Tenancy\Events\DatabaseDeleted;
|
||||||
use Stancl\Tenancy\Events\DatabaseMigrated;
|
use Stancl\Tenancy\Events\DatabaseMigrated;
|
||||||
use Stancl\Tenancy\Events\DatabaseRolledBack;
|
use Stancl\Tenancy\Events\DatabaseRolledBack;
|
||||||
use Stancl\Tenancy\Events\DatabaseSeeded;
|
use Stancl\Tenancy\Events\DatabaseSeeded;
|
||||||
|
use Stancl\Tenancy\Events\DeletingDomain;
|
||||||
|
use Stancl\Tenancy\Events\DeletingTenant;
|
||||||
use Stancl\Tenancy\Events\DomainCreated;
|
use Stancl\Tenancy\Events\DomainCreated;
|
||||||
use Stancl\Tenancy\Events\DomainDeleted;
|
use Stancl\Tenancy\Events\DomainDeleted;
|
||||||
use Stancl\Tenancy\Events\DomainSaved;
|
use Stancl\Tenancy\Events\DomainSaved;
|
||||||
use Stancl\Tenancy\Events\DomainUpdated;
|
use Stancl\Tenancy\Events\DomainUpdated;
|
||||||
|
use Stancl\Tenancy\Events\EndingTenancy;
|
||||||
|
use Stancl\Tenancy\Events\InitializingTenancy;
|
||||||
use Stancl\Tenancy\Events\RevertedToCentralContext;
|
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\TenancyBootstrapped;
|
||||||
use Stancl\Tenancy\Events\TenancyEnded;
|
use Stancl\Tenancy\Events\TenancyEnded;
|
||||||
use Stancl\Tenancy\Events\TenancyInitialized;
|
use Stancl\Tenancy\Events\TenancyInitialized;
|
||||||
|
|
@ -25,6 +35,8 @@ use Stancl\Tenancy\Events\TenantCreated;
|
||||||
use Stancl\Tenancy\Events\TenantDeleted;
|
use Stancl\Tenancy\Events\TenantDeleted;
|
||||||
use Stancl\Tenancy\Events\TenantSaved;
|
use Stancl\Tenancy\Events\TenantSaved;
|
||||||
use Stancl\Tenancy\Events\TenantUpdated;
|
use Stancl\Tenancy\Events\TenantUpdated;
|
||||||
|
use Stancl\Tenancy\Events\UpdatingDomain;
|
||||||
|
use Stancl\Tenancy\Events\UpdatingTenant;
|
||||||
use Stancl\Tenancy\Jobs\CreateDatabase;
|
use Stancl\Tenancy\Jobs\CreateDatabase;
|
||||||
use Stancl\Tenancy\Jobs\DeleteDatabase;
|
use Stancl\Tenancy\Jobs\DeleteDatabase;
|
||||||
use Stancl\Tenancy\Jobs\MigrateDatabase;
|
use Stancl\Tenancy\Jobs\MigrateDatabase;
|
||||||
|
|
@ -35,6 +47,9 @@ class TenancyServiceProvider extends ServiceProvider
|
||||||
public function events()
|
public function events()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
|
||||||
|
// Tenant events
|
||||||
|
CreatingTenant::class => [],
|
||||||
TenantCreated::class => [
|
TenantCreated::class => [
|
||||||
JobPipeline::make([
|
JobPipeline::make([
|
||||||
CreateDatabase::class,
|
CreateDatabase::class,
|
||||||
|
|
@ -48,8 +63,11 @@ class TenancyServiceProvider extends ServiceProvider
|
||||||
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 => [],
|
||||||
TenantSaved::class => [],
|
TenantSaved::class => [],
|
||||||
|
UpdatingTenant::class => [],
|
||||||
TenantUpdated::class => [],
|
TenantUpdated::class => [],
|
||||||
|
DeletingTenant::class => [],
|
||||||
TenantDeleted::class => [
|
TenantDeleted::class => [
|
||||||
JobPipeline::make([
|
JobPipeline::make([
|
||||||
DeleteDatabase::class,
|
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.
|
})->shouldBeQueued(false), // `false` by default, but you probably want to make this `true` for production.
|
||||||
],
|
],
|
||||||
|
|
||||||
|
// Domain events
|
||||||
|
CreatingDomain::class => [],
|
||||||
DomainCreated::class => [],
|
DomainCreated::class => [],
|
||||||
|
SavingDomain::class => [],
|
||||||
DomainSaved::class => [],
|
DomainSaved::class => [],
|
||||||
|
UpdatingDomain::class => [],
|
||||||
DomainUpdated::class => [],
|
DomainUpdated::class => [],
|
||||||
|
DeletingDomain::class => [],
|
||||||
DomainDeleted::class => [],
|
DomainDeleted::class => [],
|
||||||
|
|
||||||
|
// Database events
|
||||||
|
// todo: let -ing events cacnel the operations
|
||||||
DatabaseCreated::class => [],
|
DatabaseCreated::class => [],
|
||||||
DatabaseMigrated::class => [],
|
DatabaseMigrated::class => [],
|
||||||
DatabaseSeeded::class => [],
|
DatabaseSeeded::class => [],
|
||||||
DatabaseRolledBack::class => [],
|
DatabaseRolledBack::class => [],
|
||||||
DatabaseDeleted::class => [],
|
DatabaseDeleted::class => [],
|
||||||
|
|
||||||
|
// Tenancy events
|
||||||
|
// todo: let -ing events cacnel the operations
|
||||||
|
InitializingTenancy::class => [],
|
||||||
TenancyInitialized::class => [
|
TenancyInitialized::class => [
|
||||||
BootstrapTenancy::class,
|
BootstrapTenancy::class,
|
||||||
],
|
],
|
||||||
|
|
||||||
|
EndingTenancy::class => [],
|
||||||
TenancyEnded::class => [
|
TenancyEnded::class => [
|
||||||
RevertToCentralContext::class,
|
RevertToCentralContext::class,
|
||||||
],
|
],
|
||||||
|
|
||||||
|
BootstrappingTenancy::class => [],
|
||||||
TenancyBootstrapped::class => [],
|
TenancyBootstrapped::class => [],
|
||||||
|
RevertingToCentralContext::class => [],
|
||||||
RevertedToCentralContext::class => [],
|
RevertedToCentralContext::class => [],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,7 @@ namespace Stancl\Tenancy\Database\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Stancl\Tenancy\Contracts\Tenant;
|
use Stancl\Tenancy\Contracts\Tenant;
|
||||||
use Stancl\Tenancy\Events\DomainCreated;
|
use Stancl\Tenancy\Events;
|
||||||
use Stancl\Tenancy\Events\DomainDeleted;
|
|
||||||
use Stancl\Tenancy\Events\DomainSaved;
|
|
||||||
use Stancl\Tenancy\Events\DomainUpdated;
|
|
||||||
use Stancl\Tenancy\Exceptions\DomainOccupiedByOtherTenantException;
|
use Stancl\Tenancy\Exceptions\DomainOccupiedByOtherTenantException;
|
||||||
use Stancl\Tenancy\Contracts;
|
use Stancl\Tenancy\Contracts;
|
||||||
use Stancl\Tenancy\Database\Concerns\CentralConnection;
|
use Stancl\Tenancy\Database\Concerns\CentralConnection;
|
||||||
|
|
@ -42,10 +39,14 @@ class Domain extends Model implements Contracts\Domain
|
||||||
return $this->belongsTo(config('tenancy.tenant_model'));
|
return $this->belongsTo(config('tenancy.tenant_model'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public $dispatchEvents = [
|
public $dispatchesEvents = [
|
||||||
'saved' => DomainSaved::class,
|
'saved' => Events\DomainSaved::class,
|
||||||
'created' => DomainCreated::class,
|
'saving' => Events\SavingDomain::class,
|
||||||
'updated' => DomainUpdated::class,
|
'created' => Events\DomainCreated::class,
|
||||||
'deleted' => DomainDeleted::class,
|
'creating' => Events\CreatingDomain::class,
|
||||||
|
'updated' => Events\DomainUpdated::class,
|
||||||
|
'updating' => Events\UpdatingDomain::class,
|
||||||
|
'deleted' => Events\DomainDeleted::class,
|
||||||
|
'deleting' => Events\DeletingDomain::class,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -83,8 +83,12 @@ class Tenant extends Model implements Contracts\Tenant
|
||||||
|
|
||||||
public $dispatchesEvents = [
|
public $dispatchesEvents = [
|
||||||
'saved' => Events\TenantSaved::class,
|
'saved' => Events\TenantSaved::class,
|
||||||
|
'saving' => Events\SavingTenant::class,
|
||||||
'created' => Events\TenantCreated::class,
|
'created' => Events\TenantCreated::class,
|
||||||
|
'creating' => Events\CreatingTenant::class,
|
||||||
'updated' => Events\TenantUpdated::class,
|
'updated' => Events\TenantUpdated::class,
|
||||||
|
'updating' => Events\UpdatingTenant::class,
|
||||||
'deleted' => Events\TenantDeleted::class,
|
'deleted' => Events\TenantDeleted::class,
|
||||||
|
'deleting' => Events\DeletingTenant::class,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
7
src/Events/BootstrappingTenancy.php
Normal file
7
src/Events/BootstrappingTenancy.php
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Stancl\Tenancy\Events;
|
||||||
|
|
||||||
|
class BootstrappingTenancy extends Contracts\TenancyEvent
|
||||||
|
{
|
||||||
|
}
|
||||||
16
src/Events/Contracts/TenancyEvent.php
Normal file
16
src/Events/Contracts/TenancyEvent.php
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Stancl\Tenancy\Events\Contracts;
|
||||||
|
|
||||||
|
use Stancl\Tenancy\Tenancy;
|
||||||
|
|
||||||
|
abstract class TenancyEvent
|
||||||
|
{
|
||||||
|
/** @var Tenancy */
|
||||||
|
public $tenancy;
|
||||||
|
|
||||||
|
public function __construct(Tenancy $tenancy)
|
||||||
|
{
|
||||||
|
$this->tenancy = $tenancy;
|
||||||
|
}
|
||||||
|
}
|
||||||
7
src/Events/CreatingDomain.php
Normal file
7
src/Events/CreatingDomain.php
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Stancl\Tenancy\Events;
|
||||||
|
|
||||||
|
class CreatingDomain extends Contracts\DomainEvent
|
||||||
|
{
|
||||||
|
}
|
||||||
7
src/Events/CreatingTenant.php
Normal file
7
src/Events/CreatingTenant.php
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Stancl\Tenancy\Events;
|
||||||
|
|
||||||
|
class CreatingTenant extends Contracts\TenantEvent
|
||||||
|
{
|
||||||
|
}
|
||||||
7
src/Events/DeletingDomain.php
Normal file
7
src/Events/DeletingDomain.php
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Stancl\Tenancy\Events;
|
||||||
|
|
||||||
|
class DeletingDomain extends Contracts\DomainEvent
|
||||||
|
{
|
||||||
|
}
|
||||||
7
src/Events/DeletingTenant.php
Normal file
7
src/Events/DeletingTenant.php
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Stancl\Tenancy\Events;
|
||||||
|
|
||||||
|
class DeletingTenant extends Contracts\TenantEvent
|
||||||
|
{
|
||||||
|
}
|
||||||
7
src/Events/EndingTenancy.php
Normal file
7
src/Events/EndingTenancy.php
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Stancl\Tenancy\Events;
|
||||||
|
|
||||||
|
class EndingTenancy extends Contracts\TenancyEvent
|
||||||
|
{
|
||||||
|
}
|
||||||
7
src/Events/InitializingTenancy.php
Normal file
7
src/Events/InitializingTenancy.php
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Stancl\Tenancy\Events;
|
||||||
|
|
||||||
|
class InitializingTenancy extends Contracts\TenancyEvent
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
@ -2,15 +2,6 @@
|
||||||
|
|
||||||
namespace Stancl\Tenancy\Events;
|
namespace Stancl\Tenancy\Events;
|
||||||
|
|
||||||
use Stancl\Tenancy\Tenancy;
|
class RevertedToCentralContext extends Contracts\TenancyEvent
|
||||||
|
|
||||||
class RevertedToCentralContext
|
|
||||||
{
|
{
|
||||||
/** @var Tenancy */
|
|
||||||
public $tenancy;
|
|
||||||
|
|
||||||
public function __construct(Tenancy $tenancy)
|
|
||||||
{
|
|
||||||
$this->tenancy = $tenancy;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
7
src/Events/RevertingToCentralContext.php
Normal file
7
src/Events/RevertingToCentralContext.php
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Stancl\Tenancy\Events;
|
||||||
|
|
||||||
|
class RevertingToCentralContext extends Contracts\TenancyEvent
|
||||||
|
{
|
||||||
|
}
|
||||||
6
src/Events/SavedDomain.php
Normal file
6
src/Events/SavedDomain.php
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Stancl\Tenancy\Events;
|
||||||
|
|
||||||
|
class SavedDomain extends Contracts\DomainEvent
|
||||||
|
{}
|
||||||
7
src/Events/SavedTenant.php
Normal file
7
src/Events/SavedTenant.php
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Stancl\Tenancy\Events;
|
||||||
|
|
||||||
|
class SavedTenant extends Contracts\TenantEvent
|
||||||
|
{
|
||||||
|
}
|
||||||
7
src/Events/SavingDomain.php
Normal file
7
src/Events/SavingDomain.php
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Stancl\Tenancy\Events;
|
||||||
|
|
||||||
|
class SavingDomain extends Contracts\DomainEvent
|
||||||
|
{
|
||||||
|
}
|
||||||
7
src/Events/SavingTenant.php
Normal file
7
src/Events/SavingTenant.php
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Stancl\Tenancy\Events;
|
||||||
|
|
||||||
|
class SavingTenant extends Contracts\TenantEvent
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
@ -2,15 +2,6 @@
|
||||||
|
|
||||||
namespace Stancl\Tenancy\Events;
|
namespace Stancl\Tenancy\Events;
|
||||||
|
|
||||||
use Stancl\Tenancy\Tenancy;
|
class TenancyBootstrapped extends Contracts\TenancyEvent
|
||||||
|
|
||||||
class TenancyBootstrapped
|
|
||||||
{
|
{
|
||||||
/** @var Tenancy */
|
|
||||||
public $tenancy;
|
|
||||||
|
|
||||||
public function __construct(Tenancy $tenancy)
|
|
||||||
{
|
|
||||||
$this->tenancy = $tenancy;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,6 @@
|
||||||
|
|
||||||
namespace Stancl\Tenancy\Events;
|
namespace Stancl\Tenancy\Events;
|
||||||
|
|
||||||
use Stancl\Tenancy\Tenancy;
|
class TenancyEnded extends Contracts\TenancyEvent
|
||||||
|
|
||||||
class TenancyEnded
|
|
||||||
{
|
{
|
||||||
/** @var Tenancy */
|
|
||||||
public $tenancy;
|
|
||||||
|
|
||||||
public function __construct(Tenancy $tenancy)
|
|
||||||
{
|
|
||||||
$this->tenancy = $tenancy;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -2,15 +2,6 @@
|
||||||
|
|
||||||
namespace Stancl\Tenancy\Events;
|
namespace Stancl\Tenancy\Events;
|
||||||
|
|
||||||
use Stancl\Tenancy\Tenancy;
|
class TenancyInitialized extends Contracts\TenancyEvent
|
||||||
|
|
||||||
class TenancyInitialized
|
|
||||||
{
|
{
|
||||||
/** @var Tenancy */
|
|
||||||
public $tenancy;
|
|
||||||
|
|
||||||
public function __construct(Tenancy $tenancy)
|
|
||||||
{
|
|
||||||
$this->tenancy = $tenancy;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
7
src/Events/UpdatingDomain.php
Normal file
7
src/Events/UpdatingDomain.php
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Stancl\Tenancy\Events;
|
||||||
|
|
||||||
|
class UpdatingDomain extends Contracts\DomainEvent
|
||||||
|
{
|
||||||
|
}
|
||||||
7
src/Events/UpdatingTenant.php
Normal file
7
src/Events/UpdatingTenant.php
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Stancl\Tenancy\Events;
|
||||||
|
|
||||||
|
class UpdatingTenant extends Contracts\TenantEvent
|
||||||
|
{
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue