[BUGFIX] Introduce failsafe view in install tool
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / View / FailsafeView.php
1 <?php
2 namespace TYPO3\CMS\Install\View;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2013 Helmut Hummel <helmut.hummel@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 use TYPO3\CMS\Core\Utility\GeneralUtility;
27
28 /**
29 * A view with basically wraps the standalone view for normal conditions
30 * and implements a renderAlertStatus message for alert conditions
31 * which would also make the install tool to fail.
32 */
33 class FailsafeView extends \TYPO3\CMS\Extbase\Mvc\View\AbstractView {
34
35 /**
36 * @var string
37 */
38 protected $templatePathAndFileName;
39
40 /**
41 * @var string
42 */
43 protected $layoutRootPath;
44
45 /**
46 * @var string
47 */
48 protected $partialRootPath;
49
50 /**
51 * @var \TYPO3\CMS\Extbase\Object\ObjectManager
52 */
53 protected $objectManager = NULL;
54
55 /**
56 * Constructor
57 */
58 public function __construct() {
59 $this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
60 }
61
62 /**
63 * Hand over regular rendering to standalone view,
64 * or render alert status
65 *
66 * @param bool $alert
67 * @return string
68 */
69 public function render($alert = FALSE) {
70 if ($alert) {
71 return $this->renderAlertStatus();
72 }
73 /** @var \TYPO3\CMS\Install\View\StandaloneView $realView */
74 $realView = $this->objectManager->get('TYPO3\\CMS\\Install\\View\\StandaloneView');
75 $realView->assignMultiple($this->variables);
76 $realView->setTemplatePathAndFilename($this->templatePathAndFileName);
77 $realView->setLayoutRootPath($this->layoutRootPath);
78 $realView->setPartialRootPath($this->partialRootPath);
79
80 return $realView->render();
81 }
82
83 /**
84 * In case an alert happens we fall back to a simple PHP template
85 *
86 * @return string
87 */
88 protected function renderAlertStatus() {
89 $templatePath = preg_replace('#\.html$#', '.phtml', $this->templatePathAndFileName);
90 ob_start();
91 include $templatePath;
92 $renderedTemplate = ob_get_contents();
93 ob_end_clean();
94
95 return $renderedTemplate;
96 }
97
98 /**
99 * @param string $templatePathAndFileName
100 */
101 public function setTemplatePathAndFileName($templatePathAndFileName) {
102 $this->templatePathAndFileName = $templatePathAndFileName;
103 }
104
105 /**
106 * @param string $layoutRootPath
107 */
108 public function setLayoutRootPath($layoutRootPath) {
109 $this->layoutRootPath = $layoutRootPath;
110 }
111
112 /**
113 * @param string $partialRootPath
114 */
115 public function setPartialRootPath($partialRootPath) {
116 $this->partialRootPath = $partialRootPath;
117 }
118 }