From ebd3f4062a6729c4bbb3554dea9485843b7148b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Lochm=C3=BCller?= Date: Sun, 29 Sep 2024 21:59:00 +0200 Subject: [PATCH] Migration of generators to events - Part I --- Classes/Cache/IdentifierBuilder.php | 6 +-- .../Cache/Listener/NoBackendUserListener.php | 5 +- .../Listener/StaticCacheableListener.php | 7 ++- Classes/Cache/RemoteFileBackend.php | 2 +- Classes/Cache/Rule/AbstractRule.php | 3 +- Classes/Configuration.php | 33 +----------- .../Domain/Repository/AbstractRepository.php | 3 +- Classes/Event/GeneratorCreate.php | 30 ++++++++++- Classes/Event/GeneratorRemove.php | 19 ++++++- Classes/Generator/AbstractGenerator.php | 18 ++++--- Classes/Generator/BrotliGenerator.php | 16 ++++-- Classes/Generator/ConfigGenerator.php | 12 +++-- Classes/Generator/GzipGenerator.php | 20 +++++-- Classes/Generator/HtaccessGenerator.php | 14 ++--- Classes/Generator/PhpGenerator.php | 23 +++++--- Classes/Generator/PlainGenerator.php | 21 +++++--- Classes/Hook/AbstractHook.php | 12 ----- Classes/Hook/DatamapHook.php | 7 +-- Classes/Service/AbstractService.php | 7 +-- Classes/Service/GeneratorService.php | 25 ++++----- Classes/StaticFileCacheObject.php | 18 ------- Configuration/Services.yaml | 54 +++++++++++++++++++ 22 files changed, 209 insertions(+), 146 deletions(-) delete mode 100644 Classes/Hook/AbstractHook.php delete mode 100644 Classes/StaticFileCacheObject.php diff --git a/Classes/Cache/IdentifierBuilder.php b/Classes/Cache/IdentifierBuilder.php index 5a300fb9ec0..2262eaece38 100644 --- a/Classes/Cache/IdentifierBuilder.php +++ b/Classes/Cache/IdentifierBuilder.php @@ -7,13 +7,9 @@ use SFC\Staticfilecache\Exception; use SFC\Staticfilecache\Service\CacheService; use SFC\Staticfilecache\Service\ConfigurationService; -use SFC\Staticfilecache\StaticFileCacheObject; use TYPO3\CMS\Core\Utility\GeneralUtility; -/** - * IdentifierBuilder. - */ -class IdentifierBuilder extends StaticFileCacheObject +class IdentifierBuilder { /** * Get the cache name for the given URI. diff --git a/Classes/Cache/Listener/NoBackendUserListener.php b/Classes/Cache/Listener/NoBackendUserListener.php index e3b47f7f028..920d3514fa6 100644 --- a/Classes/Cache/Listener/NoBackendUserListener.php +++ b/Classes/Cache/Listener/NoBackendUserListener.php @@ -13,10 +13,11 @@ */ class NoBackendUserListener { + public function __construct(private readonly Context $context) {} + public function __invoke(CacheRuleEvent $event): void { - $context = GeneralUtility::makeInstance(Context::class); - if ($context->getPropertyFromAspect('backend.user', 'isLoggedIn', false)) { + if ($this->context->getPropertyFromAspect('backend.user', 'isLoggedIn', false)) { $event->addExplanation(__CLASS__, 'Active BE Login (TSFE:beUserLogin)'); $event->setSkipProcessing(true); } diff --git a/Classes/Cache/Listener/StaticCacheableListener.php b/Classes/Cache/Listener/StaticCacheableListener.php index 694890948e8..64336bc1fe9 100644 --- a/Classes/Cache/Listener/StaticCacheableListener.php +++ b/Classes/Cache/Listener/StaticCacheableListener.php @@ -5,6 +5,7 @@ namespace SFC\Staticfilecache\Cache\Listener; use SFC\Staticfilecache\Event\CacheRuleEvent; +use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Information\Typo3Version; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; @@ -14,6 +15,8 @@ */ class StaticCacheableListener { + public function __construct(private readonly Typo3Version $typo3Version) {} + /** * Check if the page is static cacheable. * @@ -23,14 +26,14 @@ class StaticCacheableListener public function __invoke(CacheRuleEvent $event): void { if (($GLOBALS['TSFE'] ?? null) instanceof TypoScriptFrontendController) { - if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() >= 13) { + if ($this->typo3Version->getMajorVersion() >= 13) { /* @phpstan-ignore-next-line */ $isStaticCacheble = $GLOBALS['TSFE']->isStaticCacheble($event->getRequest()); } else { /* @phpstan-ignore-next-line */ $isStaticCacheble = $GLOBALS['TSFE']->isStaticCacheble(); } - if(!$isStaticCacheble) { + if (!$isStaticCacheble) { $event->addExplanation(__CLASS__, 'The page is not static cacheable via TypoScriptFrontend. Check the first Question on: https://github.com/lochmueller/staticfilecache/blob/master/Documentation/Faq/Index.rst'); } } diff --git a/Classes/Cache/RemoteFileBackend.php b/Classes/Cache/RemoteFileBackend.php index a820dd2a1a2..ed798bc3b33 100644 --- a/Classes/Cache/RemoteFileBackend.php +++ b/Classes/Cache/RemoteFileBackend.php @@ -105,7 +105,7 @@ public function set($entryIdentifier, $data, array $tags = [], $lifetime = null) } GeneralUtility::writeFile($absoluteCacheDir . $fileName . self::FILE_EXTENSION_TAG, '|' . implode('|', $tags) . '|'); - GeneralUtility::writeFile($absoluteCacheDir . $fileName . self::FILE_EXTENSION_LIFETIME, (string)$this->calculateExpiryTime($lifetime)->getTimestamp()); + GeneralUtility::writeFile($absoluteCacheDir . $fileName . self::FILE_EXTENSION_LIFETIME, (string) $this->calculateExpiryTime($lifetime)->getTimestamp()); GeneralUtility::writeFile($absoluteCacheDir . $fileName . self::FILE_EXTENSION_IDENTIFIER, $entryIdentifier); } diff --git a/Classes/Cache/Rule/AbstractRule.php b/Classes/Cache/Rule/AbstractRule.php index 6cf4870f7cd..479c3e8e1e4 100644 --- a/Classes/Cache/Rule/AbstractRule.php +++ b/Classes/Cache/Rule/AbstractRule.php @@ -5,13 +5,12 @@ namespace SFC\Staticfilecache\Cache\Rule; use Psr\Http\Message\ServerRequestInterface; -use SFC\Staticfilecache\StaticFileCacheObject; /** * Abstract Rule. * @todo migrate to Listener */ -abstract class AbstractRule extends StaticFileCacheObject +abstract class AbstractRule { /** * Method to check the rule and modify $explanation and/or $skipProcessing. diff --git a/Classes/Configuration.php b/Classes/Configuration.php index 798692b0135..03de886b854 100644 --- a/Classes/Configuration.php +++ b/Classes/Configuration.php @@ -36,10 +36,11 @@ 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 extends StaticFileCacheObject +class Configuration implements SingletonInterface { public const EXTENSION_KEY = 'staticfilecache'; @@ -64,7 +65,6 @@ public function extLocalconf(): void $this->registerHooks() ->registerRules() ->registerCachingFramework() - ->registerGenerators() ->registerHttpPushServices() ->adjustSystemSettings() ; @@ -132,35 +132,6 @@ protected function registerCachingFramework(): self return $this; } - /** - * Register generator. - */ - protected function registerGenerators(): self - { - $generator = [ - 'config' => ConfigGenerator::class, - 'htaccess' => HtaccessGenerator::class, - ]; - - if ($this->configurationService->get('enableGeneratorPhp')) { - $generator['php'] = PhpGenerator::class; - unset($generator['htaccess']); - } - if ($this->configurationService->get('enableGeneratorPlain')) { - $generator['plain'] = PlainGenerator::class; - } - if ($this->configurationService->get('enableGeneratorGzip')) { - $generator['gzip'] = GzipGenerator::class; - } - if ($this->configurationService->get('enableGeneratorBrotli')) { - $generator['brotli'] = BrotliGenerator::class; - } - - GeneralUtility::makeInstance(ObjectFactoryService::class)->set('Generator', $generator); - - return $this; - } - /** * Register HTTP push services. */ diff --git a/Classes/Domain/Repository/AbstractRepository.php b/Classes/Domain/Repository/AbstractRepository.php index 9c7e01926dc..7f8fc3a9dc2 100644 --- a/Classes/Domain/Repository/AbstractRepository.php +++ b/Classes/Domain/Repository/AbstractRepository.php @@ -4,7 +4,6 @@ namespace SFC\Staticfilecache\Domain\Repository; -use SFC\Staticfilecache\StaticFileCacheObject; use TYPO3\CMS\Core\Database\Connection; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Database\Query\QueryBuilder; @@ -15,7 +14,7 @@ * * @todo move methods to iterator? */ -abstract class AbstractRepository extends StaticFileCacheObject +abstract class AbstractRepository { /** * Delete records. diff --git a/Classes/Event/GeneratorCreate.php b/Classes/Event/GeneratorCreate.php index 5dcf4a3daf9..4130ccd281e 100644 --- a/Classes/Event/GeneratorCreate.php +++ b/Classes/Event/GeneratorCreate.php @@ -4,8 +4,36 @@ namespace SFC\Staticfilecache\Event; +use Psr\Http\Message\ResponseInterface; + final class GeneratorCreate { - // @todo move Generator Service to Events + public function __construct( + readonly protected string $entryIdentifier, + readonly protected string $fileName, + readonly protected ResponseInterface $response, + readonly protected int $lifetime + ) {} + + public function getEntryIdentifier(): string + { + return $this->entryIdentifier; + } + + public function getFileName(): string + { + return $this->fileName; + } + + public function getResponse(): ResponseInterface + { + return $this->response; + } + + public function getLifetime(): int + { + return $this->lifetime; + } + } diff --git a/Classes/Event/GeneratorRemove.php b/Classes/Event/GeneratorRemove.php index 61e1077a539..1be83e227aa 100644 --- a/Classes/Event/GeneratorRemove.php +++ b/Classes/Event/GeneratorRemove.php @@ -4,8 +4,25 @@ namespace SFC\Staticfilecache\Event; +use Psr\Http\Message\ResponseInterface; + final class GeneratorRemove { - // @todo move Generator Service to Events + public function __construct( + readonly protected string $entryIdentifier, + readonly protected string $fileName, + ) {} + + public function getEntryIdentifier(): string + { + return $this->entryIdentifier; + } + + public function getFileName(): string + { + return $this->fileName; + } + + } diff --git a/Classes/Generator/AbstractGenerator.php b/Classes/Generator/AbstractGenerator.php index d9a83b71987..fe2931bfe15 100644 --- a/Classes/Generator/AbstractGenerator.php +++ b/Classes/Generator/AbstractGenerator.php @@ -5,19 +5,23 @@ namespace SFC\Staticfilecache\Generator; use Psr\Http\Message\ResponseInterface; +use SFC\Staticfilecache\Event\GeneratorCreate; +use SFC\Staticfilecache\Event\GeneratorRemove; +use SFC\Staticfilecache\Service\ConfigurationService; use SFC\Staticfilecache\Service\RemoveService; -use SFC\Staticfilecache\StaticFileCacheObject; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Fluid\View\StandaloneView; -/** - * @todo move to Generate Event - */ -abstract class AbstractGenerator extends StaticFileCacheObject +abstract class AbstractGenerator { - abstract public function generate(string $entryIdentifier, string $fileName, ResponseInterface $response, int $lifetime): void; + abstract public function generate(GeneratorCreate $generatorCreateEvent): void; - abstract public function remove(string $entryIdentifier, string $fileName): void; + abstract public function remove(GeneratorRemove $generatorRemoveEvent): void; + + protected function getConfigurationService(): ConfigurationService + { + return GeneralUtility::makeInstance(ConfigurationService::class); + } protected function writeFile(string $fileName, string $content): void { diff --git a/Classes/Generator/BrotliGenerator.php b/Classes/Generator/BrotliGenerator.php index 3ea48f64ef7..ba104be8c4c 100644 --- a/Classes/Generator/BrotliGenerator.php +++ b/Classes/Generator/BrotliGenerator.php @@ -5,28 +5,30 @@ namespace SFC\Staticfilecache\Generator; use Psr\Http\Message\ResponseInterface; +use SFC\Staticfilecache\Event\GeneratorCreate; +use SFC\Staticfilecache\Event\GeneratorRemove; use SFC\Staticfilecache\Service\RemoveService; use TYPO3\CMS\Core\Utility\GeneralUtility; class BrotliGenerator extends AbstractGenerator { - public function generate(string $entryIdentifier, string $fileName, ResponseInterface $response, int $lifetime): void + public function generate(GeneratorCreate $generatorCreateEvent): void { if (!$this->checkAvailable()) { return; } - $contentCompress = brotli_compress((string) $response->getBody()); + $contentCompress = brotli_compress((string) $generatorCreateEvent->getResponse()->getBody()); if ($contentCompress) { - $this->writeFile($fileName . '.br', $contentCompress); + $this->writeFile($generatorCreateEvent->getFileName() . '.br', $contentCompress); } } - public function remove(string $entryIdentifier, string $fileName): void + public function remove(GeneratorRemove $generatorRemoveEvent): void { if (!$this->checkAvailable()) { return; } - $this->removeFile($fileName . '.br'); + $this->removeFile($generatorRemoveEvent->getFileName() . '.br'); } /** @@ -34,6 +36,10 @@ public function remove(string $entryIdentifier, string $fileName): void */ protected function checkAvailable(): bool { + if (!$this->getConfigurationService()->get('enableGeneratorBrotli')) { + return false; + } + $available = \function_exists('brotli_compress'); if (!$available) { $this->logger->error('Your server do not support Botli compression, but you enable Brotli in EXT:staticfilecache configuration'); diff --git a/Classes/Generator/ConfigGenerator.php b/Classes/Generator/ConfigGenerator.php index 0a8ed55ee30..8fb694a7d20 100644 --- a/Classes/Generator/ConfigGenerator.php +++ b/Classes/Generator/ConfigGenerator.php @@ -5,24 +5,26 @@ namespace SFC\Staticfilecache\Generator; use Psr\Http\Message\ResponseInterface; +use SFC\Staticfilecache\Event\GeneratorCreate; +use SFC\Staticfilecache\Event\GeneratorRemove; use SFC\Staticfilecache\Service\ConfigurationService; use SFC\Staticfilecache\Service\RemoveService; use TYPO3\CMS\Core\Utility\GeneralUtility; class ConfigGenerator extends AbstractGenerator { - public function generate(string $entryIdentifier, string $fileName, ResponseInterface $response, int $lifetime): void + public function generate(GeneratorCreate $generatorCreateEvent): void { $config = [ 'generated' => date('r'), 'headers' => GeneralUtility::makeInstance(ConfigurationService::class) - ->getValidHeaders($response->getHeaders(), 'validFallbackHeaders'), + ->getValidHeaders($generatorCreateEvent->getResponse()->getHeaders(), 'validFallbackHeaders'), ]; - $this->writeFile($fileName . '.config.json', json_encode($config, JSON_PRETTY_PRINT)); + $this->writeFile($generatorCreateEvent->getFileName() . '.config.json', json_encode($config, JSON_PRETTY_PRINT)); } - public function remove(string $entryIdentifier, string $fileName): void + public function remove(GeneratorRemove $generatorRemoveEvent): void { - $this->removeFile($fileName . '.config.json'); + $this->removeFile($generatorRemoveEvent->getFileName() . '.config.json'); } } diff --git a/Classes/Generator/GzipGenerator.php b/Classes/Generator/GzipGenerator.php index fa36acb56dc..5bffb64987d 100644 --- a/Classes/Generator/GzipGenerator.php +++ b/Classes/Generator/GzipGenerator.php @@ -5,6 +5,8 @@ namespace SFC\Staticfilecache\Generator; use Psr\Http\Message\ResponseInterface; +use SFC\Staticfilecache\Event\GeneratorCreate; +use SFC\Staticfilecache\Event\GeneratorRemove; use SFC\Staticfilecache\Service\RemoveService; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\MathUtility; @@ -16,17 +18,25 @@ class GzipGenerator extends AbstractGenerator */ public const DEFAULT_COMPRESSION_LEVEL = 3; - public function generate(string $entryIdentifier, string $fileName, ResponseInterface $response, int $lifetime): void + public function generate(GeneratorCreate $generatorCreateEvent): void { - $contentGzip = gzencode((string) $response->getBody(), $this->getCompressionLevel()); + + if (!$this->getConfigurationService()->get('enableGeneratorGzip')) { + return; + } + $contentGzip = gzencode((string) $generatorCreateEvent->getResponse()->getBody(), $this->getCompressionLevel()); if ($contentGzip) { - $this->writeFile($fileName . '.gz', $contentGzip); + $this->writeFile($generatorCreateEvent->getFileName() . '.gz', $contentGzip); } } - public function remove(string $entryIdentifier, string $fileName): void + public function remove(GeneratorRemove $generatorRemoveEvent): void { - $this->removeFile($fileName . '.gz'); + + if (!$this->getConfigurationService()->get('enableGeneratorGzip')) { + return; + } + $this->removeFile($generatorRemoveEvent->getFileName() . '.gz'); } /** diff --git a/Classes/Generator/HtaccessGenerator.php b/Classes/Generator/HtaccessGenerator.php index 830d3ceae91..0c19ca9d511 100644 --- a/Classes/Generator/HtaccessGenerator.php +++ b/Classes/Generator/HtaccessGenerator.php @@ -5,6 +5,8 @@ namespace SFC\Staticfilecache\Generator; use Psr\Http\Message\ResponseInterface; +use SFC\Staticfilecache\Event\GeneratorCreate; +use SFC\Staticfilecache\Event\GeneratorRemove; use SFC\Staticfilecache\Service\ConfigurationService; use SFC\Staticfilecache\Service\DateTimeService; use SFC\Staticfilecache\Service\RemoveService; @@ -14,15 +16,15 @@ class HtaccessGenerator extends AbstractGenerator { - public function generate(string $entryIdentifier, string $fileName, ResponseInterface $response, int $lifetime): void + public function generate(GeneratorCreate $generatorCreateEvent): void { $configuration = GeneralUtility::makeInstance(ConfigurationService::class); - $htaccessFile = PathUtility::pathinfo($fileName, PATHINFO_DIRNAME) . '/.htaccess'; + $htaccessFile = PathUtility::pathinfo($generatorCreateEvent->getFileName(), PATHINFO_DIRNAME) . '/.htaccess'; $accessTimeout = (int) $configuration->get('htaccessTimeout'); - $lifetime = $accessTimeout ?: $lifetime; + $lifetime = $accessTimeout ?: $generatorCreateEvent->getLifetime(); - $headers = $configuration->getValidHeaders($response->getHeaders(), 'validHtaccessHeaders'); + $headers = $configuration->getValidHeaders($generatorCreateEvent->getResponse()->getHeaders(), 'validHtaccessHeaders'); if ($configuration->isBool('debugHeaders')) { $headers['X-SFC-State'] = 'StaticFileCache - via htaccess'; } @@ -61,9 +63,9 @@ protected function cleanupHeaderValues(array $headers): array return $headers; } - public function remove(string $entryIdentifier, string $fileName): void + public function remove(GeneratorRemove $generatorRemoveEvent): void { - $htaccessFile = PathUtility::pathinfo($fileName, PATHINFO_DIRNAME) . '/.htaccess'; + $htaccessFile = PathUtility::pathinfo($generatorRemoveEvent->getFileName(), PATHINFO_DIRNAME) . '/.htaccess'; $this->removeFile($htaccessFile); } diff --git a/Classes/Generator/PhpGenerator.php b/Classes/Generator/PhpGenerator.php index fc50488ab30..eecebb02cda 100644 --- a/Classes/Generator/PhpGenerator.php +++ b/Classes/Generator/PhpGenerator.php @@ -5,6 +5,8 @@ namespace SFC\Staticfilecache\Generator; use Psr\Http\Message\ResponseInterface; +use SFC\Staticfilecache\Event\GeneratorCreate; +use SFC\Staticfilecache\Event\GeneratorRemove; use SFC\Staticfilecache\Service\ConfigurationService; use SFC\Staticfilecache\Service\DateTimeService; use SFC\Staticfilecache\Service\RemoveService; @@ -16,13 +18,17 @@ */ class PhpGenerator extends HtaccessGenerator { - public function generate(string $entryIdentifier, string $fileName, ResponseInterface $response, int $lifetime): void + public function generate(GeneratorCreate $generatorCreateEvent): void { + if (!$this->getConfigurationService()->get('enableGeneratorPhp')) { + return; + } + $configuration = GeneralUtility::makeInstance(ConfigurationService::class); $accessTimeout = (int) $configuration->get('htaccessTimeout'); - $lifetime = $accessTimeout ?: $lifetime; + $lifetime = $accessTimeout ?: $generatorCreateEvent->getLifetime(); - $headers = $configuration->getValidHeaders($response->getHeaders(), 'validHtaccessHeaders'); + $headers = $configuration->getValidHeaders($generatorCreateEvent->getResponse()->getHeaders(), 'validHtaccessHeaders'); if ($configuration->isBool('debugHeaders')) { $headers['X-SFC-State'] = 'StaticFileCache - via PhpGenerator'; } @@ -34,15 +40,18 @@ public function generate(string $entryIdentifier, string $fileName, ResponseInte 'sendCacheControlHeaderRedirectAfterCacheTimeout' => $configuration->isBool('sendCacheControlHeaderRedirectAfterCacheTimeout'), 'headers' => $headers, 'requestUri' => $requestUri, - 'body' => (string) $response->getBody(), + 'body' => (string) $generatorCreateEvent->getResponse()->getBody(), ]; - $this->renderTemplateToFile($this->getTemplateName(), $variables, $fileName . '.php'); + $this->renderTemplateToFile($this->getTemplateName(), $variables, $generatorCreateEvent->getFileName() . '.php'); } - public function remove(string $entryIdentifier, string $fileName): void + public function remove(GeneratorRemove $generatorRemoveEvent): void { - $this->removeFile($fileName . '.php'); + if (!$this->getConfigurationService()->get('enableGeneratorPhp')) { + return; + } + $this->removeFile($generatorRemoveEvent->getFileName() . '.php'); } /** diff --git a/Classes/Generator/PlainGenerator.php b/Classes/Generator/PlainGenerator.php index 7c25b985a58..b14d51f86a3 100644 --- a/Classes/Generator/PlainGenerator.php +++ b/Classes/Generator/PlainGenerator.php @@ -4,19 +4,26 @@ namespace SFC\Staticfilecache\Generator; -use Psr\Http\Message\ResponseInterface; -use SFC\Staticfilecache\Service\RemoveService; -use TYPO3\CMS\Core\Utility\GeneralUtility; +use SFC\Staticfilecache\Event\GeneratorCreate; +use SFC\Staticfilecache\Event\GeneratorRemove; class PlainGenerator extends AbstractGenerator { - public function generate(string $entryIdentifier, string $fileName, ResponseInterface $response, int $lifetime): void + public function generate(GeneratorCreate $generatorCreateEvent): void { - $this->writeFile($fileName, (string) $response->getBody()); + + if (!$this->getConfigurationService()->get('enableGeneratorPlain')) { + return; + } + $this->writeFile($generatorCreateEvent->getFileName(), (string) $generatorCreateEvent->getResponse()->getBody()); } - public function remove(string $entryIdentifier, string $fileName): void + public function remove(GeneratorRemove $generatorRemoveEvent): void { - $this->removeFile($fileName); + + if (!$this->getConfigurationService()->get('enableGeneratorPlain')) { + return; + } + $this->removeFile($generatorRemoveEvent->getFileName()); } } diff --git a/Classes/Hook/AbstractHook.php b/Classes/Hook/AbstractHook.php deleted file mode 100644 index f148aefcd4a..00000000000 --- a/Classes/Hook/AbstractHook.php +++ /dev/null @@ -1,12 +0,0 @@ -override('boostMode', '0'); + /** @var CacheService $cacheService */ $cacheService = GeneralUtility::makeInstance(CacheService::class); $cacheService->get()->flushByTag('pageId_' . $id); $configuration->reset('boostMode'); diff --git a/Classes/Service/AbstractService.php b/Classes/Service/AbstractService.php index a9daabb486b..48502c1d9f2 100644 --- a/Classes/Service/AbstractService.php +++ b/Classes/Service/AbstractService.php @@ -4,9 +4,4 @@ namespace SFC\Staticfilecache\Service; -use SFC\Staticfilecache\StaticFileCacheObject; - -/** - * AbstractService. - */ -class AbstractService extends StaticFileCacheObject {} +class AbstractService {} diff --git a/Classes/Service/GeneratorService.php b/Classes/Service/GeneratorService.php index 442aba2288a..adaa4fe856d 100644 --- a/Classes/Service/GeneratorService.php +++ b/Classes/Service/GeneratorService.php @@ -4,31 +4,24 @@ namespace SFC\Staticfilecache\Service; +use Psr\EventDispatcher\EventDispatcherInterface; use Psr\Http\Message\ResponseInterface; -use SFC\Staticfilecache\Generator\AbstractGenerator; -use TYPO3\CMS\Core\Utility\GeneralUtility; +use SFC\Staticfilecache\Event\GeneratorCreate; +use SFC\Staticfilecache\Event\GeneratorRemove; class GeneratorService extends AbstractService { - /** - * Generate file. - */ + public function __construct( + protected EventDispatcherInterface $eventDispatcher, + ) {} + public function generate(string $entryIdentifier, string $fileName, ResponseInterface &$response, int $lifetime): void { - foreach (GeneralUtility::makeInstance(ObjectFactoryService::class)->get('Generator') as $implementation) { - // @var $implementation AbstractGenerator - $implementation->generate($entryIdentifier, $fileName, $response, $lifetime); - } + $this->eventDispatcher->dispatch(new GeneratorCreate($entryIdentifier, $fileName, $response, $lifetime)); } - /** - * Remove file. - */ public function remove(string $entryIdentifier, string $fileName): void { - foreach (GeneralUtility::makeInstance(ObjectFactoryService::class)->get('Generator') as $implementation) { - // @var $implementation AbstractGenerator - $implementation->remove($entryIdentifier, $fileName); - } + $this->eventDispatcher->dispatch(new GeneratorRemove($entryIdentifier, $fileName)); } } diff --git a/Classes/StaticFileCacheObject.php b/Classes/StaticFileCacheObject.php deleted file mode 100644 index c6b597011e8..00000000000 --- a/Classes/StaticFileCacheObject.php +++ /dev/null @@ -1,18 +0,0 @@ -