‪TYPO3CMS  ‪main
RenderingContextFactory.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Container\ContainerInterface;
25 use TYPO3Fluid\Fluid\Core\Cache\FluidCacheInterface;
26 use TYPO3Fluid\Fluid\Core\Parser\TemplateProcessor\EscapingModifierTemplateProcessor;
27 use TYPO3Fluid\Fluid\Core\Parser\TemplateProcessor\NamespaceDetectionTemplateProcessor;
28 use TYPO3Fluid\Fluid\Core\Parser\TemplateProcessor\PassthroughSourceModifierTemplateProcessor;
29 use TYPO3Fluid\Fluid\Core\Parser\TemplateProcessorInterface;
30 
51 {
52  public function ‪__construct(
53  private readonly ContainerInterface $container,
54  private readonly ‪CacheManager $cacheManager,
55  private readonly ‪ViewHelperResolverFactoryInterface $viewHelperResolverFactory,
56  ) {}
57 
58  public function ‪create(array $templatePathsArray = []): ‪RenderingContext
59  {
61  $processors = [];
62 
63  if ($this->container instanceof ‪FailsafeContainer) {
64  // Load default set of processors in failsafe mode (install tool context)
65  // as custom processors can not be retrieved from the symfony container
66  $processors = [
67  new EscapingModifierTemplateProcessor(),
68  new PassthroughSourceModifierTemplateProcessor(),
69  new NamespaceDetectionTemplateProcessor(),
70  ];
71  } else {
72  foreach (‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['preProcessors'] as $className) {
74  $processors[] = $this->container->get($className);
75  }
76  }
77 
78  $cache = $this->cacheManager->getCache('fluid_template');
79  if (!$cache instanceof FluidCacheInterface) {
80  throw new \RuntimeException('Cache fluid_template must implement FluidCacheInterface', 1623148753);
81  }
82 
83  $templatePaths = new ‪TemplatePaths();
84  if (!empty($templatePathsArray['templateRootPaths'])) {
85  $templatePaths->setTemplateRootPaths($templatePathsArray['templateRootPaths']);
86  }
87  if (!empty($templatePathsArray['layoutRootPaths'])) {
88  $templatePaths->setLayoutRootPaths($templatePathsArray['layoutRootPaths']);
89  }
90  if (!empty($templatePathsArray['partialRootPaths'])) {
91  $templatePaths->setPartialRootPaths($templatePathsArray['partialRootPaths']);
92  }
93 
94  return new ‪RenderingContext(
95  $this->viewHelperResolverFactory->create(),
96  $cache,
97  $processors,
98  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['expressionNodeTypes'],
99  $templatePaths
100  );
101  }
102 }
‪TYPO3\CMS\Fluid\View\TemplatePaths
Definition: TemplatePaths.php:39
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContextFactory\__construct
‪__construct(private readonly ContainerInterface $container, private readonly CacheManager $cacheManager, private readonly ViewHelperResolverFactoryInterface $viewHelperResolverFactory,)
Definition: RenderingContextFactory.php:52
‪TYPO3\CMS\Core\DependencyInjection\FailsafeContainer
Definition: FailsafeContainer.php:26
‪TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperResolverFactoryInterface
Definition: ViewHelperResolverFactoryInterface.php:27
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:36
‪TYPO3\CMS\Fluid\Core\Rendering
Definition: RenderingContext.php:18
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContextFactory\create
‪create(array $templatePathsArray=[])
Definition: RenderingContextFactory.php:58
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContextFactory
Definition: RenderingContextFactory.php:51
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext
Definition: RenderingContext.php:35