From b37463ee38e4259f690991a6c8dc243d483466c2 Mon Sep 17 00:00:00 2001 From: Claus Due Date: Mon, 31 Jul 2023 18:20:40 +0200 Subject: [PATCH] [TASK] Remove boot-time contexts sensitivity --- Classes/Builder/RenderingContextBuilder.php | 28 +++++++------------ .../Configuration/ConfigurationContext.php | 19 ------------- .../SpooledConfigurationApplicator.php | 7 ----- .../SpooledConfigurationApplicatorTest.php | 3 -- 4 files changed, 10 insertions(+), 47 deletions(-) delete mode 100644 Classes/Integration/Configuration/ConfigurationContext.php diff --git a/Classes/Builder/RenderingContextBuilder.php b/Classes/Builder/RenderingContextBuilder.php index 70aad632d..511795dba 100644 --- a/Classes/Builder/RenderingContextBuilder.php +++ b/Classes/Builder/RenderingContextBuilder.php @@ -9,7 +9,6 @@ * LICENSE.md file that was distributed with this source code. */ -use FluidTYPO3\Flux\Integration\Configuration\ConfigurationContext; use FluidTYPO3\Flux\Utility\ExtensionNamingUtility; use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; @@ -29,12 +28,10 @@ class RenderingContextBuilder implements SingletonInterface { - private ConfigurationContext $context; private RequestBuilder $requestBuilder; - public function __construct(ConfigurationContext $context, RequestBuilder $requestBuilder) + public function __construct(RequestBuilder $requestBuilder) { - $this->context = $context; $this->requestBuilder = $requestBuilder; } @@ -58,6 +55,14 @@ public function buildRenderingContextFor( if (method_exists($renderingContext, 'getControllerContext')) { /** @var ControllerContext $controllerContext */ + $controllerContext = $this->buildControllerContext($request); + try { + $renderingContext->setControllerContext($controllerContext); + } catch (\TypeError $error) { + throw new \UnexpectedValueException( + 'Controller class ' . $request->getControllerObjectName() . ' caused error: ' . $error->getMessage() + ); + } $controllerContext = clone $renderingContext->getControllerContext($request); $controllerContext->setRequest($request); $renderingContext->setControllerContext($controllerContext); @@ -72,25 +77,12 @@ public function buildRenderingContextFor( $renderingContext->setControllerName($controllerName); } - if (!$this->context->isBootMode()) { - $templatePaths = $renderingContext->getTemplatePaths(); - } else { - $resources = ExtensionManagementUtility::extPath($extensionKey) . 'Resources/Private/'; - $paths = [ - TemplatePaths::CONFIG_TEMPLATEROOTPATHS => [$resources . 'Templates/'], - TemplatePaths::CONFIG_PARTIALROOTPATHS => [$resources . 'Partials/'], - TemplatePaths::CONFIG_LAYOUTROOTPATHS => [$resources . 'Layouts/'], - ]; - /** @var TemplatePaths $templatePaths */ - $templatePaths = GeneralUtility::makeInstance(TemplatePaths::class, $paths); - } + $templatePaths = $renderingContext->getTemplatePaths(); if ($templatePathAndFilename) { $templatePaths->setTemplatePathAndFilename($templatePathAndFilename); } - $renderingContext->setTemplatePaths($templatePaths); - return $renderingContext; } diff --git a/Classes/Integration/Configuration/ConfigurationContext.php b/Classes/Integration/Configuration/ConfigurationContext.php deleted file mode 100644 index 8c29bb8ab..000000000 --- a/Classes/Integration/Configuration/ConfigurationContext.php +++ /dev/null @@ -1,19 +0,0 @@ -bootMode; - } - - public function setBootMode(bool $bootMode): void - { - $this->bootMode = $bootMode; - } -} diff --git a/Classes/Integration/Configuration/SpooledConfigurationApplicator.php b/Classes/Integration/Configuration/SpooledConfigurationApplicator.php index e3e102d2e..5666ca3ca 100644 --- a/Classes/Integration/Configuration/SpooledConfigurationApplicator.php +++ b/Classes/Integration/Configuration/SpooledConfigurationApplicator.php @@ -24,18 +24,15 @@ class SpooledConfigurationApplicator { - private ConfigurationContext $context; private ContentTypeBuilder $contentTypeBuilder; private ContentTypeManager $contentTypeManager; private RequestBuilder $requestBuilder; public function __construct( - ConfigurationContext $context, ContentTypeBuilder $contentTypeBuilder, ContentTypeManager $contentTypeManager, RequestBuilder $requestBuilder ) { - $this->context = $context; $this->contentTypeBuilder = $contentTypeBuilder; $this->contentTypeManager = $contentTypeManager; $this->requestBuilder = $requestBuilder; @@ -43,8 +40,6 @@ public function __construct( public function processData(): void { - $this->context->setBootMode(true); - // Initialize the TCA needed by "template as CType" integrations $this->spoolQueuedContentTypeTableConfigurations(Core::getQueuedContentTypeRegistrations()); @@ -60,8 +55,6 @@ public function processData(): void $this->spoolQueuedContentTypeRegistrations(Core::getQueuedContentTypeRegistrations()); Core::clearQueuedContentTypeRegistrations(); - - $this->context->setBootMode(false); } private function spoolQueuedContentTypeTableConfigurations(array $queue): void diff --git a/Tests/Unit/Integration/Configuration/SpooledConfigurationApplicatorTest.php b/Tests/Unit/Integration/Configuration/SpooledConfigurationApplicatorTest.php index f4b500660..7a2d237f4 100644 --- a/Tests/Unit/Integration/Configuration/SpooledConfigurationApplicatorTest.php +++ b/Tests/Unit/Integration/Configuration/SpooledConfigurationApplicatorTest.php @@ -85,13 +85,10 @@ protected function setUp(): void $this->requestBuilder = $this->getMockBuilder(RequestBuilder::class)->disableOriginalConstructor()->getMock(); - $configurationContext = new ConfigurationContext(); - $this->subject = $this->getMockBuilder(SpooledConfigurationApplicator::class) ->onlyMethods(['getApplicationContext', 'getContentTypeManager']) ->setConstructorArgs( [ - $configurationContext, $this->contentTypeBuilder, $this->contentTypeManager, $this->requestBuilder,