From 117848c72a20b5bc0cecb0f93e0656744bdcce1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Lochm=C3=BCller?= Date: Sun, 6 Oct 2024 22:15:51 +0200 Subject: [PATCH] Migration from Rule structure to PSR-14 Event Listener --- .../EnableListener.php} | 16 +-- .../NoFakeFrontendListener.php} | 25 ++-- .../NoIntScriptsListener.php} | 13 +- .../Listener/NoLongPathSegmentListener.php | 33 +++++ .../NoNoCacheListener.php} | 10 +- .../NoUserOrGroupSetListener.php} | 12 +- .../NoWorkspacePreviewListener.php} | 12 +- .../SiteCacheableListener.php} | 14 +- .../ValidDoktypeListener.php} | 23 ++- .../ValidPageInformationListener.php} | 11 +- Classes/Cache/Rule/AbstractRule.php | 19 --- Classes/Cache/Rule/NoLongPathSegment.php | 32 ----- Classes/Cache/StaticFileBackend.php | 27 ++-- Classes/Command/BoostQueueCommand.php | 23 ++- Classes/Configuration.php | 46 ------ Classes/Domain/Repository/PageRepository.php | 8 +- Classes/Domain/Repository/QueueRepository.php | 21 ++- Classes/Middleware/GenerateMiddleware.php | 3 - Classes/Middleware/PrepareMiddleware.php | 13 +- Classes/Service/DateTimeService.php | 2 - .../Service/HtaccessConfigurationService.php | 2 - Classes/Service/HttpPush/FontHttpPush.php | 4 - .../InlineAssets/AbstractInlineAssets.php | 2 +- Classes/Service/ObjectFactoryService.php | 31 ---- Configuration/Services.yaml | 133 +++++++++++++----- Tests/Unit/Cache/Rule/AbstractRuleTest.php | 12 -- Tests/Unit/Cache/Rule/NoFakeFrontendTest.php | 28 ---- 27 files changed, 234 insertions(+), 341 deletions(-) rename Classes/Cache/{Rule/Enable.php => Listener/EnableListener.php} (55%) rename Classes/Cache/{Rule/NoFakeFrontend.php => Listener/NoFakeFrontendListener.php} (58%) rename Classes/Cache/{Rule/NoIntScripts.php => Listener/NoIntScriptsListener.php} (70%) create mode 100644 Classes/Cache/Listener/NoLongPathSegmentListener.php rename Classes/Cache/{Rule/NoNoCache.php => Listener/NoNoCacheListener.php} (53%) rename Classes/Cache/{Rule/NoUserOrGroupSet.php => Listener/NoUserOrGroupSetListener.php} (80%) rename Classes/Cache/{Rule/NoWorkspacePreview.php => Listener/NoWorkspacePreviewListener.php} (54%) rename Classes/Cache/{Rule/SiteCacheable.php => Listener/SiteCacheableListener.php} (50%) rename Classes/Cache/{Rule/ValidDoktype.php => Listener/ValidDoktypeListener.php} (53%) rename Classes/Cache/{Rule/ValidPageInformation.php => Listener/ValidPageInformationListener.php} (59%) delete mode 100644 Classes/Cache/Rule/AbstractRule.php delete mode 100644 Classes/Cache/Rule/NoLongPathSegment.php delete mode 100644 Classes/Service/ObjectFactoryService.php delete mode 100644 Tests/Unit/Cache/Rule/AbstractRuleTest.php delete mode 100755 Tests/Unit/Cache/Rule/NoFakeFrontendTest.php diff --git a/Classes/Cache/Rule/Enable.php b/Classes/Cache/Listener/EnableListener.php similarity index 55% rename from Classes/Cache/Rule/Enable.php rename to Classes/Cache/Listener/EnableListener.php index 03d1fc74ab7..ed7314b30c6 100644 --- a/Classes/Cache/Rule/Enable.php +++ b/Classes/Cache/Listener/EnableListener.php @@ -2,26 +2,22 @@ declare(strict_types=1); -namespace SFC\Staticfilecache\Cache\Rule; +namespace SFC\Staticfilecache\Cache\Listener; use Psr\Http\Message\ServerRequestInterface; +use SFC\Staticfilecache\Event\CacheRuleEvent; use SFC\Staticfilecache\Service\ConfigurationService; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; -/** - * Enable. - */ -class Enable extends AbstractRule +class EnableListener { - /** - * Enable. - */ - public function checkRule(ServerRequestInterface $request, array &$explanation, bool &$skipProcessing): void + public function __invoke(CacheRuleEvent $event): void { /** @var ConfigurationService $configuration */ $configuration = GeneralUtility::makeInstance(ConfigurationService::class); if ($configuration->isBool('disableCache')) { - $explanation[__CLASS__] = 'static cache disabled by TypoScript'; + $event->addExplanation(__CLASS__, 'static cache disabled by TypoScript'); } } } diff --git a/Classes/Cache/Rule/NoFakeFrontend.php b/Classes/Cache/Listener/NoFakeFrontendListener.php similarity index 58% rename from Classes/Cache/Rule/NoFakeFrontend.php rename to Classes/Cache/Listener/NoFakeFrontendListener.php index 4808b072db3..6805edf54a3 100644 --- a/Classes/Cache/Rule/NoFakeFrontend.php +++ b/Classes/Cache/Listener/NoFakeFrontendListener.php @@ -2,19 +2,13 @@ declare(strict_types=1); -namespace SFC\Staticfilecache\Cache\Rule; +namespace SFC\Staticfilecache\Cache\Listener; -use Psr\Http\Message\ServerRequestInterface; +use SFC\Staticfilecache\Event\CacheRuleEvent; -/** - * No fake frontend. - */ -class NoFakeFrontend extends AbstractRule +class NoFakeFrontendListener { - /** - * No fake frontend. - */ - public function checkRule(ServerRequestInterface $request, array &$explanation, bool &$skipProcessing): void + public function __invoke(CacheRuleEvent $event): void { $ignorePaths = [ // Solr extension @@ -24,17 +18,16 @@ public function checkRule(ServerRequestInterface $request, array &$explanation, foreach ($ignorePaths as $ignorePath) { foreach ($this->getCallPaths() as $path) { if (str_ends_with($path, $ignorePath)) { - $skipProcessing = true; - $explanation[__CLASS__] = 'Fake frontend'; - + $event->setSkipProcessing(true); + $event->addExplanation(__CLASS__, 'Fake frontend'); return; } } } - if ($request->hasHeader('x-yoast-page-request')) { - $skipProcessing = true; - $explanation[__CLASS__] = 'Yoast SEO page request'; + if ($event->getRequest()->hasHeader('x-yoast-page-request')) { + $event->setSkipProcessing(true); + $event->addExplanation(__CLASS__, 'Yoast SEO page request'); } } diff --git a/Classes/Cache/Rule/NoIntScripts.php b/Classes/Cache/Listener/NoIntScriptsListener.php similarity index 70% rename from Classes/Cache/Rule/NoIntScripts.php rename to Classes/Cache/Listener/NoIntScriptsListener.php index d50282e0b36..9725af24a2d 100644 --- a/Classes/Cache/Rule/NoIntScripts.php +++ b/Classes/Cache/Listener/NoIntScriptsListener.php @@ -2,25 +2,22 @@ declare(strict_types=1); -namespace SFC\Staticfilecache\Cache\Rule; +namespace SFC\Staticfilecache\Cache\Listener; -use Psr\Http\Message\ServerRequestInterface; +use SFC\Staticfilecache\Event\CacheRuleEvent; use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; /** * No _INT scripts. */ -class NoIntScripts extends AbstractRule +class NoIntScriptsListener { - /** - * Check if there are no _INT scripts. - */ - public function checkRule(ServerRequestInterface $request, array &$explanation, bool &$skipProcessing): void + public function __invoke(CacheRuleEvent $event): void { $tsfe = $GLOBALS['TSFE'] ?? null; if ($tsfe instanceof TypoScriptFrontendController && $tsfe->isINTincScript()) { foreach ((array) $tsfe->config['INTincScript'] as $key => $configuration) { - $explanation[__CLASS__ . ':' . $key] = 'The page has a INTincScript: ' . implode(', ', $this->getInformation($configuration)); + $event->addExplanation(__CLASS__ . ':' . $key, 'The page has a INTincScript: ' . implode(', ', $this->getInformation($configuration))); } } } diff --git a/Classes/Cache/Listener/NoLongPathSegmentListener.php b/Classes/Cache/Listener/NoLongPathSegmentListener.php new file mode 100644 index 00000000000..528083d6c77 --- /dev/null +++ b/Classes/Cache/Listener/NoLongPathSegmentListener.php @@ -0,0 +1,33 @@ +getRequest()->getUri(); + $path = (string) parse_url($uri, PHP_URL_PATH); + $segments = explode('/', $path); + + foreach ($segments as $segment) { + if (\strlen($segment) > 255) { + $event->addExplanation(__CLASS__, 'The URI seegment of the URI is to long to create a folder based on tthis segment: ' . $segment); + $event->setSkipProcessing(true); + + return; + } + } + + } +} diff --git a/Classes/Cache/Rule/NoNoCache.php b/Classes/Cache/Listener/NoNoCacheListener.php similarity index 53% rename from Classes/Cache/Rule/NoNoCache.php rename to Classes/Cache/Listener/NoNoCacheListener.php index 9665d526f0d..b4c47e677d9 100644 --- a/Classes/Cache/Rule/NoNoCache.php +++ b/Classes/Cache/Listener/NoNoCacheListener.php @@ -2,25 +2,25 @@ declare(strict_types=1); -namespace SFC\Staticfilecache\Cache\Rule; +namespace SFC\Staticfilecache\Cache\Listener; -use Psr\Http\Message\ServerRequestInterface; +use SFC\Staticfilecache\Event\CacheRuleEvent; use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; /** * No no_cache. */ -class NoNoCache extends AbstractRule +class NoNoCacheListener { /** * No no_cache. */ - public function checkRule(ServerRequestInterface $request, array &$explanation, bool &$skipProcessing): void + public function __invoke(CacheRuleEvent $event): void { $tsfe = $GLOBALS['TSFE'] ?? null; /* @phpstan-ignore-next-line */ if ($tsfe instanceof TypoScriptFrontendController && $tsfe->no_cache) { - $explanation[__CLASS__] = 'config.no_cache is true'; + $event->addExplanation(__CLASS__, 'config.no_cache is true'); } } } diff --git a/Classes/Cache/Rule/NoUserOrGroupSet.php b/Classes/Cache/Listener/NoUserOrGroupSetListener.php similarity index 80% rename from Classes/Cache/Rule/NoUserOrGroupSet.php rename to Classes/Cache/Listener/NoUserOrGroupSetListener.php index 5e27076280a..7ca3d3fbc4d 100644 --- a/Classes/Cache/Rule/NoUserOrGroupSet.php +++ b/Classes/Cache/Listener/NoUserOrGroupSetListener.php @@ -2,26 +2,24 @@ declare(strict_types=1); -namespace SFC\Staticfilecache\Cache\Rule; +namespace SFC\Staticfilecache\Cache\Listener; use Psr\Http\Message\ServerRequestInterface; +use SFC\Staticfilecache\Event\CacheRuleEvent; use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; -/** - * NoUserOrGroupSet. - */ -class NoUserOrGroupSet extends AbstractRule +class NoUserOrGroupSetListener { /** * Check if no user or group is set. */ - public function checkRule(ServerRequestInterface $request, array &$explanation, bool &$skipProcessing): void + public function __invoke(CacheRuleEvent $event): void { if ($this->isUserOrGroupSet()) { - $explanation[__CLASS__] = 'User or group are set'; + $event->addExplanation(__CLASS__, 'User or group are set'); } } diff --git a/Classes/Cache/Rule/NoWorkspacePreview.php b/Classes/Cache/Listener/NoWorkspacePreviewListener.php similarity index 54% rename from Classes/Cache/Rule/NoWorkspacePreview.php rename to Classes/Cache/Listener/NoWorkspacePreviewListener.php index c1770d57dc8..88e179b6a50 100644 --- a/Classes/Cache/Rule/NoWorkspacePreview.php +++ b/Classes/Cache/Listener/NoWorkspacePreviewListener.php @@ -2,15 +2,13 @@ declare(strict_types=1); -namespace SFC\Staticfilecache\Cache\Rule; +namespace SFC\Staticfilecache\Cache\Listener; use Psr\Http\Message\ServerRequestInterface; +use SFC\Staticfilecache\Event\CacheRuleEvent; use TYPO3\CMS\Core\Context\Context; -/** - * No workspace preview. - */ -class NoWorkspacePreview extends AbstractRule +class NoWorkspacePreviewListener { public function __construct( private readonly Context $context, @@ -19,10 +17,10 @@ public function __construct( /** * Check if it is no workspace preview. */ - public function checkRule(ServerRequestInterface $request, array &$explanation, bool &$skipProcessing): void + public function __invoke(CacheRuleEvent $event): void { if ($this->context->getPropertyFromAspect('workspace', 'isOffline', false)) { - $explanation[__CLASS__] = 'The page is in workspace preview mode'; + $event->addExplanation(__CLASS__, 'The page is in workspace preview mode'); } } } diff --git a/Classes/Cache/Rule/SiteCacheable.php b/Classes/Cache/Listener/SiteCacheableListener.php similarity index 50% rename from Classes/Cache/Rule/SiteCacheable.php rename to Classes/Cache/Listener/SiteCacheableListener.php index 17a4c71dfb2..6b421c50142 100644 --- a/Classes/Cache/Rule/SiteCacheable.php +++ b/Classes/Cache/Listener/SiteCacheableListener.php @@ -2,28 +2,26 @@ declare(strict_types=1); -namespace SFC\Staticfilecache\Cache\Rule; +namespace SFC\Staticfilecache\Cache\Listener; use Psr\Http\Message\ServerRequestInterface; +use SFC\Staticfilecache\Event\CacheRuleEvent; use TYPO3\CMS\Core\Site\Entity\Site; -/** - * Check if the current site is static cacheable. - */ -class SiteCacheable extends AbstractRule +class SiteCacheableListener { /** * Check if the current site is static cacheable. */ - public function checkRule(ServerRequestInterface $request, array &$explanation, bool &$skipProcessing): void + public function __invoke(CacheRuleEvent $event): void { - $site = $request->getAttribute('site'); + $site = $event->getRequest()->getAttribute('site'); if (!($site instanceof Site)) { return; } $config = $site->getConfiguration(); if (isset($config['disableStaticFileCache']) && $config['disableStaticFileCache']) { - $explanation[__CLASS__] = 'static cache disabled on site configuration: ' . $site->getIdentifier(); + $event->addExplanation(__CLASS__, 'static cache disabled on site configuration: ' . $site->getIdentifier()); } } } diff --git a/Classes/Cache/Rule/ValidDoktype.php b/Classes/Cache/Listener/ValidDoktypeListener.php similarity index 53% rename from Classes/Cache/Rule/ValidDoktype.php rename to Classes/Cache/Listener/ValidDoktypeListener.php index 28afd29919a..97f0f402002 100644 --- a/Classes/Cache/Rule/ValidDoktype.php +++ b/Classes/Cache/Listener/ValidDoktypeListener.php @@ -2,25 +2,23 @@ declare(strict_types=1); -namespace SFC\Staticfilecache\Cache\Rule; +namespace SFC\Staticfilecache\Cache\Listener; use Psr\Http\Message\ServerRequestInterface; +use SFC\Staticfilecache\Event\CacheRuleEvent; use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; -/** - * Check if the doktype is valid. - */ -class ValidDoktype extends AbstractRule +class ValidDoktypeListener { /** - * Check if the URI is valid. + * Check if the doktype is valid. */ - public function checkRule(ServerRequestInterface $request, array &$explanation, bool &$skipProcessing): void + public function __invoke(CacheRuleEvent $event): void { $tsfe = $GLOBALS['TSFE'] ?? null; if (!($tsfe instanceof TypoScriptFrontendController) || !isset($GLOBALS['TSFE']->page)) { - $explanation[__CLASS__] = 'There is no valid page in the frontendController object'; - $skipProcessing = true; + $event->addExplanation(__CLASS__, 'There is no valid page in the frontendController object'); + $event->setSkipProcessing(true); return; } @@ -33,11 +31,12 @@ public function checkRule(ServerRequestInterface $request, array &$explanation, $currentType = (int) ($GLOBALS['TSFE']->page['doktype'] ?? 1); if (\in_array($currentType, $ignoreTypes, true)) { - $explanation[__CLASS__] = 'The Page doktype ' . $currentType . ' is one of the following not allowed numbers: ' . implode( + + $event->addExplanation(__CLASS__, 'The Page doktype ' . $currentType . ' is one of the following not allowed numbers: ' . implode( ', ', $ignoreTypes - ); - $skipProcessing = true; + )); + $event->setSkipProcessing(true); } } } diff --git a/Classes/Cache/Rule/ValidPageInformation.php b/Classes/Cache/Listener/ValidPageInformationListener.php similarity index 59% rename from Classes/Cache/Rule/ValidPageInformation.php rename to Classes/Cache/Listener/ValidPageInformationListener.php index 483996ca898..054e20d2f98 100644 --- a/Classes/Cache/Rule/ValidPageInformation.php +++ b/Classes/Cache/Listener/ValidPageInformationListener.php @@ -2,9 +2,10 @@ declare(strict_types=1); -namespace SFC\Staticfilecache\Cache\Rule; +namespace SFC\Staticfilecache\Cache\Listener; use Psr\Http\Message\ServerRequestInterface; +use SFC\Staticfilecache\Event\CacheRuleEvent; use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; /** @@ -12,17 +13,17 @@ * * @see https://github.com/lochmueller/staticfilecache/issues/150 */ -class ValidPageInformation extends AbstractRule +class ValidPageInformationListener { /** * ValidPageInformation. */ - public function checkRule(ServerRequestInterface $request, array &$explanation, bool &$skipProcessing): void + public function __invoke(CacheRuleEvent $event): void { $tsfe = $GLOBALS['TSFE'] ?? null; if (!$tsfe instanceof TypoScriptFrontendController || !\is_array($tsfe->page) || !$tsfe->page['uid']) { - $skipProcessing = true; - $explanation[__CLASS__] = 'There is no valid page in the TSFE'; + $event->setSkipProcessing(true); + $event->addExplanation(__CLASS__, 'There is no valid page in the TSFE'); } } } diff --git a/Classes/Cache/Rule/AbstractRule.php b/Classes/Cache/Rule/AbstractRule.php deleted file mode 100644 index 479c3e8e1e4..00000000000 --- a/Classes/Cache/Rule/AbstractRule.php +++ /dev/null @@ -1,19 +0,0 @@ -getUri(); - $path = (string) parse_url($uri, PHP_URL_PATH); - $segments = explode('/', $path); - - foreach ($segments as $segment) { - if (\strlen($segment) > 255) { - $explanation[__CLASS__] = 'The URI seegment of the URI is to long to create a folder based on tthis segment: ' . $segment; - $skipProcessing = true; - - return; - } - } - } -} diff --git a/Classes/Cache/StaticFileBackend.php b/Classes/Cache/StaticFileBackend.php index 30c583b2347..86c798d8bc3 100644 --- a/Classes/Cache/StaticFileBackend.php +++ b/Classes/Cache/StaticFileBackend.php @@ -33,13 +33,21 @@ */ class StaticFileBackend extends StaticDatabaseBackend implements TransientBackendInterface { + protected GeneratorService $generatorService; + + public function __construct($context, array $options = []) + { + $this->generatorService = GeneralUtility::makeInstance(GeneratorService::class); + parent::__construct($context, $options); + } + /** * Saves data in the cache. * - * @param string $entryIdentifier An identifier for this specific cache entry - * @param ResponseInterface $data The data to be stored - * @param array $tags Tags to associate with this cache entry - * @param int $lifetime Lifetime of this cache entry in seconds + * @param string $entryIdentifier An identifier for this specific cache entry + * @param ResponseInterface $data The data to be stored + * @param array $tags Tags to associate with this cache entry + * @param int $lifetime Lifetime of this cache entry in seconds * * @throws \TYPO3\CMS\Core\Cache\Exception if no cache frontend has been set * @throws InvalidDataException if the data is not a string @@ -88,7 +96,7 @@ public function set($entryIdentifier, $data, array $tags = [], $lifetime = null) $this->removeStaticFiles($entryIdentifier); - GeneralUtility::makeInstance(GeneratorService::class)->generate($entryIdentifier, $fileName, $data, $realLifetime); + $this->generatorService->generate($entryIdentifier, $fileName, $data, $realLifetime); } catch (\Exception $exception) { $this->logger->error('Error in cache create process', ['exception' => $exception]); } @@ -145,8 +153,7 @@ public function remove($entryIdentifier) if ($this->isBoostMode()) { $this->getQueue() - ->addIdentifier($entryIdentifier) - ; + ->addIdentifier($entryIdentifier); return true; } @@ -331,7 +338,9 @@ protected function findIdentifiersByTagIncludingExpired($tag): array */ protected function findIdentifiersByTagsIncludingExpired(array $tags): array { - $base = (new DateTimeService())->getCurrentTime(); + + // @todo check + // $base = GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('date', 'timestamp') // Use EXEC_TIME because the core still use EXEC_TIME for checking the time $base = $GLOBALS['EXEC_TIME']; @@ -383,7 +392,7 @@ public function findIdentifiersByTags(array $tags) protected function removeStaticFiles(string $entryIdentifier): bool { $fileName = $this->getFilepath($entryIdentifier); - GeneralUtility::makeInstance(GeneratorService::class)->remove($entryIdentifier, $fileName); + $this->generatorService->remove($entryIdentifier, $fileName); return true; } diff --git a/Classes/Command/BoostQueueCommand.php b/Classes/Command/BoostQueueCommand.php index 4a478d5971d..8a2043a871d 100644 --- a/Classes/Command/BoostQueueCommand.php +++ b/Classes/Command/BoostQueueCommand.php @@ -36,10 +36,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int $stopProcessingAfter = (int) $input->getOption('stop-processing-after'); $limit = (int) $input->getOption('limit-items'); $limit = $limit > 0 ? $limit : 5000; - $rows = $this->queueRepository->findOpen($limit); - $io->progressStart(\count($rows)); - foreach ($rows as $runEntry) { + $count = 0; + foreach ($this->queueRepository->findOpen($limit) as $runEntry) { if ($stopProcessingAfter > 0 && time() >= $startTime + $stopProcessingAfter) { $io->note('Skip after "stopProcessingAfter" time.'); @@ -47,11 +46,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int } $this->queueService->runSingleRequest($runEntry); - $io->progressAdvance(); + $count++; } - $io->progressFinish(); - $io->success(\count($rows) . ' items are done (perhaps not all are processed).'); + $io->success($count . ' items are done (perhaps not all are processed).'); if (!(bool) $input->getOption('avoid-cleanup')) { $this->cleanupQueue($io); @@ -63,14 +61,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int protected function cleanupQueue(SymfonyStyle $io): void { - $uids = $this->queueRepository->findOldUids(); - $io->progressStart(\count($uids)); - foreach ($uids as $uid) { - $this->queueRepository->delete(['uid' => $uid]); - $io->progressAdvance(); + $count = 0; + foreach ($this->queueRepository->findOldUids() as $row) { + $this->queueRepository->delete(['uid' => $row['uid']]); + $count++; } - $io->progressFinish(); - - $io->success(\count($uids) . ' items are removed.'); + $io->success($count . ' items are removed.'); } } diff --git a/Classes/Configuration.php b/Classes/Configuration.php index 85f7ec7a2ce..c1394adf6ad 100644 --- a/Classes/Configuration.php +++ b/Classes/Configuration.php @@ -7,38 +7,14 @@ use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationExtensionNotConfiguredException; use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationPathDoesNotExistException; use SFC\Staticfilecache\Cache\RemoteFileBackend; -use SFC\Staticfilecache\Cache\Rule\Enable; -use SFC\Staticfilecache\Cache\Rule\NoFakeFrontend; -use SFC\Staticfilecache\Cache\Rule\NoIntScripts; -use SFC\Staticfilecache\Cache\Rule\NoLongPathSegment; -use SFC\Staticfilecache\Cache\Rule\NoNoCache; -use SFC\Staticfilecache\Cache\Rule\NoUserOrGroupSet; -use SFC\Staticfilecache\Cache\Rule\NoWorkspacePreview; -use SFC\Staticfilecache\Cache\Rule\SiteCacheable; -use SFC\Staticfilecache\Cache\Rule\ValidDoktype; -use SFC\Staticfilecache\Cache\Rule\ValidPageInformation; use SFC\Staticfilecache\Cache\StaticFileBackend; use SFC\Staticfilecache\Cache\UriFrontend; -use SFC\Staticfilecache\Controller\BackendController; -use SFC\Staticfilecache\Generator\BrotliGenerator; -use SFC\Staticfilecache\Generator\ConfigGenerator; -use SFC\Staticfilecache\Generator\GzipGenerator; -use SFC\Staticfilecache\Generator\HtaccessGenerator; -use SFC\Staticfilecache\Generator\PhpGenerator; -use SFC\Staticfilecache\Generator\PlainGenerator; use SFC\Staticfilecache\Hook\DatamapHook; use SFC\Staticfilecache\Service\ConfigurationService; -use SFC\Staticfilecache\Service\HttpPush\FontHttpPush; -use SFC\Staticfilecache\Service\HttpPush\ImageHttpPush; -use SFC\Staticfilecache\Service\HttpPush\ScriptHttpPush; -use SFC\Staticfilecache\Service\HttpPush\StyleHttpPush; -use SFC\Staticfilecache\Service\HttpPush\SvgHttpPush; -use SFC\Staticfilecache\Service\ObjectFactoryService; use TYPO3\CMS\Core\Cache\Backend\NullBackend; use TYPO3\CMS\Core\Core\Environment; use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Extbase\Utility\ExtensionUtility; class Configuration implements SingletonInterface { @@ -63,7 +39,6 @@ public function __construct() public function extLocalconf(): void { $this->registerHooks() - ->registerRules() ->registerCachingFramework() ->adjustSystemSettings() ; @@ -79,27 +54,6 @@ protected function registerHooks(): self return $this; } - /** - * Register rules. - */ - protected function registerRules(): self - { - GeneralUtility::makeInstance(ObjectFactoryService::class)->set('CacheRule', [ - 'siteCacheable' => SiteCacheable::class, - 'validDoktype' => ValidDoktype::class, - 'noWorkspacePreview' => NoWorkspacePreview::class, - 'noUserOrGroupSet' => NoUserOrGroupSet::class, - 'noIntScripts' => NoIntScripts::class, - 'noNoCache' => NoNoCache::class, - 'enable' => Enable::class, - 'validPageInformation' => ValidPageInformation::class, - 'noFakeFrontend' => NoFakeFrontend::class, - 'noLongPathSegment' => NoLongPathSegment::class, - ]); - - return $this; - } - /** * Register caching framework. */ diff --git a/Classes/Domain/Repository/PageRepository.php b/Classes/Domain/Repository/PageRepository.php index 451fcd94fb1..69c073d923e 100644 --- a/Classes/Domain/Repository/PageRepository.php +++ b/Classes/Domain/Repository/PageRepository.php @@ -11,9 +11,9 @@ class PageRepository extends AbstractRepository * * @param int $pageId * @param string $displayMode - * @todo move methods to iterator? + * @return iterable */ - public function findForBackend($pageId, $displayMode): array + public function findForBackend($pageId, $displayMode): iterable { $queryBuilder = $this->createQuery(); @@ -38,11 +38,11 @@ public function findForBackend($pageId, $displayMode): array break; } - return (array) $queryBuilder->select('*') + yield from $queryBuilder->select('*') ->from('pages') ->orWhere(...$where) ->executeQuery() - ->fetchAllAssociative() + ->iterateAssociative() ; } diff --git a/Classes/Domain/Repository/QueueRepository.php b/Classes/Domain/Repository/QueueRepository.php index a7d9a73f758..0722aba2d9e 100644 --- a/Classes/Domain/Repository/QueueRepository.php +++ b/Classes/Domain/Repository/QueueRepository.php @@ -8,27 +8,24 @@ class QueueRepository extends AbstractRepository { /** * Find the entries for the worker. - * - * @todo move methods to iterator? + * @return iterable */ - public function findOpen($limit = 999): array + public function findOpen($limit = 999): iterable { $queryBuilder = $this->createQuery(); - return (array) $queryBuilder->select('*') + yield from $queryBuilder->select('*') ->from($this->getTableName()) ->where($queryBuilder->expr()->eq('call_date', 0)) ->setMaxResults($limit) ->orderBy('cache_priority', 'desc') ->executeQuery() - ->fetchAllAssociative() + ->iterateAssociative() ; } /** * Find open by identifier. - * - * @todo move methods to iterator? */ public function countOpenByIdentifier($identifier): int { @@ -48,19 +45,17 @@ public function countOpenByIdentifier($identifier): int /** * Find old entries. - * @return list - * - * @todo move methods to iterator? + * @return iterable */ - public function findOldUids(): array + public function findOldUids(): iterable { $queryBuilder = $this->createQuery(); - return $queryBuilder->select('uid') + yield from $queryBuilder->select('uid') ->from($this->getTableName()) ->where($queryBuilder->expr()->gt('call_date', 0)) ->executeQuery() - ->fetchFirstColumn() + ->iterateAssociative() ; } diff --git a/Classes/Middleware/GenerateMiddleware.php b/Classes/Middleware/GenerateMiddleware.php index e3227437489..bfe2cbb8221 100644 --- a/Classes/Middleware/GenerateMiddleware.php +++ b/Classes/Middleware/GenerateMiddleware.php @@ -91,9 +91,6 @@ protected function calculateLifetime(TypoScriptFrontendController $tsfe): int return 0; } - // @todo migrate for v13 to Events - // Check ModifyCacheLifetimeForPageEvent & AfterCachedPageIsPersistedEvent - if ($this->typo3Version->getMajorVersion() >= 13) { /* @phpstan-ignore-next-line */ $timeOutTime = $tsfe->get_cache_timeout($this->request); diff --git a/Classes/Middleware/PrepareMiddleware.php b/Classes/Middleware/PrepareMiddleware.php index 904ae6b3662..89599c9f34a 100644 --- a/Classes/Middleware/PrepareMiddleware.php +++ b/Classes/Middleware/PrepareMiddleware.php @@ -10,18 +10,19 @@ use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; -use SFC\Staticfilecache\Cache\Rule\AbstractRule; use SFC\Staticfilecache\Event\CacheRuleEvent; use SFC\Staticfilecache\Service\ConfigurationService; use SFC\Staticfilecache\Service\HttpPushService; use SFC\Staticfilecache\Service\InlineAssetsService; -use SFC\Staticfilecache\Service\ObjectFactoryService; use SFC\Staticfilecache\Service\TypoScriptFrontendService; use TYPO3\CMS\Core\Utility\GeneralUtility; class PrepareMiddleware implements MiddlewareInterface { - public function __construct(protected EventDispatcherInterface $eventDispatcher) {} + public function __construct( + protected EventDispatcherInterface $eventDispatcher, + protected HttpPushService $httpPushService + ) {} /** * Process an incoming server request. @@ -36,10 +37,6 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface $explanation = []; $skipProcessing = false; - foreach (GeneralUtility::makeInstance(ObjectFactoryService::class)->get('CacheRule') as $rule) { - // @var $rule AbstractRule - $rule->checkRule($request, $explanation, $skipProcessing); - } $event = new CacheRuleEvent($request, $explanation, $skipProcessing); $this->eventDispatcher->dispatch($event); @@ -71,7 +68,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface $responseBody->write($processedHtml); $response = $response->withBody($responseBody); - $pushHeaders = (array) GeneralUtility::makeInstance(HttpPushService::class)->getHttpPushHeaders((string) $response->getBody()); + $pushHeaders = (array) $this->httpPushService->getHttpPushHeaders((string) $response->getBody()); foreach ($pushHeaders as $pushHeader) { $response = $response->withAddedHeader('Link', '<' . $pushHeader['path'] . '>; rel=preload; as=' . $pushHeader['type']); } diff --git a/Classes/Service/DateTimeService.php b/Classes/Service/DateTimeService.php index 5296fc8243f..5e16c92b8be 100644 --- a/Classes/Service/DateTimeService.php +++ b/Classes/Service/DateTimeService.php @@ -12,8 +12,6 @@ class DateTimeService /** * Get current time * Same time for the complete request. - * - * @todo remove and replace with context API */ public function getCurrentTime(): int { diff --git a/Classes/Service/HtaccessConfigurationService.php b/Classes/Service/HtaccessConfigurationService.php index 105214aec19..b461e675f3a 100644 --- a/Classes/Service/HtaccessConfigurationService.php +++ b/Classes/Service/HtaccessConfigurationService.php @@ -28,8 +28,6 @@ public function foundConfigurationInHtaccess(): bool /** * Get all relevant htaccess paths. - * - * @todo check if we add another path, if typo3-secure-web is installed?! */ public function getHtaccessPaths(): array { diff --git a/Classes/Service/HttpPush/FontHttpPush.php b/Classes/Service/HttpPush/FontHttpPush.php index cce350ccfb7..4ec904d3845 100644 --- a/Classes/Service/HttpPush/FontHttpPush.php +++ b/Classes/Service/HttpPush/FontHttpPush.php @@ -4,10 +4,6 @@ namespace SFC\Staticfilecache\Service\HttpPush; -use SFC\Staticfilecache\Event\HttpPushHeaderEvent; -use SFC\Staticfilecache\Service\ObjectFactoryService; -use TYPO3\CMS\Core\Utility\GeneralUtility; - class FontHttpPush extends AbstractHttpPush { /** diff --git a/Classes/Service/InlineAssets/AbstractInlineAssets.php b/Classes/Service/InlineAssets/AbstractInlineAssets.php index ff5e9b3b5dc..1a561eeac91 100644 --- a/Classes/Service/InlineAssets/AbstractInlineAssets.php +++ b/Classes/Service/InlineAssets/AbstractInlineAssets.php @@ -58,7 +58,7 @@ protected function parseAsset(array $match): string } switch ($match['ext']) { - case 'svg':// TODO ; https://github.com/peteboere/css-crush/commit/7cd5d73f67212dfc7ec0f85e4a84932a32ce95d8 + case 'svg': $type = 'image/svg+xml;utf8'; $file = str_replace('"', '\'', $file); // change quotes $file = preg_replace('/#(?=[a-f0-9]{3,6})/', '%23', $file); // adapt hex-color diff --git a/Classes/Service/ObjectFactoryService.php b/Classes/Service/ObjectFactoryService.php deleted file mode 100644 index be6653905a1..00000000000 --- a/Classes/Service/ObjectFactoryService.php +++ /dev/null @@ -1,31 +0,0 @@ -checkRule($request, $explanation, $skipProcessing); - static::assertFalse($skipProcessing); - } -}