Skip to content

Commit 7523eb2

Browse files
authored
Merge pull request #418 from RayTM/master
[BUGFIX] Added missing middleware implementing frontend.cache.instruction for TYPO3 v13
2 parents c638b4e + 7877202 commit 7523eb2

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SFC\Staticfilecache\Middleware;
6+
7+
use Psr\Http\Message\ResponseInterface;
8+
use Psr\Http\Message\ServerRequestInterface;
9+
use Psr\Http\Server\MiddlewareInterface;
10+
use Psr\Http\Server\RequestHandlerInterface;
11+
use TYPO3\CMS\Frontend\Cache\CacheInstruction;
12+
13+
class FrontendCacheMiddleware implements MiddlewareInterface
14+
{
15+
public function process(
16+
ServerRequestInterface $request,
17+
RequestHandlerInterface $handler,
18+
): ResponseInterface
19+
{
20+
if (class_exists(CacheInstruction::class)) {
21+
// Get the attribute, if not available, use a new CacheInstruction object
22+
$cacheInstruction = $request->getAttribute(
23+
'frontend.cache.instruction',
24+
new CacheInstruction(),
25+
);
26+
27+
// Disable the cache and give a reason
28+
$cacheInstruction->disableCache('EXT:staticfilecache: Cache is disabled');
29+
30+
// Write back the cache instruction to the attribute
31+
$request = $request->withAttribute('frontend.cache.instruction', $cacheInstruction);
32+
}
33+
return $handler->handle($request);
34+
}
35+
}

Configuration/RequestMiddlewares.php

+10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use SFC\Staticfilecache\Middleware\CookieCheckMiddleware;
66
use SFC\Staticfilecache\Middleware\FallbackMiddleware;
77
use SFC\Staticfilecache\Middleware\FrontendUserMiddleware;
8+
use SFC\Staticfilecache\Middleware\FrontendCacheMiddleware;
89
use SFC\Staticfilecache\Middleware\GenerateMiddleware;
910
use SFC\Staticfilecache\Middleware\PrepareMiddleware;
1011

@@ -40,6 +41,15 @@
4041
'staticfilecache/generate',
4142
],
4243
],
44+
'staticfilecache/frontend-cache' => [
45+
'target' => FrontendCacheMiddleware::class,
46+
'after' => [
47+
'typo3/cms-frontend/authentication',
48+
],
49+
'before' => [
50+
'staticfilecache/generate',
51+
],
52+
],
4353
'staticfilecache/cookie-check' => [
4454
'target' => CookieCheckMiddleware::class,
4555
'before' => [

0 commit comments

Comments
 (0)