‪TYPO3CMS  ‪main
RenderingContext.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\Http\Message\ServerRequestInterface;
25 use TYPO3Fluid\Fluid\Core\Cache\FluidCacheInterface;
26 use TYPO3Fluid\Fluid\Core\Compiler\TemplateCompiler;
27 use TYPO3Fluid\Fluid\Core\Parser\Configuration;
28 use TYPO3Fluid\Fluid\Core\Parser\InterceptorInterface;
29 use TYPO3Fluid\Fluid\Core\Parser\TemplateParser;
30 use TYPO3Fluid\Fluid\Core\Variables\StandardVariableProvider;
31 use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperInvoker;
32 use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperVariableContainer;
33 
34 class ‪RenderingContext extends \TYPO3Fluid\Fluid\Core\Rendering\RenderingContext
35 {
36  protected ?ServerRequestInterface ‪$request = null;
37 
41  protected ‪$controllerName = 'Default';
42 
46  protected ‪$controllerAction = 'Default';
47 
51  public function ‪__construct(
52  ‪ViewHelperResolver $viewHelperResolver,
53  FluidCacheInterface $cache,
54  array $templateProcessors,
55  array $expressionNodeTypes,
56  ‪TemplatePaths $templatePaths,
57  ) {
58  // Partially cloning parent::__construct() but with custom implementations.
59  $this->setTemplateParser(new TemplateParser());
60  $this->setTemplateCompiler(new TemplateCompiler());
61  $this->setViewHelperInvoker(new ViewHelperInvoker());
62  $this->setViewHelperVariableContainer(new ViewHelperVariableContainer());
63  $this->setVariableProvider(new StandardVariableProvider());
64  $this->setTemplateProcessors($templateProcessors);
65  $this->setExpressionNodeTypes($expressionNodeTypes);
66  $this->setTemplatePaths($templatePaths);
67  $this->setViewHelperResolver($viewHelperResolver);
68  $this->setCache($cache);
69  }
70 
76  public function ‪buildParserConfiguration(): Configuration
77  {
78  $parserConfiguration = parent::buildParserConfiguration();
79  foreach (‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['interceptors'] as $className) {
80  $interceptor = GeneralUtility::makeInstance($className);
81  if (!$interceptor instanceof InterceptorInterface) {
82  throw new \InvalidArgumentException(
83  'Interceptor "' . $className . '" needs to implement ' . InterceptorInterface::class . '.',
84  1462869795
85  );
86  }
87  $parserConfiguration->addInterceptor($interceptor);
88  }
89  return $parserConfiguration;
90  }
91 
95  public function ‪setControllerAction($action): void
96  {
97  $dotPosition = strpos($action, '.');
98  if ($dotPosition !== false) {
99  $action = substr($action, 0, $dotPosition);
100  }
101  $this->controllerAction = $action;
102  if ($this->request instanceof RequestInterface) {
103  // @todo: Avoid altogether?!
104  $this->request = $this->request->withControllerActionName(lcfirst($action));
105  }
106  }
107 
111  public function ‪setControllerName(‪$controllerName): void
112  {
113  $this->controllerName = ‪$controllerName;
114  if ($this->request instanceof RequestInterface) {
115  // @todo: Avoid altogether?!
116  $this->request = $this->request->withControllerName(‪$controllerName);
117  }
118  }
119 
120  public function ‪getControllerName(): string
121  {
122  // @todo: Why fallback to request here? This is not consistent!
123  return $this->request instanceof ‪RequestInterface ? $this->request->‪getControllerName() : ‪$this->controllerName;
124  }
125 
126  public function ‪getControllerAction(): string
127  {
128  // @todo: Why fallback to request here? This is not consistent!
129  return $this->request instanceof ‪RequestInterface ? $this->request->‪getControllerActionName() : ‪$this->controllerAction;
130  }
131 
137  public function ‪setRequest(?ServerRequestInterface ‪$request): void
138  {
139  $this->request = ‪$request;
140  if (‪$request instanceof RequestInterface) {
141  // Set magic if this is an extbase request
142  $this->‪setControllerAction($request->getControllerActionName());
143  $this->‪setControllerName($request->getControllerName());
144  }
145  }
146 
147  public function ‪getRequest(): ?ServerRequestInterface
148  {
149  return ‪$this->request;
150  }
151 }
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\buildParserConfiguration
‪buildParserConfiguration()
Definition: RenderingContext.php:74
‪TYPO3\CMS\Fluid\View\TemplatePaths
Definition: TemplatePaths.php:39
‪TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperResolver
Definition: ViewHelperResolver.php:58
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\setControllerAction
‪setControllerAction($action)
Definition: RenderingContext.php:93
‪TYPO3\CMS\Extbase\Mvc\RequestInterface\getControllerName
‪getControllerName()
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\$controllerName
‪string $controllerName
Definition: RenderingContext.php:40
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\setControllerName
‪setControllerName($controllerName)
Definition: RenderingContext.php:109
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\getControllerName
‪getControllerName()
Definition: RenderingContext.php:118
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\$request
‪ServerRequestInterface $request
Definition: RenderingContext.php:36
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\__construct
‪__construct(ViewHelperResolver $viewHelperResolver, FluidCacheInterface $cache, array $templateProcessors, array $expressionNodeTypes, TemplatePaths $templatePaths,)
Definition: RenderingContext.php:49
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\getRequest
‪getRequest()
Definition: RenderingContext.php:145
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\getControllerAction
‪getControllerAction()
Definition: RenderingContext.php:124
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\setRequest
‪setRequest(?ServerRequestInterface $request)
Definition: RenderingContext.php:135
‪TYPO3\CMS\Extbase\Mvc\RequestInterface
Definition: RequestInterface.php:24
‪TYPO3\CMS\Fluid\Core\Rendering
Definition: RenderingContext.php:18
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\$controllerAction
‪string $controllerAction
Definition: RenderingContext.php:44
‪TYPO3\CMS\Extbase\Mvc\RequestInterface\getControllerActionName
‪getControllerActionName()
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext
Definition: RenderingContext.php:35