mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 22:34:03 +00:00
vague first draft of v3. TenantModelTest is passing
This commit is contained in:
parent
c2c90ff755
commit
bd9aad229b
56 changed files with 803 additions and 1366 deletions
19
src/Events/Contracts/DomainEvent.php
Normal file
19
src/Events/Contracts/DomainEvent.php
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Events\Contracts;
|
||||
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Stancl\Tenancy\Database\Models\Domain;
|
||||
|
||||
abstract class DomainEvent
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/** @var Domain */
|
||||
public $domain;
|
||||
|
||||
public function __construct(Domain $domain)
|
||||
{
|
||||
$this->domain = $domain;
|
||||
}
|
||||
}
|
||||
19
src/Events/Contracts/TenantEvent.php
Normal file
19
src/Events/Contracts/TenantEvent.php
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Events\Contracts;
|
||||
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Stancl\Tenancy\Database\Models\Tenant;
|
||||
|
||||
abstract class TenantEvent
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/** @var Tenant */
|
||||
public $tenant;
|
||||
|
||||
public function __construct(Tenant $tenant)
|
||||
{
|
||||
$this->tenant = $tenant;
|
||||
}
|
||||
}
|
||||
7
src/Events/DatabaseCreated.php
Normal file
7
src/Events/DatabaseCreated.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Events;
|
||||
|
||||
class DatabaseCreated extends Contracts\TenantEvent
|
||||
{
|
||||
}
|
||||
7
src/Events/DatabaseDeleted.php
Normal file
7
src/Events/DatabaseDeleted.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Events;
|
||||
|
||||
class DatabaseDeleted extends Contracts\TenantEvent
|
||||
{
|
||||
}
|
||||
6
src/Events/DatabaseMigrated.php
Normal file
6
src/Events/DatabaseMigrated.php
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Events;
|
||||
|
||||
class DatabaseMigrated extends Contracts\TenantEvent
|
||||
{}
|
||||
7
src/Events/DatabaseSeeded.php
Normal file
7
src/Events/DatabaseSeeded.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Events;
|
||||
|
||||
class DatabaseSeeded extends Contracts\TenantEvent
|
||||
{
|
||||
}
|
||||
7
src/Events/DomainCreated.php
Normal file
7
src/Events/DomainCreated.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Events;
|
||||
|
||||
class DomainCreated extends Contracts\DomainEvent
|
||||
{
|
||||
}
|
||||
7
src/Events/DomainDeleted.php
Normal file
7
src/Events/DomainDeleted.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Events;
|
||||
|
||||
class DomainDeleted extends Contracts\DomainEvent
|
||||
{
|
||||
}
|
||||
7
src/Events/DomainSaved.php
Normal file
7
src/Events/DomainSaved.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Events;
|
||||
|
||||
class DomainSaved extends Contracts\DomainEvent
|
||||
{
|
||||
}
|
||||
7
src/Events/DomainUpdated.php
Normal file
7
src/Events/DomainUpdated.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Events;
|
||||
|
||||
class DomainUpdated extends Contracts\DomainEvent
|
||||
{
|
||||
}
|
||||
0
src/Events/Listeners/BootstrapTenancy.php
Normal file
0
src/Events/Listeners/BootstrapTenancy.php
Normal file
74
src/Events/Listeners/JobPipeline.php
Normal file
74
src/Events/Listeners/JobPipeline.php
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Events\Listeners;
|
||||
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Pipeline\Pipeline;
|
||||
|
||||
class JobPipeline implements ShouldQueue
|
||||
{
|
||||
/** @var bool */
|
||||
public static $shouldQueueByDefault = true;
|
||||
|
||||
/** @var callable[]|string[] */
|
||||
public $jobs = [];
|
||||
|
||||
/** @var callable */
|
||||
public $send;
|
||||
|
||||
/** @var bool */
|
||||
public $shouldQueue = true;
|
||||
|
||||
public function __construct($jobs, callable $send = null, bool $shouldQueue = null)
|
||||
{
|
||||
$this->jobs = $jobs;
|
||||
$this->send = $send ?? function ($event) {
|
||||
// If no $send callback is set, we'll just pass the event through the jobs.
|
||||
return $event;
|
||||
};
|
||||
$this->shouldQueue = $shouldQueue ?? static::$shouldQueueByDefault;
|
||||
}
|
||||
|
||||
/** @param callable[]|string[] $jobs */
|
||||
public static function make(array $jobs): self
|
||||
{
|
||||
return new static($jobs);
|
||||
}
|
||||
|
||||
public function queue(bool $shouldQueue): self
|
||||
{
|
||||
$this->shouldQueue = $shouldQueue;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function send(callable $send): self
|
||||
{
|
||||
$this->send = $send;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** @return bool|$this */
|
||||
public function shouldQueue(bool $shouldQueue = null)
|
||||
{
|
||||
if ($shouldQueue !== null) {
|
||||
$this->shouldQueue = $shouldQueue;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this->shouldQueue;
|
||||
}
|
||||
|
||||
public function handle($event): void
|
||||
{
|
||||
/** @var Pipeline $pipeline */
|
||||
$pipeline = app(Pipeline::class);
|
||||
|
||||
$pipeline
|
||||
->send(($this->send)($event))
|
||||
->through($this->jobs)
|
||||
->thenReturn();
|
||||
}
|
||||
}
|
||||
15
src/Events/Listeners/QueueableListener.php
Normal file
15
src/Events/Listeners/QueueableListener.php
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Events\Listeners;
|
||||
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
abstract class QueueableListener implements ShouldQueue
|
||||
{
|
||||
public static $shouldQueue = false;
|
||||
|
||||
public function shouldQueue()
|
||||
{
|
||||
return static::$shouldQueue;
|
||||
}
|
||||
}
|
||||
15
src/Events/Listeners/RevertToCentral.php
Normal file
15
src/Events/Listeners/RevertToCentral.php
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Events\Listeners;
|
||||
|
||||
use Stancl\Tenancy\Events\TenancyEnded;
|
||||
|
||||
class RevertToCentral
|
||||
{
|
||||
public function handle(TenancyEnded $event)
|
||||
{
|
||||
foreach (tenancy()->getBootstrappers() as $bootstrapper) {
|
||||
$bootstrapper->end();
|
||||
}
|
||||
}
|
||||
}
|
||||
16
src/Events/TenancyEnded.php
Normal file
16
src/Events/TenancyEnded.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Events;
|
||||
|
||||
use Stancl\Tenancy\Database\Models\Tenant;
|
||||
|
||||
class TenancyEnded
|
||||
{
|
||||
/** @var Tenant */
|
||||
protected $tenant;
|
||||
|
||||
public function __construct(Tenant $tenant)
|
||||
{
|
||||
$this->tenant = $tenant;
|
||||
}
|
||||
}
|
||||
16
src/Events/TenancyInitialized.php
Normal file
16
src/Events/TenancyInitialized.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Events;
|
||||
|
||||
use Stancl\Tenancy\Database\Models\Tenant;
|
||||
|
||||
class TenancyInitialized
|
||||
{
|
||||
/** @var Tenant */
|
||||
protected $tenant;
|
||||
|
||||
public function __construct(Tenant $tenant)
|
||||
{
|
||||
$this->tenant = $tenant;
|
||||
}
|
||||
}
|
||||
7
src/Events/TenantCreated.php
Normal file
7
src/Events/TenantCreated.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Events;
|
||||
|
||||
class TenantCreated extends Contracts\TenantEvent
|
||||
{
|
||||
}
|
||||
7
src/Events/TenantDeleted.php
Normal file
7
src/Events/TenantDeleted.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Events;
|
||||
|
||||
class TenantDeleted extends Contracts\TenantEvent
|
||||
{
|
||||
}
|
||||
7
src/Events/TenantSaved.php
Normal file
7
src/Events/TenantSaved.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Events;
|
||||
|
||||
class TenantSaved extends Contracts\TenantEvent
|
||||
{
|
||||
}
|
||||
7
src/Events/TenantUpdated.php
Normal file
7
src/Events/TenantUpdated.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Events;
|
||||
|
||||
class TenantUpdated extends Contracts\TenantEvent
|
||||
{
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue