From f83504ac6f61e260d5382a5feaac0fa98ef98664 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Fri, 2 Sep 2022 17:24:37 +0200 Subject: [PATCH] [4.x] Add ScoutTenancyBootstrapper (#936) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add ScoutTenancyBootstrapper * Fix code style (php-cs-fixer) * extract getTenantPrefix method * Fix code style (php-cs-fixer) Co-authored-by: PHP CS Fixer Co-authored-by: Samuel Ć tancl --- .../Integrations/ScoutTenancyBootstrapper.php | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/Bootstrappers/Integrations/ScoutTenancyBootstrapper.php diff --git a/src/Bootstrappers/Integrations/ScoutTenancyBootstrapper.php b/src/Bootstrappers/Integrations/ScoutTenancyBootstrapper.php new file mode 100644 index 00000000..49869bb5 --- /dev/null +++ b/src/Bootstrappers/Integrations/ScoutTenancyBootstrapper.php @@ -0,0 +1,42 @@ +config = $config; + } + + public function bootstrap(Tenant $tenant) + { + if (! isset($this->originalScoutPrefix)) { + $this->originalScoutPrefix = $this->config->get('scout.prefix'); + } + + $this->config->set('scout.prefix', $this->getTenantPrefix($tenant)); + } + + public function revert() + { + $this->config->set('scout.prefix', $this->originalScoutPrefix); + } + + protected function getTenantPrefix(Tenant $tenant): string + { + return (string) $tenant->getTenantKey(); + } +}