TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
RenderingContext.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Fluid\Core\Rendering;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
27 use TYPO3Fluid\Fluid\Core\Compiler\TemplateCompiler;
28 use TYPO3Fluid\Fluid\Core\Parser\Configuration;
29 use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\Expression\CastingExpressionNode;
30 use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\Expression\MathExpressionNode;
31 use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\Expression\TernaryExpressionNode;
32 use TYPO3Fluid\Fluid\Core\Parser\TemplateParser;
33 use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperInvoker;
34 use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperVariableContainer;
35 use TYPO3Fluid\Fluid\View\ViewInterface;
36 
40 class RenderingContext extends \TYPO3Fluid\Fluid\Core\Rendering\RenderingContext
41 {
48 
55  protected $objectManager;
56 
62  protected $controllerContext;
63 
70 
76  protected $legacyMode = false;
77 
85  protected $expressionNodeTypes = [
86  LegacyNamespaceExpressionNode::class,
87  CastingExpressionNode::class,
88  MathExpressionNode::class,
89  TernaryExpressionNode::class
90  ];
91 
99  LegacyNamespaceExpressionNode::class
100  ];
101 
105  public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
106  {
107  $this->objectManager = $objectManager;
108  }
109 
113  public function injectViewHelperVariableContainer(\TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperVariableContainer $viewHelperVariableContainer)
114  {
115  $this->viewHelperVariableContainer = $viewHelperVariableContainer;
116  }
117 
121  public function __construct(ViewInterface $view = null)
122  {
123  if ($view !== null) {
124  // Note: if $view is received here this indicates internal framework instancing
125  // and it is safe to call the parent constructor. Custom, non-view-providing
126  // usages will only perform the initialisation below (which is sufficient mind you!)
127  parent::__construct($view);
128  } else {
129  // Reproduced partial initialisation from parent::__construct; minus the custom
130  // implementations we attach below.
131  $this->setTemplateParser(new TemplateParser());
132  $this->setTemplateCompiler(new TemplateCompiler());
133  $this->setViewHelperInvoker(new ViewHelperInvoker());
134  $this->setViewHelperVariableContainer(new ViewHelperVariableContainer());
135  }
136 
137  $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
138  $this->setTemplatePaths($objectManager->get(TemplatePaths::class));
139  $this->setViewHelperResolver($objectManager->get(ViewHelperResolver::class));
140  $this->setVariableProvider($objectManager->get(CmsVariableProvider::class));
141  $this->setTemplateProcessors(
142  array_merge(
143  parent::getTemplateProcessors(),
144  [
145  $objectManager->get(XmlnsNamespaceTemplatePreProcessor::class),
146  ]
147  )
148  );
150  $cache = $objectManager->get(CacheManager::class)->getCache('fluid_template');
151  if (is_a($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['fluid_template']['frontend'], FluidTemplateCache::class, true)) {
152  $this->setCache($cache);
153  }
154  }
155 
162  public function buildParserConfiguration()
163  {
164  $parserConfiguration = parent::buildParserConfiguration();
165  if (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['interceptors'])) {
166  foreach ($GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['interceptors'] as $className) {
167  $interceptor = GeneralUtility::makeInstance($className);
168  if (!$interceptor instanceof InterceptorInterface) {
169  throw new \InvalidArgumentException('Interceptor "' . $className . '" needs to implement ' . InterceptorInterface::class . '.', 1462869795);
170  }
171  $parserConfiguration->addInterceptor($interceptor);
172  }
173  }
174 
175  return $parserConfiguration;
176  }
177 
186  public function setLegacyMode($legacyMode)
187  {
188  $this->legacyMode = $legacyMode;
189  }
190 
194  public function getExpressionNodeTypes()
195  {
196  return $this->legacyMode ? $this->legacyExpressionNodeTypes : $this->expressionNodeTypes;
197  }
198 
204  public function getObjectManager()
205  {
206  return $this->objectManager;
207  }
208 
217  {
219  'getTemplateVariableContainer is deprecated since TYPO3 CMS 8, will be removed in TYPO3 CMS 9' .
220  ' - use getVariableProvider instead'
221  );
222  return $this->variableProvider;
223  }
224 
230  public function getControllerContext()
231  {
233  }
234 
239  public function setControllerAction($action)
240  {
241  $action = lcfirst(pathinfo($action, PATHINFO_FILENAME));
242  parent::setControllerAction($action);
243  $this->controllerContext->getRequest()->setControllerActionName($action);
244  }
245 
250  public function setControllerName($controllerName)
251  {
252  parent::setControllerName($controllerName);
253  $this->controllerContext->getRequest()->setControllerName($controllerName);
254  }
255 
261  public function setControllerContext(\TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext)
262  {
263  $request = $controllerContext->getRequest();
264  $this->controllerContext = $controllerContext;
265  $this->setControllerAction($request->getControllerActionName());
266  // Check if Request is using a sub-package key; in which case we translate this
267  // for our RenderingContext as an emulated plain old sub-namespace controller.
268  $controllerName = $request->getControllerName();
269  if ($request->getControllerSubpackageKey() && !strpos($controllerName, '\\')) {
270  $this->setControllerName($request->getControllerSubpackageKey() . '\\' . $controllerName);
271  } else {
272  $this->setControllerName($controllerName);
273  }
274  }
275 
282  {
284  }
285 }
setControllerContext(\TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext)
injectViewHelperVariableContainer(\TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperVariableContainer $viewHelperVariableContainer)
injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static makeInstance($className,...$constructorArguments)