mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 17:04:04 +00:00
globalUrl: useAssetOrigin() instead of setAssetRoot()
This change was prompted by a phpstan failure after a recent update. While making this change, I noticed we don't need the macro anymore as useAssetOrigin() was added to the UrlGenerator earlier this year, simplifying our implementation.
This commit is contained in:
parent
0cd0bc44b1
commit
45cf7029af
3 changed files with 9 additions and 19 deletions
|
|
@ -46,10 +46,6 @@ parameters:
|
||||||
message: '#PHPDoc tag \@param has invalid value \(dynamic#'
|
message: '#PHPDoc tag \@param has invalid value \(dynamic#'
|
||||||
paths:
|
paths:
|
||||||
- src/helpers.php
|
- src/helpers.php
|
||||||
-
|
|
||||||
message: '#Illuminate\\Routing\\UrlGenerator#'
|
|
||||||
paths:
|
|
||||||
- src/Bootstrappers/FilesystemTenancyBootstrapper.php
|
|
||||||
- '#Method Stancl\\Tenancy\\Tenancy::cachedResolvers\(\) should return array#'
|
- '#Method Stancl\\Tenancy\\Tenancy::cachedResolvers\(\) should return array#'
|
||||||
- '#Access to an undefined property Stancl\\Tenancy\\Middleware\\IdentificationMiddleware\:\:\$tenancy#'
|
- '#Access to an undefined property Stancl\\Tenancy\\Middleware\\IdentificationMiddleware\:\:\$tenancy#'
|
||||||
- '#Access to an undefined property Stancl\\Tenancy\\Middleware\\IdentificationMiddleware\:\:\$resolver#'
|
- '#Access to an undefined property Stancl\\Tenancy\\Middleware\\IdentificationMiddleware\:\:\$resolver#'
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ declare(strict_types=1);
|
||||||
namespace Stancl\Tenancy\Bootstrappers;
|
namespace Stancl\Tenancy\Bootstrappers;
|
||||||
|
|
||||||
use Illuminate\Foundation\Application;
|
use Illuminate\Foundation\Application;
|
||||||
use Illuminate\Routing\UrlGenerator;
|
|
||||||
use Illuminate\Session\FileSessionHandler;
|
use Illuminate\Session\FileSessionHandler;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
||||||
|
|
@ -22,13 +21,6 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
|
||||||
) {
|
) {
|
||||||
$this->originalAssetUrl = $this->app['config']['app.asset_url'];
|
$this->originalAssetUrl = $this->app['config']['app.asset_url'];
|
||||||
$this->originalStoragePath = $app->storagePath();
|
$this->originalStoragePath = $app->storagePath();
|
||||||
|
|
||||||
$this->app['url']->macro('setAssetRoot', function ($root) {
|
|
||||||
/** @var UrlGenerator $this */
|
|
||||||
$this->assetRoot = $root;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function bootstrap(Tenant $tenant): void
|
public function bootstrap(Tenant $tenant): void
|
||||||
|
|
@ -107,16 +99,16 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
|
||||||
|
|
||||||
if ($suffix === false) {
|
if ($suffix === false) {
|
||||||
$this->app['config']['app.asset_url'] = $this->originalAssetUrl;
|
$this->app['config']['app.asset_url'] = $this->originalAssetUrl;
|
||||||
$this->app['url']->setAssetRoot($this->originalAssetUrl);
|
$this->app['url']->useAssetOrigin($this->originalAssetUrl);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->originalAssetUrl) {
|
if ($this->originalAssetUrl) {
|
||||||
$this->app['config']['app.asset_url'] = $this->originalAssetUrl . "/$suffix";
|
$this->app['config']['app.asset_url'] = $this->originalAssetUrl . "/$suffix";
|
||||||
$this->app['url']->setAssetRoot($this->app['config']['app.asset_url']);
|
$this->app['url']->useAssetOrigin($this->app['config']['app.asset_url']);
|
||||||
} else {
|
} else {
|
||||||
$this->app['url']->setAssetRoot($this->app['url']->route('stancl.tenancy.asset', ['path' => '']));
|
$this->app['url']->useAssetOrigin($this->app['url']->route('stancl.tenancy.asset', ['path' => '']));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ namespace Stancl\Tenancy;
|
||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
use Illuminate\Cache\CacheManager;
|
use Illuminate\Cache\CacheManager;
|
||||||
|
use Illuminate\Contracts\Container\Container;
|
||||||
use Illuminate\Database\Console\Migrations\FreshCommand;
|
use Illuminate\Database\Console\Migrations\FreshCommand;
|
||||||
use Illuminate\Routing\Events\RouteMatched;
|
use Illuminate\Routing\Events\RouteMatched;
|
||||||
use Illuminate\Support\Facades\Event;
|
use Illuminate\Support\Facades\Event;
|
||||||
|
|
@ -157,12 +158,13 @@ class TenancyServiceProvider extends ServiceProvider
|
||||||
$this->loadRoutesFrom(__DIR__ . '/../assets/routes.php');
|
$this->loadRoutesFrom(__DIR__ . '/../assets/routes.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->app->singleton('globalUrl', function ($app) {
|
$this->app->singleton('globalUrl', function (Container $app) {
|
||||||
if ($app->bound(FilesystemTenancyBootstrapper::class)) {
|
if ($app->bound(FilesystemTenancyBootstrapper::class)) {
|
||||||
$instance = clone $app['url'];
|
/** @var \Illuminate\Routing\UrlGenerator */
|
||||||
$instance->setAssetRoot($app[FilesystemTenancyBootstrapper::class]->originalAssetUrl);
|
$instance = clone $app->make('url');
|
||||||
|
$instance->useAssetOrigin($app->make(FilesystemTenancyBootstrapper::class)->originalAssetUrl);
|
||||||
} else {
|
} else {
|
||||||
$instance = $app['url'];
|
$instance = $app->make('url');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $instance;
|
return $instance;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue