1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 14:34:04 +00:00

Tenancy Fake basic logic added

This commit is contained in:
Chinmay Purav 2023-03-18 19:48:48 +05:30
parent 7d98ebb5d1
commit 1fbb2f42a3
2 changed files with 51 additions and 0 deletions

View file

@ -12,4 +12,9 @@ class Tenancy extends Facade
{
return \Stancl\Tenancy\Tenancy::class;
}
public static function fake()
{
static::swap(new TenancyFake);
}
}

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