mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 17:04:04 +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 Throwable;
|
||||
|
||||
class TenantAssetController implements HasMiddleware // todo@docs this was renamed from TenantAssetsController
|
||||
class TenantAssetController implements HasMiddleware
|
||||
{
|
||||
/**
|
||||
* 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.
|
||||
|
|
@ -30,12 +30,13 @@ class TenantAssetController implements HasMiddleware // todo@docs this was renam
|
|||
|
||||
public static function middleware()
|
||||
{
|
||||
return [
|
||||
new Middleware(array_merge(
|
||||
return array_map(
|
||||
fn ($middleware) => new Middleware($middleware),
|
||||
array_merge(
|
||||
[tenancy()->defaultMiddleware()],
|
||||
static::$middleware,
|
||||
)),
|
||||
];
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -46,7 +47,9 @@ class TenantAssetController implements HasMiddleware // todo@docs this was renam
|
|||
$this->validatePath($path);
|
||||
|
||||
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);
|
||||
} catch (Throwable) {
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ beforeEach(function () {
|
|||
|
||||
TenancyUrlGenerator::$prefixRouteNames = false;
|
||||
TenancyUrlGenerator::$passTenantParameterToRoutes = true;
|
||||
TenantAssetController::$headers = [];
|
||||
|
||||
/** @var CloneRoutesAsTenant $cloneAction */
|
||||
$cloneAction = app(CloneRoutesAsTenant::class);
|
||||
|
|
@ -137,7 +138,7 @@ test('TenantAssetController headers are configurable', function () {
|
|||
$response->assertSuccessful();
|
||||
$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 () {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue