mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 05:14:03 +00:00
Make resolving 'url' return a pre-created generator instance instead of creating it on every app('url') call
This commit is contained in:
parent
ab02d2885c
commit
2266c47722
1 changed files with 15 additions and 17 deletions
|
|
@ -37,7 +37,7 @@ class UrlGeneratorBootstrapper implements TenancyBootstrapper
|
||||||
|
|
||||||
public function revert(): void
|
public function revert(): void
|
||||||
{
|
{
|
||||||
$this->app->bind('url', fn () => $this->originalUrlGenerator);
|
$this->app->extend('url', fn () => $this->originalUrlGenerator);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -47,14 +47,13 @@ class UrlGeneratorBootstrapper implements TenancyBootstrapper
|
||||||
*/
|
*/
|
||||||
protected function useTenancyUrlGenerator(): void
|
protected function useTenancyUrlGenerator(): void
|
||||||
{
|
{
|
||||||
$this->app->extend('url', function (UrlGenerator $urlGenerator, Application $app) {
|
|
||||||
$newGenerator = new TenancyUrlGenerator(
|
$newGenerator = new TenancyUrlGenerator(
|
||||||
$app['router']->getRoutes(),
|
$this->app['router']->getRoutes(),
|
||||||
$urlGenerator->getRequest(),
|
$this->originalUrlGenerator->getRequest(),
|
||||||
$app['config']->get('app.asset_url'),
|
$this->app['config']->get('app.asset_url'),
|
||||||
);
|
);
|
||||||
|
|
||||||
$newGenerator->defaults($urlGenerator->getDefaultParameters());
|
$newGenerator->defaults($this->originalUrlGenerator->getDefaultParameters());
|
||||||
|
|
||||||
$newGenerator->setSessionResolver(function () {
|
$newGenerator->setSessionResolver(function () {
|
||||||
return $this->app['session'] ?? null;
|
return $this->app['session'] ?? null;
|
||||||
|
|
@ -64,7 +63,6 @@ class UrlGeneratorBootstrapper implements TenancyBootstrapper
|
||||||
return $this->app->make('config')->get('app.key');
|
return $this->app->make('config')->get('app.key');
|
||||||
});
|
});
|
||||||
|
|
||||||
return $newGenerator;
|
$this->app->extend('url', fn () => $newGenerator);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue