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

Intelligent asset()

This commit is contained in:
Samuel Štancl 2019-09-21 16:43:03 +02:00
parent 6134c8113b
commit a34bcfbe3e
4 changed files with 17 additions and 4 deletions

View file

@ -9,6 +9,7 @@ use Illuminate\Support\Facades\Storage;
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
use Stancl\Tenancy\Tenant;
// todo test the helpers
class FilesystemTenancyBootstrapper implements TenancyBootstrapper
{
protected $originalPaths = [];
@ -22,7 +23,8 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
$this->originalPaths = [
'disks' => [],
'path' => $this->app->storagePath(),
'asset' => $this->app['config']['asset_url'],
'asset_url' => $this->app['config']['app.asset_url'],
'forced_root' => $this->app['url']->getForcedRoot(),
];
}
@ -34,8 +36,12 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
$this->app->useStoragePath($this->originalPaths['path'] . "/{$suffix}");
// asset()
$this->app['config']['app.asset_url'] = ($this->originalPaths['asset'] ?? $this->app['config']['app.url']) . "/$suffix";
$this->app['url']->setAssetRoot($this->app['config']['app.asset_url']);
if ($this->originalPaths['asset_url']) {
$this->app['config']['app.asset_url'] = ($this->originalPaths['asset_url'] ?? $this->app['config']['app.url']) . "/$suffix";
$this->app['url']->setAssetRoot($this->app['config']['app.asset_url']);
} else {
$this->app['url']->forceRootUrl($this->app['url']->route('stancl.tenancy.asset', ['path' => '']));
}
// Storage facade
foreach ($this->app['config']['tenancy.filesystem.disks'] as $disk) {
@ -57,8 +63,9 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
$this->app->useStoragePath($this->originalPaths['path']);
// asset()
$this->app['config']['app.asset_url'] = $this->originalPaths['asset'];
$this->app['config']['app.asset_url'] = $this->originalPaths['asset_url'];
$this->app['url']->setAssetRoot($this->app['config']['app.asset_url']);
$this->app['url']->forceRootUrl($this->originalPaths['forced_root']);
// Storage facade
foreach ($this->app['config']['tenancy.filesystem.disks'] as $disk) {

View file

@ -46,6 +46,9 @@ class TenancyServiceProvider extends ServiceProvider
return $this;
});
$this->app['url']->macro('getForcedRoot', function () {
return $this->forcedRoot;
});
}
/**

View file

@ -35,6 +35,7 @@ if (! \function_exists('tenant_asset')) {
}
if (! \function_exists('global_asset')) {
// todo test this
function global_asset($asset)
{
return app('globalUrl')->asset($asset);

View file

@ -2,6 +2,8 @@
declare(strict_types=1);
// if app.asset_url is set, suffix it
// if it's not set, use this controller?
Route::get('/tenancy/assets/{path}', 'Stancl\Tenancy\Controllers\TenantAssetsController@asset')
->where('path', '(.*)')
->name('stancl.tenancy.asset');