TYPO3 CMS  TYPO3_7-6
FailsafeView.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 
18 
25 {
30 
34  protected $layoutRootPath;
35 
39  protected $partialRootPath;
40 
44  protected $objectManager = null;
45 
49  public function __construct()
50  {
51  $this->objectManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
52  }
53 
61  public function render($alert = false)
62  {
63  if ($alert) {
64  return $this->renderAlertStatus();
65  }
67  $realView = $this->objectManager->get(\TYPO3\CMS\Install\View\StandaloneView::class);
68  $realView->assignMultiple($this->variables);
69  $realView->setTemplatePathAndFilename($this->templatePathAndFileName);
70  $realView->setLayoutRootPaths([$this->layoutRootPath]);
71  $realView->setPartialRootPaths([$this->partialRootPath]);
72 
73  return $realView->render();
74  }
75 
81  protected function renderAlertStatus()
82  {
83  $templatePath = preg_replace('#\.html$#', '.phtml', $this->templatePathAndFileName);
84  ob_start();
85  include $templatePath;
86  $renderedTemplate = ob_get_contents();
87  ob_end_clean();
88 
89  return $renderedTemplate;
90  }
91 
96  {
97  $this->templatePathAndFileName = $templatePathAndFileName;
98  }
99 
104  {
105  $this->layoutRootPath = $layoutRootPath;
106  }
107 
112  {
113  $this->partialRootPath = $partialRootPath;
114  }
115 }
setTemplatePathAndFileName($templatePathAndFileName)