mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 15:14:04 +00:00
Tenancy Fake basic logic added
This commit is contained in:
parent
7d98ebb5d1
commit
1fbb2f42a3
2 changed files with 51 additions and 0 deletions
|
|
@ -12,4 +12,9 @@ class Tenancy extends Facade
|
||||||
{
|
{
|
||||||
return \Stancl\Tenancy\Tenancy::class;
|
return \Stancl\Tenancy\Tenancy::class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function fake()
|
||||||
|
{
|
||||||
|
static::swap(new TenancyFake);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
46
src/Facades/TenancyFake.php
Normal file
46
src/Facades/TenancyFake.php
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Stancl\Tenancy\Facades;
|
||||||
|
|
||||||
|
use Stancl\Tenancy\Database\Models\Tenant;
|
||||||
|
use Stancl\Tenancy\Tenancy;
|
||||||
|
|
||||||
|
class TenancyFake extends Tenancy
|
||||||
|
{
|
||||||
|
public function initialize($tenant): void
|
||||||
|
{
|
||||||
|
if (!is_object($tenant)) {
|
||||||
|
$tenantId = $tenant;
|
||||||
|
$tenant = $this->find($tenantId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->initialized && $this->tenant->id === $tenant->id) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Remove this (so that runForMultiple() is still performant) and make the FS bootstrapper work either way
|
||||||
|
if ($this->initialized) {
|
||||||
|
$this->end();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->tenant = $tenant;
|
||||||
|
|
||||||
|
$this->initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function end(): void
|
||||||
|
{
|
||||||
|
if (!$this->initialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->initialized = false;
|
||||||
|
|
||||||
|
$this->tenant = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function find($id): ?Tenant
|
||||||
|
{
|
||||||
|
return new Tenant(['id' => $id]);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue