Skip to content

Commit 49e34bc

Browse files
committed
Migration of TSFE to request Attributes
1 parent e545b23 commit 49e34bc

16 files changed

+61
-125
lines changed

Classes/Cache/Listener/CachingAllowedListener.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
namespace SFC\Staticfilecache\Cache\Listener;
66

77
use SFC\Staticfilecache\Event\CacheRuleEvent;
8+
use TYPO3\CMS\Frontend\Cache\CacheInstruction;
89

910
class CachingAllowedListener
1011
{
1112
public function __invoke(CacheRuleEvent $event): void
1213
{
13-
if (!$event->getRequest()->getAttribute('frontend.cache.instruction')->isCachingAllowed()) {
14+
if (!$event->getRequest()->getAttribute('frontend.cache.instruction', new CacheInstruction())->isCachingAllowed()) {
1415
$event->addExplanation(__CLASS__, 'No caching via frontend.cache.instruction attribute');
1516
}
1617
}

Classes/Cache/Listener/ForceStaticCacheListener.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
use Psr\Http\Message\ServerRequestInterface;
99
use SFC\Staticfilecache\Event\CacheRuleEvent;
1010
use SFC\Staticfilecache\Event\ForceStaticFileCacheEvent;
11-
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
11+
use TYPO3\CMS\Core\TypoScript\FrontendTypoScript;
12+
use TYPO3\CMS\Frontend\Page\PageInformation;
1213

1314
/**
1415
* Force the cache for special pages.
@@ -19,33 +20,38 @@ public function __construct(protected readonly EventDispatcherInterface $eventDi
1920

2021
public function __invoke(CacheRuleEvent $event): void
2122
{
22-
if ($event->isSkipProcessing() && $this->isForceCacheUri($GLOBALS['TSFE'] ?? null, $event->getRequest())) {
23+
if ($event->isSkipProcessing() && $this->isForceCacheUri($event->getRequest())) {
2324
$event->setSkipProcessing(false);
2425
$event->truncateExplanations();
2526

26-
if ($GLOBALS['TSFE'] instanceof TypoScriptFrontendController) {
27-
if (!\is_array($GLOBALS['TSFE']->config['INTincScript'])) {
27+
$frontendTypoScript = $event->getRequest()->getAttribute('frontend.typoscript');
28+
if ($frontendTypoScript instanceof FrontendTypoScript) {
29+
$configArray = $frontendTypoScript->getConfigArray();
30+
if (!\is_array($configArray['INTincScript'])) {
2831
// Avoid exceptions in recursivelyReplaceIntPlaceholdersInContent
29-
$GLOBALS['TSFE']->config['INTincScript'] = [];
32+
$configArray['INTincScript'] = [];
33+
$frontendTypoScript->setConfigArray($configArray);
3034
}
3135

36+
// @todo
3237
// render the plugins in the output
33-
$GLOBALS['TSFE']->INTincScript($event->getRequest());
38+
// v14??? $GLOBALS['TSFE']->INTincScript($event->getRequest());
3439
}
3540
}
3641
}
3742

3843
/**
3944
* Is force cache URI?
4045
*/
41-
protected function isForceCacheUri(?TypoScriptFrontendController $frontendController, ServerRequestInterface $request): bool
46+
protected function isForceCacheUri(ServerRequestInterface $request): bool
4247
{
43-
if (!\is_object($frontendController)) {
48+
$pageInformation = $request->getAttribute('frontend.page.information');
49+
if (!$pageInformation instanceof PageInformation) {
4450
return false;
4551
}
4652

47-
$forceStatic = (bool) ($frontendController->page['tx_staticfilecache_cache_force'] ?? false);
48-
$event = new ForceStaticFileCacheEvent($forceStatic, $frontendController, $request);
53+
$forceStatic = (bool) ($pageInformation->getPageRecord()['tx_staticfilecache_cache_force'] ?? false);
54+
$event = new ForceStaticFileCacheEvent($forceStatic, $request);
4955
$this->eventDispatcher->dispatch($event);
5056

5157
return $event->isForceStatic();

Classes/Cache/Listener/NoBackendUserListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function __construct(private readonly Context $context) {}
1717
public function __invoke(CacheRuleEvent $event): void
1818
{
1919
if ($this->context->getPropertyFromAspect('backend.user', 'isLoggedIn', false)) {
20-
$event->addExplanation(__CLASS__, 'Active BE Login (TSFE:beUserLogin)');
20+
$event->addExplanation(__CLASS__, 'Active BE Login via context -> aspect');
2121
$event->setSkipProcessing(true);
2222
}
2323
}

Classes/Cache/Listener/NoIntScriptsListener.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use SFC\Staticfilecache\Event\CacheRuleEvent;
88
use SFC\Staticfilecache\Service\ConfigurationService;
9+
use TYPO3\CMS\Core\TypoScript\FrontendTypoScript;
910
use TYPO3\CMS\Frontend\Cache\NonceValueSubstitution;
1011
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
1112

@@ -15,16 +16,19 @@ public function __construct(protected readonly ConfigurationService $configurati
1516

1617
public function __invoke(CacheRuleEvent $event): void
1718
{
18-
$tsfe = $GLOBALS['TSFE'] ?? null;
19-
if ($tsfe instanceof TypoScriptFrontendController && $tsfe->isINTincScript()) {
20-
foreach ((array) $tsfe->config['INTincScript'] as $key => $configuration) {
19+
$frontendTypoScript = $event->getRequest()->getAttribute('frontend.typoscript');
20+
if ($frontendTypoScript instanceof FrontendTypoScript) {
21+
$configArray = $frontendTypoScript->getConfigArray();
22+
if (isset($configArray['INTincScript']) && is_array($configArray['INTincScript'])) {
23+
foreach ($configArray['INTincScript'] as $key => $configuration) {
2124

22-
$cspGenerationOverride = (bool) $this->configurationService->get('cspGenerationOverride');
23-
if ($cspGenerationOverride && isset($configuration['target']) && $configuration['target'] === NonceValueSubstitution::class . '->substituteNonce') {
24-
continue;
25-
}
25+
$cspGenerationOverride = (bool) $this->configurationService->get('cspGenerationOverride');
26+
if ($cspGenerationOverride && isset($configuration['target']) && $configuration['target'] === NonceValueSubstitution::class . '->substituteNonce') {
27+
continue;
28+
}
2629

27-
$event->addExplanation(__CLASS__ . ':' . $key, 'The page has a INTincScript: ' . implode(', ', $this->getInformation($configuration)));
30+
$event->addExplanation(__CLASS__ . ':' . $key, 'The page has a INTincScript: ' . implode(', ', $this->getInformation($configuration)));
31+
}
2832
}
2933
}
3034
}

Classes/Cache/Listener/PageCacheableListener.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@
55
namespace SFC\Staticfilecache\Cache\Listener;
66

77
use SFC\Staticfilecache\Event\CacheRuleEvent;
8-
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
8+
use TYPO3\CMS\Frontend\Page\PageInformation;
99

1010
class PageCacheableListener
1111
{
1212
public function __invoke(CacheRuleEvent $event): void
1313
{
14-
if (!(($GLOBALS['TSFE'] ?? null) instanceof TypoScriptFrontendController)) {
14+
$pageInformation = $event->getRequest()->getAttribute('frontend.page.information');
15+
if (!$pageInformation instanceof PageInformation) {
1516
return;
1617
}
17-
$cache = (bool) ($GLOBALS['TSFE']->page['tx_staticfilecache_cache'] ?? true);
18+
19+
$cache = (bool) ($pageInformation->getPageRecord()['tx_staticfilecache_cache'] ?? true);
1820
if (!$cache) {
1921
$event->addExplanation(__CLASS__, 'static cache disabled on page');
2022
}

Classes/Cache/Listener/ValidDoktypeListener.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace SFC\Staticfilecache\Cache\Listener;
66

77
use SFC\Staticfilecache\Event\CacheRuleEvent;
8-
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
8+
use TYPO3\CMS\Frontend\Page\PageInformation;
99

1010
class ValidDoktypeListener
1111
{
@@ -14,9 +14,10 @@ class ValidDoktypeListener
1414
*/
1515
public function __invoke(CacheRuleEvent $event): void
1616
{
17-
$tsfe = $GLOBALS['TSFE'] ?? null;
18-
if (!($tsfe instanceof TypoScriptFrontendController) || !isset($GLOBALS['TSFE']->page)) {
19-
$event->addExplanation(__CLASS__, 'There is no valid page in the frontendController object');
17+
18+
$pageInformation = $event->getRequest()->getAttribute('frontend.page.information');
19+
if (!$pageInformation instanceof PageInformation) {
20+
$event->addExplanation(__CLASS__, 'There is no valid page in the frontend.page.information');
2021
$event->setSkipProcessing(true);
2122

2223
return;
@@ -28,7 +29,7 @@ public function __invoke(CacheRuleEvent $event): void
2829
255, // DOKTYPE_RECYCLER,
2930
];
3031

31-
$currentType = (int) ($GLOBALS['TSFE']->page['doktype'] ?? 1);
32+
$currentType = (int) ($pageInformation->getPageRecord()['doktype'] ?? 1);
3233
if (\in_array($currentType, $ignoreTypes, true)) {
3334

3435
$event->addExplanation(__CLASS__, 'The Page doktype ' . $currentType . ' is one of the following not allowed numbers: ' . implode(

Classes/Cache/Listener/ValidPageInformationListener.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace SFC\Staticfilecache\Cache\Listener;
66

77
use SFC\Staticfilecache\Event\CacheRuleEvent;
8-
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
8+
use TYPO3\CMS\Frontend\Page\PageInformation;
99

1010
/**
1111
* ValidPageInformation.
@@ -19,10 +19,10 @@ class ValidPageInformationListener
1919
*/
2020
public function __invoke(CacheRuleEvent $event): void
2121
{
22-
$tsfe = $GLOBALS['TSFE'] ?? null;
23-
if (!$tsfe instanceof TypoScriptFrontendController || !\is_array($tsfe->page) || !$tsfe->page['uid']) {
22+
$pageInformation = $event->getRequest()->getAttribute('frontend.page.information');
23+
if (!$pageInformation instanceof PageInformation) {
2424
$event->setSkipProcessing(true);
25-
$event->addExplanation(__CLASS__, 'There is no valid page in the TSFE');
25+
$event->addExplanation(__CLASS__, 'There is no valid page information in the frontend.page.information');
2626
}
2727
}
2828
}

Classes/Cache/RemoteFileBackend.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ protected function getFileName(string $entryIdentifier): string
275275

276276
public function flushByTags(array $tags): void
277277
{
278-
// @todo check
278+
foreach ($tags as $tag) {
279+
$this->flushByTag($tag);
280+
}
279281
}
280282
}

Classes/Cache/StaticFileBackend.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use TYPO3\CMS\Core\Utility\GeneralUtility;
2525
use TYPO3\CMS\Core\Utility\PathUtility;
2626
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
27+
use TYPO3\CMS\Frontend\Page\PageInformation;
2728

2829
/**
2930
* Cache backend for StaticFileCache.
@@ -327,8 +328,10 @@ protected function getPriority(string $uri)
327328
$priority += (QueueService::PRIORITY_MEDIUM - \strlen($uri));
328329
}
329330

330-
if (($GLOBALS['TSFE'] ?? null) instanceof TypoScriptFrontendController) {
331-
$priority += (int) $GLOBALS['TSFE']->page['tx_staticfilecache_cache_priority'];
331+
// @todo
332+
$pageInformation = $GLOBALS['TYPO3_REQUEST']?->getAttribute('frontend.page.information');
333+
if ($pageInformation instanceof PageInformation) {
334+
$priority += (int) ($pageInformation->getPageRecord()['tx_staticfilecache_cache_priority'] ?? 0);
332335
}
333336

334337
return $priority;

Classes/Event/ForceStaticFileCacheEvent.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
namespace SFC\Staticfilecache\Event;
66

77
use Psr\Http\Message\ServerRequestInterface;
8-
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
98

109
final class ForceStaticFileCacheEvent
1110
{
1211
public function __construct(
1312
private bool $forceStatic,
14-
private ?TypoScriptFrontendController $frontendController,
1513
private ServerRequestInterface $request
1614
) {}
1715

@@ -25,16 +23,6 @@ public function setForceStatic(bool $forceStatic): void
2523
$this->forceStatic = $forceStatic;
2624
}
2725

28-
public function getFrontendController(): TypoScriptFrontendController
29-
{
30-
return $this->frontendController;
31-
}
32-
33-
public function setFrontendController(TypoScriptFrontendController $frontendController): void
34-
{
35-
$this->frontendController = $frontendController;
36-
}
37-
3826
public function getRequest(): ServerRequestInterface
3927
{
4028
return $this->request;

0 commit comments

Comments
 (0)