Skip to content

Commit

Permalink
[TASK] Remove boot-time contexts sensitivity
Browse files Browse the repository at this point in the history
  • Loading branch information
NamelessCoder committed Jul 31, 2023
1 parent 6ee8bdc commit b37463e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 47 deletions.
28 changes: 10 additions & 18 deletions Classes/Builder/RenderingContextBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand All @@ -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);
Expand All @@ -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;
}

Expand Down
19 changes: 0 additions & 19 deletions Classes/Integration/Configuration/ConfigurationContext.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,22 @@

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;
}

public function processData(): void
{
$this->context->setBootMode(true);

// Initialize the TCA needed by "template as CType" integrations
$this->spoolQueuedContentTypeTableConfigurations(Core::getQueuedContentTypeRegistrations());

Expand All @@ -60,8 +55,6 @@ public function processData(): void

$this->spoolQueuedContentTypeRegistrations(Core::getQueuedContentTypeRegistrations());
Core::clearQueuedContentTypeRegistrations();

$this->context->setBootMode(false);
}

private function spoolQueuedContentTypeTableConfigurations(array $queue): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b37463e

Please sign in to comment.