mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 18:44:03 +00:00
Fix tenant asset controller middleware() logic
This commit is contained in:
parent
d243309bcf
commit
fdd401fc8f
2 changed files with 13 additions and 9 deletions
|
|
@ -12,14 +12,14 @@ use Illuminate\Routing\Controllers\Middleware;
|
||||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
class TenantAssetController implements HasMiddleware // todo@docs this was renamed from TenantAssetsController
|
class TenantAssetController implements HasMiddleware
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Used for adding custom headers to the response.
|
* Used for adding custom headers to the response.
|
||||||
*
|
*
|
||||||
* @var (Closure(Request): array)|null
|
* @var (Closure(Request): array)|array
|
||||||
*/
|
*/
|
||||||
public static Closure|null $headers;
|
public static Closure|array $headers = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Additional middleware to be used on the route to this controller.
|
* Additional middleware to be used on the route to this controller.
|
||||||
|
|
@ -30,12 +30,13 @@ class TenantAssetController implements HasMiddleware // todo@docs this was renam
|
||||||
|
|
||||||
public static function middleware()
|
public static function middleware()
|
||||||
{
|
{
|
||||||
return [
|
return array_map(
|
||||||
new Middleware(array_merge(
|
fn ($middleware) => new Middleware($middleware),
|
||||||
|
array_merge(
|
||||||
[tenancy()->defaultMiddleware()],
|
[tenancy()->defaultMiddleware()],
|
||||||
static::$middleware,
|
static::$middleware,
|
||||||
)),
|
),
|
||||||
];
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -46,7 +47,9 @@ class TenantAssetController implements HasMiddleware // todo@docs this was renam
|
||||||
$this->validatePath($path);
|
$this->validatePath($path);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$headers = isset(static::$headers) ? (static::$headers)($request) : [];
|
$headers = static::$headers instanceof Closure
|
||||||
|
? (static::$headers)($request)
|
||||||
|
: static::$headers;
|
||||||
|
|
||||||
return response()->file(storage_path("app/public/$path"), $headers);
|
return response()->file(storage_path("app/public/$path"), $headers);
|
||||||
} catch (Throwable) {
|
} catch (Throwable) {
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ beforeEach(function () {
|
||||||
|
|
||||||
TenancyUrlGenerator::$prefixRouteNames = false;
|
TenancyUrlGenerator::$prefixRouteNames = false;
|
||||||
TenancyUrlGenerator::$passTenantParameterToRoutes = true;
|
TenancyUrlGenerator::$passTenantParameterToRoutes = true;
|
||||||
|
TenantAssetController::$headers = [];
|
||||||
|
|
||||||
/** @var CloneRoutesAsTenant $cloneAction */
|
/** @var CloneRoutesAsTenant $cloneAction */
|
||||||
$cloneAction = app(CloneRoutesAsTenant::class);
|
$cloneAction = app(CloneRoutesAsTenant::class);
|
||||||
|
|
@ -137,7 +138,7 @@ test('TenantAssetController headers are configurable', function () {
|
||||||
$response->assertSuccessful();
|
$response->assertSuccessful();
|
||||||
$response->assertHeader('X-Foo', 'Bar');
|
$response->assertHeader('X-Foo', 'Bar');
|
||||||
|
|
||||||
TenantAssetController::$headers = null; // reset static property
|
TenantAssetController::$headers = []; // reset static property
|
||||||
});
|
});
|
||||||
|
|
||||||
test('global asset helper returns the same url regardless of tenancy initialization', function () {
|
test('global asset helper returns the same url regardless of tenancy initialization', function () {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue