1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 17:34:03 +00:00
tenancy/src/Bootstrappers/UrlTenancyBootstrapper.php
2023-02-01 14:37:34 +00:00

35 lines
865 B
PHP

<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Bootstrappers;
use Closure;
use Illuminate\Contracts\Routing\UrlGenerator;
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
use Stancl\Tenancy\Contracts\Tenant;
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);
}
}