1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 22:14:03 +00:00

[4.x] Add ScoutTenancyBootstrapper (#936)

* Add ScoutTenancyBootstrapper

* Fix code style (php-cs-fixer)

* extract getTenantPrefix method

* Fix code style (php-cs-fixer)

Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
This commit is contained in:
lukinovec 2022-09-02 17:24:37 +02:00 committed by GitHub
parent 020039bf89
commit f83504ac6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Bootstrappers\Integrations;
use Illuminate\Contracts\Config\Repository;
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
use Stancl\Tenancy\Contracts\Tenant;
class ScoutTenancyBootstrapper implements TenancyBootstrapper
{
/** @var Repository */
protected $config;
/** @var string */
protected $originalScoutPrefix;
public function __construct(Repository $config)
{
$this->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();
}
}