From 1fbb2f42a36d15743c29b41f9c5d2a833d906782 Mon Sep 17 00:00:00 2001 From: Chinmay Purav Date: Sat, 18 Mar 2023 19:48:48 +0530 Subject: [PATCH] Tenancy Fake basic logic added --- src/Facades/Tenancy.php | 5 ++++ src/Facades/TenancyFake.php | 46 +++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 src/Facades/TenancyFake.php diff --git a/src/Facades/Tenancy.php b/src/Facades/Tenancy.php index 1395ba63..50a35fdc 100644 --- a/src/Facades/Tenancy.php +++ b/src/Facades/Tenancy.php @@ -12,4 +12,9 @@ class Tenancy extends Facade { return \Stancl\Tenancy\Tenancy::class; } + + public static function fake() + { + static::swap(new TenancyFake); + } } diff --git a/src/Facades/TenancyFake.php b/src/Facades/TenancyFake.php new file mode 100644 index 00000000..8926b819 --- /dev/null +++ b/src/Facades/TenancyFake.php @@ -0,0 +1,46 @@ +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]); + } +}