[TASK] Use fully qualified name resolution in PHP 5.5
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / View / FailsafeView.php
1 <?php
2 namespace TYPO3\CMS\Install\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 use TYPO3\CMS\Core\Utility\GeneralUtility;
17
18 /**
19 * A view with basically wraps the standalone view for normal conditions
20 * and implements a renderAlertStatus message for alert conditions
21 * which would also make the install tool to fail.
22 */
23 class FailsafeView extends \TYPO3\CMS\Extbase\Mvc\View\AbstractView {
24
25 /**
26 * @var string
27 */
28 protected $templatePathAndFileName;
29
30 /**
31 * @var string
32 */
33 protected $layoutRootPath;
34
35 /**
36 * @var string
37 */
38 protected $partialRootPath;
39
40 /**
41 * @var \TYPO3\CMS\Extbase\Object\ObjectManager
42 */
43 protected $objectManager = NULL;
44
45 /**
46 * Constructor
47 */
48 public function __construct() {
49 $this->objectManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
50 }
51
52 /**
53 * Hand over regular rendering to standalone view,
54 * or render alert status
55 *
56 * @param bool $alert
57 * @return string
58 */
59 public function render($alert = FALSE) {
60 if ($alert) {
61 return $this->renderAlertStatus();
62 }
63 /** @var \TYPO3\CMS\Install\View\StandaloneView $realView */
64 $realView = $this->objectManager->get(\TYPO3\CMS\Install\View\StandaloneView::class);
65 $realView->assignMultiple($this->variables);
66 $realView->setTemplatePathAndFilename($this->templatePathAndFileName);
67 $realView->setLayoutRootPath($this->layoutRootPath);
68 $realView->setPartialRootPath($this->partialRootPath);
69
70 return $realView->render();
71 }
72
73 /**
74 * In case an alert happens we fall back to a simple PHP template
75 *
76 * @return string
77 */
78 protected function renderAlertStatus() {
79 $templatePath = preg_replace('#\.html$#', '.phtml', $this->templatePathAndFileName);
80 ob_start();
81 include $templatePath;
82 $renderedTemplate = ob_get_contents();
83 ob_end_clean();
84
85 return $renderedTemplate;
86 }
87
88 /**
89 * @param string $templatePathAndFileName
90 */
91 public function setTemplatePathAndFileName($templatePathAndFileName) {
92 $this->templatePathAndFileName = $templatePathAndFileName;
93 }
94
95 /**
96 * @param string $layoutRootPath
97 */
98 public function setLayoutRootPath($layoutRootPath) {
99 $this->layoutRootPath = $layoutRootPath;
100 }
101
102 /**
103 * @param string $partialRootPath
104 */
105 public function setPartialRootPath($partialRootPath) {
106 $this->partialRootPath = $partialRootPath;
107 }
108 }