mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 19:14:03 +00:00
Add UrlTenancyBootstrapper
This commit is contained in:
parent
21d55ef472
commit
1b00f5f1ae
3 changed files with 49 additions and 1 deletions
34
src/Bootstrappers/UrlTenancyBootstrapper.php
Normal file
34
src/Bootstrappers/UrlTenancyBootstrapper.php
Normal 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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue