‪TYPO3CMS  11.5
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 
24 use TYPO3Fluid\Fluid\Core\Cache\FluidCacheInterface;
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\Variables\StandardVariableProvider;
30 use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperInvoker;
31 use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperVariableContainer;
32 
36 class ‪RenderingContext extends \TYPO3Fluid\Fluid\Core\Rendering\RenderingContext
37 {
44  protected ‪$controllerContext;
45 
49  protected ‪$request;
50 
54  protected ‪$controllerName = 'Default';
55 
59  protected ‪$controllerAction = 'Default';
60 
66  public function ‪injectViewHelperVariableContainer(ViewHelperVariableContainer $viewHelperVariableContainer)
67  {
68  $this->setViewHelperVariableContainer($viewHelperVariableContainer);
69  }
70 
74  public function ‪__construct(
75  ‪ViewHelperResolver $viewHelperResolver,
76  FluidCacheInterface $cache,
77  array $templateProcessors,
78  array $expressionNodeTypes
79  ) {
80  // Reproduced partial initialisation from parent::__construct; minus the custom implementations we attach below.
81  $this->setTemplateParser(new TemplateParser());
82  $this->setTemplateCompiler(new TemplateCompiler());
83  $this->setViewHelperInvoker(new ViewHelperInvoker());
84  $this->setViewHelperVariableContainer(new ViewHelperVariableContainer());
85  $this->setVariableProvider(new StandardVariableProvider());
86 
87  $this->setTemplateProcessors($templateProcessors);
88 
89  $this->setExpressionNodeTypes($expressionNodeTypes);
90  $this->setTemplatePaths(GeneralUtility::makeInstance(TemplatePaths::class));
91  $this->setViewHelperResolver($viewHelperResolver);
92 
93  $this->setCache($cache);
94  }
95 
101  public function ‪getParserConfiguration(): Configuration
102  {
103  $parserConfiguration = parent::getParserConfiguration();
104  $this->‪addInterceptorsToParserConfiguration(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['interceptors'], $parserConfiguration);
105  return $parserConfiguration;
106  }
107 
114  public function ‪buildParserConfiguration()
115  {
116  $parserConfiguration = parent::buildParserConfiguration();
117  $this->‪addInterceptorsToParserConfiguration(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['interceptors'], $parserConfiguration);
118  return $parserConfiguration;
119  }
120 
121  protected function ‪addInterceptorsToParserConfiguration(iterable $interceptors, Configuration $parserConfiguration): void
122  {
123  foreach ($interceptors as $className) {
124  $interceptor = GeneralUtility::makeInstance($className);
125  if (!$interceptor instanceof InterceptorInterface) {
126  throw new \InvalidArgumentException('Interceptor "' . $className . '" needs to implement ' . InterceptorInterface::class . '.', 1462869795);
127  }
128  $parserConfiguration->addInterceptor($interceptor);
129  }
130  }
131 
138  public function ‪getControllerContext()
139  {
140  if ($this->controllerContext) {
142  }
143  ‪$controllerContext = GeneralUtility::makeInstance(ControllerContext::class);
144  if ($this->request) {
145  ‪$controllerContext->‪setRequest($this->request);
146  }
147  return ‪$controllerContext;
148  }
149 
153  public function ‪setControllerAction($action)
154  {
155  $dotPosition = strpos($action, '.');
156  if ($dotPosition !== false) {
157  $action = substr($action, 0, $dotPosition);
158  }
159  $this->controllerAction = $action;
160  if ($this->request) {
161  $this->request->setControllerActionName(lcfirst($action));
162  }
163  }
164 
170  {
171  $this->controllerName = ‪$controllerName;
172  if ($this->request instanceof ‪Request) {
173  $this->request->setControllerName(‪$controllerName);
174  }
175  }
176 
180  public function ‪getControllerName()
181  {
182  return $this->request instanceof ‪Request ? $this->request->‪getControllerName() : ‪$this->controllerName;
183  }
184 
188  public function ‪getControllerAction()
189  {
190  return $this->request instanceof ‪Request ? $this->request->‪getControllerActionName() : ‪$this->controllerAction;
191  }
192 
200  {
201  $this->controllerContext = ‪$controllerContext;
202  if ($this->request === null) {
203  trigger_error(
204  'Setting request from controllerContext in class ' . __CLASS__ . ' is deprecated. Use setRequest() directly.',
205  E_USER_DEPRECATED
206  );
208  $this->‪setRequest(‪$request);
209  }
210  }
211 
218  public function ‪setRequest(Request ‪$request): void
219  {
220  $this->request = ‪$request;
221  $this->‪setControllerAction($request->getControllerActionName());
222  $this->‪setControllerName($request->getControllerName());
223  // Also ensure that controller context is filled, if not set yet.
224  if ($this->controllerContext === null) {
225  // @deprecated since v11, will be removed with v12.
226  $this->controllerContext = GeneralUtility::makeInstance(ControllerContext::class);
227  $this->controllerContext->setRequest(‪$request);
228  }
229  }
230 
235  public function ‪getRequest(): Request
236  {
237  return ‪$this->request;
238  }
239 
244  public function ‪getUriBuilder(): UriBuilder
245  {
246  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
247  $uriBuilder->setRequest($this->request);
248  return $uriBuilder;
249  }
250 }
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\addInterceptorsToParserConfiguration
‪addInterceptorsToParserConfiguration(iterable $interceptors, Configuration $parserConfiguration)
Definition: RenderingContext.php:117
‪TYPO3\CMS\Fluid\View\TemplatePaths
Definition: TemplatePaths.php:37
‪TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperResolver
Definition: ViewHelperResolver.php:57
‪TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
Definition: UriBuilder.php:41
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\setControllerAction
‪setControllerAction($action)
Definition: RenderingContext.php:149
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\$controllerName
‪string $controllerName
Definition: RenderingContext.php:51
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\getRequest
‪Request getRequest()
Definition: RenderingContext.php:231
‪TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext
Definition: ControllerContext.php:30
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\setRequest
‪setRequest(Request $request)
Definition: RenderingContext.php:214
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\setControllerName
‪setControllerName($controllerName)
Definition: RenderingContext.php:165
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\buildParserConfiguration
‪Configuration buildParserConfiguration()
Definition: RenderingContext.php:110
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\$request
‪Request $request
Definition: RenderingContext.php:47
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\setControllerContext
‪setControllerContext(ControllerContext $controllerContext)
Definition: RenderingContext.php:195
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\injectViewHelperVariableContainer
‪injectViewHelperVariableContainer(ViewHelperVariableContainer $viewHelperVariableContainer)
Definition: RenderingContext.php:62
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\getControllerName
‪string getControllerName()
Definition: RenderingContext.php:176
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\$controllerContext
‪ControllerContext $controllerContext
Definition: RenderingContext.php:43
‪TYPO3\CMS\Extbase\Mvc\Request\getControllerName
‪getControllerName()
Definition: Request.php:167
‪TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext\getRequest
‪TYPO3 CMS Extbase Mvc Request getRequest()
Definition: ControllerContext.php:86
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\getUriBuilder
‪UriBuilder getUriBuilder()
Definition: RenderingContext.php:240
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\getControllerContext
‪ControllerContext getControllerContext()
Definition: RenderingContext.php:134
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\__construct
‪__construct(ViewHelperResolver $viewHelperResolver, FluidCacheInterface $cache, array $templateProcessors, array $expressionNodeTypes)
Definition: RenderingContext.php:70
‪TYPO3\CMS\Fluid\Core\Rendering
Definition: RenderingContext.php:16
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\getParserConfiguration
‪Configuration getParserConfiguration()
Definition: RenderingContext.php:97
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\$controllerAction
‪string $controllerAction
Definition: RenderingContext.php:55
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext
Definition: RenderingContext.php:37
‪TYPO3\CMS\Extbase\Mvc\Request
Definition: Request.php:39
‪TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext\setRequest
‪setRequest(Request $request)
Definition: ControllerContext.php:76
‪TYPO3\CMS\Extbase\Mvc\Request\getControllerActionName
‪getControllerActionName()
Definition: Request.php:191
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\getControllerAction
‪string getControllerAction()
Definition: RenderingContext.php:184