1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 20:54:04 +00:00

[4.x] Allow user to customize tenant's URL root in CLI (#1044)

* Add UrlTenancyBootstrapper

* Fix code style (php-cs-fixer)

* Move URL overriding to a separate method, call it in `boot()`

* Test URL root overriding

* Change parameter formatting

Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>

* Fix code style (php-cs-fixer)

* Improve URL bootstrapper test

* Move `$scheme` and `$hostname` to the closure

* Update code example comment

* Hardcode values instead of referencing variables

* Delete extra line

---------

Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
This commit is contained in:
lukinovec 2023-02-17 10:56:43 +01:00 committed by GitHub
parent a006e49881
commit 617e9a7a73
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 102 additions and 6 deletions

View file

@ -0,0 +1,35 @@
<?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);
}
}