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

Make RootUrlBootstrapper run ONLY in CLI by default (add $rootUrlOverrideInTests), work with resolved UrlGenerator

This commit is contained in:
lukinovec 2024-08-29 15:58:50 +02:00
parent 2c0f61585d
commit ab02d2885c

View file

@ -36,20 +36,24 @@ class RootUrlBootstrapper implements TenancyBootstrapper
protected string|null $originalRootUrl = null; protected string|null $originalRootUrl = null;
public static bool $rootUrlOverrideInTests = false;
public function __construct( public function __construct(
protected UrlGenerator $urlGenerator,
protected Repository $config, protected Repository $config,
protected Application $app, protected Application $app,
) {} ) {}
public function bootstrap(Tenant $tenant): void public function bootstrap(Tenant $tenant): void
{ {
if ($this->app->runningInConsole() && static::$rootUrlOverride) { $shouldRunInTests = ! app()->runningUnitTests() || static::$rootUrlOverrideInTests;
$this->originalRootUrl = $this->urlGenerator->to('/'); $shouldRun = $this->app->runningInConsole() && $shouldRunInTests && static::$rootUrlOverride;
if ($shouldRun) {
$this->originalRootUrl = $this->app['url']->to('/');
$newRootUrl = (static::$rootUrlOverride)($tenant, $this->originalRootUrl); $newRootUrl = (static::$rootUrlOverride)($tenant, $this->originalRootUrl);
$this->urlGenerator->forceRootUrl($newRootUrl); $this->app['url']->forceRootUrl($newRootUrl);
$this->config->set('app.url', $newRootUrl); $this->config->set('app.url', $newRootUrl);
} }
} }
@ -57,7 +61,7 @@ class RootUrlBootstrapper implements TenancyBootstrapper
public function revert(): void public function revert(): void
{ {
if ($this->originalRootUrl) { if ($this->originalRootUrl) {
$this->urlGenerator->forceRootUrl($this->originalRootUrl); $this->app['url']->forceRootUrl($this->originalRootUrl);
$this->config->set('app.url', $this->originalRootUrl); $this->config->set('app.url', $this->originalRootUrl);
} }
} }