mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 10:14:04 +00:00
Make RootUrlBootstrapper run ONLY in CLI by default (add $rootUrlOverrideInTests), work with resolved UrlGenerator
This commit is contained in:
parent
2c0f61585d
commit
ab02d2885c
1 changed files with 9 additions and 5 deletions
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue