‪TYPO3CMS  ‪main
ViewHelperResolver.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;
21 use Psr\Http\Message\ServerRequestInterface;
26 use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperInterface;
27 
55 class ‪ViewHelperResolver extends \TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperResolver
56 {
57  protected ContainerInterface ‪$container;
58 
68  public function ‪__construct(ContainerInterface ‪$container, array $namespaces)
69  {
70  $this->container = ‪$container;
71  $this->namespaces = $namespaces;
72  if ((‪$GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface
73  && ‪ApplicationType::fromRequest(‪$GLOBALS['TYPO3_REQUEST'])->isFrontend()
74  && $this->‪getBackendUser() instanceof ‪BackendUserAuthentication
75  ) {
76  if ($this->‪getBackendUser()->uc['AdminPanel']['preview_showFluidDebug'] ?? false) {
77  $this->namespaces['f'][] = 'TYPO3\\CMS\\Fluid\\ViewHelpers\\Debug';
78  }
79  }
80  }
81 
85  public function ‪createViewHelperInstanceFromClassName($viewHelperClassName): ViewHelperInterface
86  {
87  if ($this->container instanceof ‪FailsafeContainer) {
88  // The install tool creates VH instances using makeInstance to not rely on symfony DI here,
89  // otherwise we'd have to have all install-tool used ones in ServiceProvider.php. However,
90  // none of the install tool used VH's use injection.
92  $viewHelperInstance = GeneralUtility::makeInstance($viewHelperClassName);
93  return $viewHelperInstance;
94  }
95 
96  if ($this->container->has($viewHelperClassName)) {
98  $viewHelperInstance = $this->container->get($viewHelperClassName);
99  } else {
101  $viewHelperInstance = new $viewHelperClassName();
102  }
103  return $viewHelperInstance;
104  }
105 
107  {
108  return ‪$GLOBALS['BE_USER'] ?? null;
109  }
110 }
‪TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperResolver
Definition: ViewHelperResolver.php:56
‪TYPO3\CMS\Fluid\Core\ViewHelper
Definition: ViewHelperResolver.php:18
‪TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperResolver\$container
‪ContainerInterface $container
Definition: ViewHelperResolver.php:57
‪TYPO3\CMS\Core\DependencyInjection\FailsafeContainer
Definition: FailsafeContainer.php:26
‪TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperResolver\getBackendUser
‪getBackendUser()
Definition: ViewHelperResolver.php:106
‪TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperResolver\createViewHelperInstanceFromClassName
‪createViewHelperInstanceFromClassName($viewHelperClassName)
Definition: ViewHelperResolver.php:85
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperResolver\__construct
‪__construct(ContainerInterface $container, array $namespaces)
Definition: ViewHelperResolver.php:68
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Http\fromRequest
‪@ fromRequest
Definition: ApplicationType.php:66
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Http\ApplicationType
‪ApplicationType
Definition: ApplicationType.php:55