1
0
Fork 0
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:
Samuel Štancl 2020-05-08 04:37:43 +02:00
parent c2c90ff755
commit bd9aad229b
56 changed files with 803 additions and 1366 deletions

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

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

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

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

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

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

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

View file

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

View file

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

View file

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

View file

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