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

Add UrlTenancyBootstrapper

This commit is contained in:
lukinovec 2023-01-12 06:42:21 +01:00
parent 21d55ef472
commit 1b00f5f1ae
3 changed files with 49 additions and 1 deletions

View file

@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Bootstrappers;
use Closure;
use Stancl\Tenancy\Contracts\Tenant;
use Illuminate\Contracts\Routing\UrlGenerator;
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
class UrlTenancyBootstrapper implements TenancyBootstrapper
{
public static Closure|null $rootUrlOverride = null;
protected string|null $originalRootUrl = null;
public function __construct(protected UrlGenerator $urlGenerator)
{
}
public function bootstrap(Tenant $tenant): void
{
$this->originalRootUrl = $this->urlGenerator->to('/');
if (static::$rootUrlOverride) {
$this->urlGenerator->forceRootUrl((static::$rootUrlOverride)($tenant));
}
}
public function revert(): void
{
$this->urlGenerator->forceRootUrl($this->originalRootUrl);
}
}