[TASK] Remove ext:dbal from installation steps
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Controller / ErrorPageController.php
1 <?php
2 declare (strict_types = 1);
3 namespace TYPO3\CMS\Core\Controller;
4
5 /*
6 * This file is part of the TYPO3 CMS project.
7 *
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
11 *
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
14 *
15 * The TYPO3 project - inspiring people to share!
16 */
17
18 use TYPO3\CMS\Core\Messaging\AbstractMessage;
19 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21 use TYPO3\CMS\Core\Utility\PathUtility;
22 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContext;
23 use TYPO3Fluid\Fluid\View\TemplatePaths;
24 use TYPO3Fluid\Fluid\View\TemplateView;
25
26 /**
27 * A class representing error messages shown on a page, rendered via fluid.
28 * Classic Example: "No pages are found on rootlevel"
29 */
30 class ErrorPageController
31 {
32 /**
33 * The view object
34 * @var TemplateView
35 */
36 protected $view;
37
38 /**
39 * The severity level
40 * @var int
41 */
42 protected $severity = AbstractMessage::ERROR;
43
44 /**
45 * Sets up the view
46 */
47 public function __construct()
48 {
49 $this->view = GeneralUtility::makeInstance(TemplateView::class);
50 $context = new RenderingContext($this->view);
51 $context->setControllerName('ErrorPage');
52 $context->setTemplatePaths(new TemplatePaths([
53 'templateRootPaths' => [
54 ExtensionManagementUtility::extPath('core', 'Resources/Private/Templates/ErrorPage/')
55 ]
56 ]));
57 $this->view->setRenderingContext($context);
58 }
59
60 /**
61 * Renders the view and returns the content
62 *
63 * @param string $title The title to be shown
64 * @param string $message The message to be shown
65 * @param int $severity The severity of the error, see AbstractMessage constants
66 * @param int $errorCode The error code to be referenced
67 * @return string the output of the view
68 */
69 public function errorAction(
70 string $title,
71 string $message,
72 int $severity = AbstractMessage::ERROR,
73 int $errorCode = 0): string
74 {
75 $this->severity = $severity;
76 $classes = [
77 AbstractMessage::NOTICE => 'notice',
78 AbstractMessage::INFO => 'information',
79 AbstractMessage::OK => 'ok',
80 AbstractMessage::WARNING => 'warning',
81 AbstractMessage::ERROR => 'error'
82 ];
83 $this->view->assign('severityCssClass', $classes[$this->severity]);
84 $this->view->assign('severity', $this->severity);
85 $this->view->assign('message', $message);
86 $this->view->assign('title', $title);
87 $this->view->assign('errorCodeUrlPrefix', TYPO3_URL_EXCEPTION);
88 $this->view->assign('errorCode', $errorCode);
89 $this->view->assign('logo', PathUtility::getAbsoluteWebPath(ExtensionManagementUtility::extPath('backend', 'Resources/Public/Images/typo3_orange.svg')));
90 $this->view->assign('cssFile', PathUtility::getAbsoluteWebPath(ExtensionManagementUtility::extPath('core', 'Resources/Public/Css/errorpage.css')));
91 $this->view->assign('copyrightYear', TYPO3_copyright_year);
92 return $this->view->render('Error');
93 }
94 }