Skip to content

Commit

Permalink
Merge pull request #418 from RayTM/master
Browse files Browse the repository at this point in the history
[BUGFIX] Added missing middleware implementing frontend.cache.instruction for TYPO3 v13
  • Loading branch information
lochmueller authored Aug 15, 2024
2 parents c638b4e + 7877202 commit 7523eb2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Classes/Middleware/FrontendCacheMiddleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace SFC\Staticfilecache\Middleware;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use TYPO3\CMS\Frontend\Cache\CacheInstruction;

class FrontendCacheMiddleware implements MiddlewareInterface
{
public function process(
ServerRequestInterface $request,
RequestHandlerInterface $handler,
): ResponseInterface
{
if (class_exists(CacheInstruction::class)) {
// Get the attribute, if not available, use a new CacheInstruction object
$cacheInstruction = $request->getAttribute(

Check failure on line 22 in Classes/Middleware/FrontendCacheMiddleware.php

View workflow job for this annotation

GitHub Actions / build (8.1, 12)

There is no request attribute "frontend.cache.instruction" configured so we can't figure out the exact type to return when calling Psr\Http\Message\ServerRequestInterface::getAttribute

Check failure on line 22 in Classes/Middleware/FrontendCacheMiddleware.php

View workflow job for this annotation

GitHub Actions / build (8.2, 12)

There is no request attribute "frontend.cache.instruction" configured so we can't figure out the exact type to return when calling Psr\Http\Message\ServerRequestInterface::getAttribute
'frontend.cache.instruction',
new CacheInstruction(),
);

// Disable the cache and give a reason
$cacheInstruction->disableCache('EXT:staticfilecache: Cache is disabled');

// Write back the cache instruction to the attribute
$request = $request->withAttribute('frontend.cache.instruction', $cacheInstruction);
}
return $handler->handle($request);
}
}
10 changes: 10 additions & 0 deletions Configuration/RequestMiddlewares.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use SFC\Staticfilecache\Middleware\CookieCheckMiddleware;
use SFC\Staticfilecache\Middleware\FallbackMiddleware;
use SFC\Staticfilecache\Middleware\FrontendUserMiddleware;
use SFC\Staticfilecache\Middleware\FrontendCacheMiddleware;
use SFC\Staticfilecache\Middleware\GenerateMiddleware;
use SFC\Staticfilecache\Middleware\PrepareMiddleware;

Expand Down Expand Up @@ -40,6 +41,15 @@
'staticfilecache/generate',
],
],
'staticfilecache/frontend-cache' => [
'target' => FrontendCacheMiddleware::class,
'after' => [
'typo3/cms-frontend/authentication',
],
'before' => [
'staticfilecache/generate',
],
],
'staticfilecache/cookie-check' => [
'target' => CookieCheckMiddleware::class,
'before' => [
Expand Down

0 comments on commit 7523eb2

Please sign in to comment.