[TASK] Use null coalescing operator where possible
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Mvc / View / NotFoundView.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Mvc\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
17 /**
18 * The not found view - a special case.
19 *
20 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
21 */
22 class NotFoundView extends \TYPO3\CMS\Extbase\Mvc\View\AbstractView
23 {
24 /**
25 * @var array
26 */
27 protected $variablesMarker = ['errorMessage' => 'ERROR_MESSAGE'];
28
29 /**
30 * Renders the not found view
31 *
32 * @return string The rendered view
33 * @throws \TYPO3\CMS\Extbase\Mvc\Exception if no request has been set
34 * @api
35 */
36 public function render()
37 {
38 if (!is_object($this->controllerContext->getRequest())) {
39 throw new \TYPO3\CMS\Extbase\Mvc\Exception('Can\'t render view without request object.', 1192450280);
40 }
41 $template = file_get_contents($this->getTemplatePathAndFilename());
42 if ($this->controllerContext->getRequest() instanceof \TYPO3\CMS\Extbase\Mvc\Web\Request) {
43 $template = str_replace('###BASEURI###', \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL'), $template);
44 }
45 foreach ($this->variablesMarker as $variableName => $marker) {
46 $variableValue = $this->variables[$variableName] ?? '';
47 $template = str_replace('###' . $marker . '###', $variableValue, $template);
48 }
49 return $template;
50 }
51
52 /**
53 * Retrieves path and filename of the not-found-template
54 *
55 * @return string path and filename of the not-found-template
56 */
57 protected function getTemplatePathAndFilename()
58 {
59 return \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('extbase') . 'Resources/Private/MVC/NotFoundView_Template.html';
60 }
61
62 /**
63 * A magic call method.
64 *
65 * Because this not found view is used as a Special Case in situations when no matching
66 * view is available, it must be able to handle method calls which originally were
67 * directed to another type of view. This magic method should prevent PHP from issuing
68 * a fatal error.
69 *
70 * @param string $methodName
71 * @param array $arguments
72 */
73 public function __call($methodName, array $arguments)
74 {
75 }
76 }