‪TYPO3CMS  10.4
RenderingContext.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
22 use TYPO3\CMS\Fluid\Core\Cache\FluidTemplateCache;
25 use TYPO3Fluid\Fluid\Core\Compiler\TemplateCompiler;
26 use TYPO3Fluid\Fluid\Core\Parser\Configuration;
27 use TYPO3Fluid\Fluid\Core\Parser\InterceptorInterface;
28 use TYPO3Fluid\Fluid\Core\Parser\TemplateParser;
29 use TYPO3Fluid\Fluid\Core\Parser\TemplateProcessorInterface;
30 use TYPO3Fluid\Fluid\Core\Variables\StandardVariableProvider;
31 use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperInvoker;
32 use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperVariableContainer;
33 use TYPO3Fluid\Fluid\View\ViewInterface;
34 
38 class ‪RenderingContext extends \TYPO3Fluid\Fluid\Core\Rendering\RenderingContext
39 {
45  protected ‪$controllerContext;
46 
50  protected ‪$controllerName = 'Default';
51 
55  protected ‪$controllerAction = 'Default';
56 
60  public function ‪injectViewHelperVariableContainer(ViewHelperVariableContainer $viewHelperVariableContainer)
61  {
62  $this->viewHelperVariableContainer = $viewHelperVariableContainer;
63  }
64 
68  public function ‪__construct(ViewInterface $view = null)
69  {
70  if ($view !== null) {
71  // Note: if $view is received here this indicates internal framework instancing
72  // and it is safe to call the parent constructor. Custom, non-view-providing
73  // usages will only perform the initialisation below (which is sufficient mind you!)
74  parent::__construct($view);
75  } else {
76  // Reproduced partial initialisation from parent::__construct; minus the custom
77  // implementations we attach below.
78  $this->setTemplateParser(new TemplateParser($this));
79  if (method_exists($this, 'setTemplateCompiler')) {
80  $this->setTemplateCompiler(new TemplateCompiler());
81  }
82  if (method_exists($this, 'setViewHelperInvoker')) {
83  $this->setViewHelperInvoker(new ViewHelperInvoker());
84  }
85  $this->setViewHelperVariableContainer(new ViewHelperVariableContainer());
86  $this->setVariableProvider(new StandardVariableProvider());
87  }
88 
89  $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
90  if (method_exists($this, 'setTemplateProcessors')) {
92  $processors = array_map([$objectManager, 'get'], ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['preProcessors']);
93  $this->setTemplateProcessors($processors);
94  }
95  $this->setExpressionNodeTypes(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['expressionNodeTypes']);
96  $this->setTemplatePaths($objectManager->get(TemplatePaths::class));
97  $this->setViewHelperResolver($objectManager->get(ViewHelperResolver::class));
98 
99  if (method_exists($this, 'setCache')) {
101  $cache = $objectManager->get(CacheManager::class)->getCache('fluid_template');
102  if (is_a(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['fluid_template']['frontend'], FluidTemplateCache::class, true)) {
103  $this->setCache($cache);
104  }
105  }
106  }
107 
113  public function ‪getParserConfiguration(): Configuration
114  {
115  $parserConfiguration = parent::getParserConfiguration();
116  $this->‪addInterceptorsToParserConfiguration(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['interceptors'], $parserConfiguration);
117  return $parserConfiguration;
118  }
119 
126  public function ‪buildParserConfiguration()
127  {
128  $parserConfiguration = parent::buildParserConfiguration();
129  $this->‪addInterceptorsToParserConfiguration(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['interceptors'], $parserConfiguration);
130  return $parserConfiguration;
131  }
132 
133  protected function ‪addInterceptorsToParserConfiguration(iterable $interceptors, Configuration $parserConfiguration): void
134  {
135  foreach ($interceptors as $className) {
136  $interceptor = GeneralUtility::makeInstance($className);
137  if (!$interceptor instanceof InterceptorInterface) {
138  throw new \InvalidArgumentException('Interceptor "' . $className . '" needs to implement ' . InterceptorInterface::class . '.', 1462869795);
139  }
140  $parserConfiguration->addInterceptor($interceptor);
141  }
142  }
143 
149  public function ‪getControllerContext()
150  {
152  }
153 
157  public function ‪setControllerAction($action)
158  {
159  $dotPosition = strpos($action, '.');
160  if ($dotPosition !== false) {
161  $action = substr($action, 0, $dotPosition);
162  }
163  $this->controllerAction = $action;
164  if ($this->controllerContext) {
165  $this->controllerContext->getRequest()->setControllerActionName(lcfirst($action));
166  }
167  }
168 
174  {
175  $this->controllerName = ‪$controllerName;
176  if ($this->controllerContext) {
177  $this->controllerContext->getRequest()->setControllerName(‪$controllerName);
178  }
179  }
180 
184  public function ‪getControllerName()
185  {
186  return $this->controllerContext ? $this->controllerContext->getRequest()->getControllerName() : ‪$this->controllerName;
187  }
188 
192  public function ‪getControllerAction()
193  {
194  return $this->controllerContext ? $this->controllerContext->getRequest()->getControllerActionName() : ‪$this->controllerAction;
195  }
196 
202  public function ‪setControllerContext(ControllerContext ‪$controllerContext)
203  {
204  $request = ‪$controllerContext->‪getRequest();
205  $this->controllerContext = ‪$controllerContext;
206  $this->‪setControllerAction($request->getControllerActionName());
207  // Check if Request is using a sub-package key; in which case we translate this
208  // for our RenderingContext as an emulated plain old sub-namespace controller.
209  ‪$controllerName = $request->getControllerName();
210  if ($request->getControllerSubpackageKey() && !strpos(‪$controllerName, '\\')) {
211  $this->‪setControllerName($request->getControllerSubpackageKey() . '\\' . ‪$controllerName);
212  } else {
214  }
215  }
216 }
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\addInterceptorsToParserConfiguration
‪addInterceptorsToParserConfiguration(iterable $interceptors, Configuration $parserConfiguration)
Definition: RenderingContext.php:130
‪TYPO3\CMS\Fluid\View\TemplatePaths
Definition: TemplatePaths.php:35
‪TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperResolver
Definition: ViewHelperResolver.php:53
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\setControllerAction
‪setControllerAction($action)
Definition: RenderingContext.php:154
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\$controllerName
‪string $controllerName
Definition: RenderingContext.php:48
‪TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext
Definition: ControllerContext.php:28
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\setControllerName
‪setControllerName($controllerName)
Definition: RenderingContext.php:170
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\buildParserConfiguration
‪Configuration buildParserConfiguration()
Definition: RenderingContext.php:123
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\__construct
‪__construct(ViewInterface $view=null)
Definition: RenderingContext.php:65
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\getControllerContext
‪TYPO3 CMS Extbase Mvc Controller ControllerContext getControllerContext()
Definition: RenderingContext.php:146
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\setControllerContext
‪setControllerContext(ControllerContext $controllerContext)
Definition: RenderingContext.php:199
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\injectViewHelperVariableContainer
‪injectViewHelperVariableContainer(ViewHelperVariableContainer $viewHelperVariableContainer)
Definition: RenderingContext.php:57
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:35
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\getControllerName
‪string getControllerName()
Definition: RenderingContext.php:181
‪TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext\getRequest
‪TYPO3 CMS Extbase Mvc Request getRequest()
Definition: ControllerContext.php:88
‪TYPO3\CMS\Fluid\Core\Rendering
Definition: RenderingContext.php:16
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\$controllerContext
‪TYPO3 CMS Extbase Mvc Controller ControllerContext null $controllerContext
Definition: RenderingContext.php:44
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\getParserConfiguration
‪Configuration getParserConfiguration()
Definition: RenderingContext.php:110
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\$controllerAction
‪string $controllerAction
Definition: RenderingContext.php:52
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext
Definition: RenderingContext.php:39
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:28
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\getControllerAction
‪string getControllerAction()
Definition: RenderingContext.php:189