‪TYPO3CMS  9.5
StandaloneView.php
Go to the documentation of this file.
1 <?php
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 
20 use ‪TYPO3\CMS\Extbase\Mvc\Web\Request as WebRequest;
26 
32 {
36  protected ‪$objectManager;
37 
45  public function ‪__construct(‪ContentObjectRenderer $contentObject = null)
46  {
47  $this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
48 
50  $configurationManager = $this->objectManager->get(ConfigurationManagerInterface::class);
51  if ($contentObject === null) {
53  $contentObject = GeneralUtility::makeInstance(ContentObjectRenderer::class);
54  }
55  $configurationManager->setContentObject($contentObject);
56 
58  $request = $this->objectManager->get(WebRequest::class);
59  $request->setRequestUri(GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'));
60  $request->setBaseUri(GeneralUtility::getIndpEnv('TYPO3_SITE_URL'));
62  $uriBuilder = $this->objectManager->get(UriBuilder::class);
63  $uriBuilder->setRequest($request);
65  ‪$controllerContext = $this->objectManager->get(ControllerContext::class);
68  $renderingContext = $this->objectManager->get(RenderingContext::class, $this);
69  $renderingContext->setControllerContext(‪$controllerContext);
70  parent::__construct($renderingContext);
71  }
72 
79  public function ‪setFormat($format)
80  {
81  if ($this->baseRenderingContext instanceof ‪RenderingContext) {
82  $this->baseRenderingContext->getControllerContext()->getRequest()->setFormat($format);
83  $this->baseRenderingContext->getTemplatePaths()->setFormat($format);
84  } else {
85  throw new \RuntimeException('The rendering context must be of type ' . RenderingContext::class, 1482251886);
86  }
87  }
88 
95  public function ‪getFormat()
96  {
97  if ($this->baseRenderingContext instanceof ‪RenderingContext) {
98  return $this->baseRenderingContext->getControllerContext()->getRequest()->getFormat();
99  }
100  throw new \RuntimeException('The rendering context must be of type ' . RenderingContext::class, 1482251887);
101  }
102 
110  public function ‪getRequest()
111  {
112  if ($this->baseRenderingContext instanceof ‪RenderingContext) {
113  return $this->baseRenderingContext->getControllerContext()->getRequest();
114  }
115  throw new \RuntimeException('The rendering context must be of type ' . RenderingContext::class, 1482251888);
116  }
117 
127  public function ‪getTemplatePathAndFilename()
128  {
129  $templatePaths = $this->baseRenderingContext->getTemplatePaths();
130  return $templatePaths->resolveTemplateFileForControllerAndActionAndFormat(
131  $this->baseRenderingContext->getControllerName(),
132  $this->baseRenderingContext->getControllerAction(),
133  $templatePaths->getFormat()
134  );
135  }
136 
143  public function ‪setTemplateSource($templateSource)
144  {
145  $this->baseRenderingContext->getTemplatePaths()->setTemplateSource($templateSource);
146  }
147 
153  public function ‪hasTemplate()
154  {
155  try {
156  $this->baseRenderingContext->getTemplatePaths()->getTemplateSource(
157  $this->baseRenderingContext->getControllerName(),
158  $this->baseRenderingContext->getControllerAction()
159  );
160  return true;
162  return false;
163  }
164  }
165 }
‪TYPO3\CMS\Fluid\View\StandaloneView\setTemplateSource
‪setTemplateSource($templateSource)
Definition: StandaloneView.php:142
‪TYPO3\CMS\Fluid\View\StandaloneView\__construct
‪__construct(ContentObjectRenderer $contentObject=null)
Definition: StandaloneView.php:44
‪TYPO3\CMS\Fluid\View\StandaloneView\$objectManager
‪ObjectManager null $objectManager
Definition: StandaloneView.php:35
‪TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
Definition: UriBuilder.php:29
‪TYPO3\CMS\Fluid\View\StandaloneView\hasTemplate
‪bool hasTemplate()
Definition: StandaloneView.php:152
‪TYPO3\CMS\Fluid\View\AbstractTemplateView\$controllerContext
‪TYPO3 CMS Extbase Mvc Controller ControllerContext $controllerContext
Definition: AbstractTemplateView.php:33
‪TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext\setUriBuilder
‪setUriBuilder(\TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder $uriBuilder)
Definition: ControllerContext.php:129
‪TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext
Definition: ControllerContext.php:21
‪TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext\setRequest
‪setRequest(\TYPO3\CMS\Extbase\Mvc\Request $request)
Definition: ControllerContext.php:71
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
Definition: ConfigurationManagerInterface.php:22
‪TYPO3\CMS\Fluid\View\AbstractTemplateView
Definition: AbstractTemplateView.php:30
‪TYPO3\CMS\Fluid\View\StandaloneView\getFormat
‪string getFormat()
Definition: StandaloneView.php:94
‪TYPO3\CMS\Fluid\View\StandaloneView\setFormat
‪setFormat($format)
Definition: StandaloneView.php:78
‪TYPO3\CMS\Extbase\Mvc\Web\Request
Definition: Request.php:21
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:32
‪TYPO3\CMS\Fluid\View\Exception\InvalidTemplateResourceException
Definition: LegacyClassesForIde.php:72
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:91
‪TYPO3\CMS\Fluid\View\StandaloneView\getRequest
‪WebRequest getRequest()
Definition: StandaloneView.php:109
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext
Definition: RenderingContext.php:36
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:25
‪TYPO3\CMS\Fluid\View
Definition: AbstractTemplateView.php:2
‪TYPO3\CMS\Fluid\View\StandaloneView\getTemplatePathAndFilename
‪string getTemplatePathAndFilename()
Definition: StandaloneView.php:126