TYPO3 CMS  TYPO3_8-7
StandaloneView.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Fluid\View;
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 
26 
34 {
38  protected $objectManager = null;
39 
47  public function __construct(ContentObjectRenderer $contentObject = null)
48  {
49  $this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
50 
52  $configurationManager = $this->objectManager->get(ConfigurationManagerInterface::class);
53  if ($contentObject === null) {
55  $contentObject = GeneralUtility::makeInstance(ContentObjectRenderer::class);
56  }
57  $configurationManager->setContentObject($contentObject);
58 
60  $request = $this->objectManager->get(WebRequest::class);
61  $request->setRequestUri(GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'));
62  $request->setBaseUri(GeneralUtility::getIndpEnv('TYPO3_SITE_URL'));
64  $uriBuilder = $this->objectManager->get(UriBuilder::class);
65  $uriBuilder->setRequest($request);
67  $controllerContext = $this->objectManager->get(ControllerContext::class);
68  $controllerContext->setRequest($request);
69  $controllerContext->setUriBuilder($uriBuilder);
70  $renderingContext = $this->objectManager->get(RenderingContext::class, $this);
71  $renderingContext->setControllerContext($controllerContext);
72  parent::__construct($renderingContext);
73  }
74 
78  public function setTemplate($templateName)
79  {
80  $this->baseRenderingContext->setControllerAction($templateName);
81  }
82 
90  public function setFormat($format)
91  {
92  if ($this->baseRenderingContext instanceof RenderingContext) {
93  $this->baseRenderingContext->getControllerContext()->getRequest()->setFormat($format);
94  $this->baseRenderingContext->getTemplatePaths()->setFormat($format);
95  } else {
96  throw new \RuntimeException('The rendering context must be of type ' . RenderingContext::class, 1482251886);
97  }
98  }
99 
107  public function getFormat()
108  {
109  if ($this->baseRenderingContext instanceof RenderingContext) {
110  return $this->baseRenderingContext->getControllerContext()->getRequest()->getFormat();
111  }
112  throw new \RuntimeException('The rendering context must be of type ' . RenderingContext::class, 1482251887);
113  }
114 
121  public function getRequest()
122  {
123  if ($this->baseRenderingContext instanceof RenderingContext) {
124  return $this->baseRenderingContext->getControllerContext()->getRequest();
125  }
126  throw new \RuntimeException('The rendering context must be of type ' . RenderingContext::class, 1482251888);
127  }
128 
135  public function setTemplatePathAndFilename($templatePathAndFilename)
136  {
137  $this->baseRenderingContext->getTemplatePaths()->setTemplatePathAndFilename($templatePathAndFilename);
138  }
139 
150  public function getTemplatePathAndFilename()
151  {
152  $templatePaths = $this->baseRenderingContext->getTemplatePaths();
153  return $templatePaths->resolveTemplateFileForControllerAndActionAndFormat(
154  $this->baseRenderingContext->getControllerName(),
155  $this->baseRenderingContext->getControllerAction(),
156  $templatePaths->getFormat()
157  );
158  }
159 
167  public function setTemplateSource($templateSource)
168  {
169  $this->baseRenderingContext->getTemplatePaths()->setTemplateSource($templateSource);
170  }
171 
178  public function setTemplateRootPaths(array $templateRootPaths)
179  {
180  $this->baseRenderingContext->getTemplatePaths()->setTemplateRootPaths($templateRootPaths);
181  }
182 
189  public function setLayoutRootPaths(array $layoutRootPaths)
190  {
191  $this->baseRenderingContext->getTemplatePaths()->setLayoutRootPaths($layoutRootPaths);
192  }
193 
201  public function getLayoutRootPaths()
202  {
203  return $this->baseRenderingContext->getTemplatePaths()->getLayoutRootPaths();
204  }
205 
213  public function setPartialRootPaths(array $partialRootPaths)
214  {
215  $this->baseRenderingContext->getTemplatePaths()->setPartialRootPaths($partialRootPaths);
216  }
217 
225  public function getPartialRootPaths()
226  {
227  return $this->baseRenderingContext->getTemplatePaths()->getPartialRootPaths();
228  }
229 
236  public function hasTemplate()
237  {
238  try {
239  $this->baseRenderingContext->getTemplatePaths()->getTemplateSource(
240  $this->baseRenderingContext->getControllerName(),
241  $this->baseRenderingContext->getControllerAction()
242  );
243  return true;
244  } catch (InvalidTemplateResourceException $e) {
245  return false;
246  }
247  }
248 }
setPartialRootPaths(array $partialRootPaths)
setTemplatePathAndFilename($templatePathAndFilename)
setTemplateRootPaths(array $templateRootPaths)
setLayoutRootPaths(array $layoutRootPaths)
static makeInstance($className,... $constructorArguments)
__construct(RenderingContextInterface $context=null)