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

Add more events

This commit is contained in:
Samuel Štancl 2020-05-17 17:42:09 +02:00
parent ed96aee669
commit b87c0bc9d2
22 changed files with 165 additions and 52 deletions

View file

@ -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 => [],
];
}

View file

@ -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,
];
}

View file

@ -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,
];
}

View file

@ -0,0 +1,7 @@
<?php
namespace Stancl\Tenancy\Events;
class BootstrappingTenancy extends Contracts\TenancyEvent
{
}

View 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;
}
}

View file

@ -0,0 +1,7 @@
<?php
namespace Stancl\Tenancy\Events;
class CreatingDomain extends Contracts\DomainEvent
{
}

View file

@ -0,0 +1,7 @@
<?php
namespace Stancl\Tenancy\Events;
class CreatingTenant extends Contracts\TenantEvent
{
}

View file

@ -0,0 +1,7 @@
<?php
namespace Stancl\Tenancy\Events;
class DeletingDomain extends Contracts\DomainEvent
{
}

View file

@ -0,0 +1,7 @@
<?php
namespace Stancl\Tenancy\Events;
class DeletingTenant extends Contracts\TenantEvent
{
}

View file

@ -0,0 +1,7 @@
<?php
namespace Stancl\Tenancy\Events;
class EndingTenancy extends Contracts\TenancyEvent
{
}

View file

@ -0,0 +1,7 @@
<?php
namespace Stancl\Tenancy\Events;
class InitializingTenancy extends Contracts\TenancyEvent
{
}

View file

@ -2,15 +2,6 @@
namespace Stancl\Tenancy\Events;
use Stancl\Tenancy\Tenancy;
class RevertedToCentralContext
class RevertedToCentralContext extends Contracts\TenancyEvent
{
/** @var Tenancy */
public $tenancy;
public function __construct(Tenancy $tenancy)
{
$this->tenancy = $tenancy;
}
}

View file

@ -0,0 +1,7 @@
<?php
namespace Stancl\Tenancy\Events;
class RevertingToCentralContext extends Contracts\TenancyEvent
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Stancl\Tenancy\Events;
class SavedDomain extends Contracts\DomainEvent
{}

View file

@ -0,0 +1,7 @@
<?php
namespace Stancl\Tenancy\Events;
class SavedTenant extends Contracts\TenantEvent
{
}

View file

@ -0,0 +1,7 @@
<?php
namespace Stancl\Tenancy\Events;
class SavingDomain extends Contracts\DomainEvent
{
}

View file

@ -0,0 +1,7 @@
<?php
namespace Stancl\Tenancy\Events;
class SavingTenant extends Contracts\TenantEvent
{
}

View file

@ -2,15 +2,6 @@
namespace Stancl\Tenancy\Events;
use Stancl\Tenancy\Tenancy;
class TenancyBootstrapped
class TenancyBootstrapped extends Contracts\TenancyEvent
{
/** @var Tenancy */
public $tenancy;
public function __construct(Tenancy $tenancy)
{
$this->tenancy = $tenancy;
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -0,0 +1,7 @@
<?php
namespace Stancl\Tenancy\Events;
class UpdatingDomain extends Contracts\DomainEvent
{
}

View file

@ -0,0 +1,7 @@
<?php
namespace Stancl\Tenancy\Events;
class UpdatingTenant extends Contracts\TenantEvent
{
}