ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
ErrorPageResponder.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ilUtil;
24use ilLanguage;
29use ILIAS\HTTP\Services as HTTPServices;
30use ILIAS\GlobalScreen\Services as GlobalScreenServices;
31
46{
47 public function __construct(
48 private readonly GlobalScreenServices $global_screen,
49 private readonly ilLanguage $language,
50 private readonly UIServices $ui,
51 private readonly HTTPServices $http
52 ) {
53 }
54
55 public function respond(
56 string $error_message,
57 int $status_code,
58 ?Link $back_target = null
59 ): void {
60 $this->global_screen->tool()->context()->claim()->external();
61 $this->language->loadLanguageModule('error');
62
63 $message_box = $this->ui->factory()->messageBox()->failure($error_message);
64
65 if ($back_target !== null) {
66 $ui_button = $this->ui->factory()->button()->standard(
67 $back_target->getLabel(),
68 ilUtil::secureUrl((string) $back_target->getURL())
69 );
70 $message_box = $message_box->withButtons([$ui_button]);
71 }
72
73 $local_tpl = new ilGlobalTemplate('tpl.error.html', true, true);
74 $local_tpl->setCurrentBlock('msg_box');
75 $local_tpl->setVariable(
76 'MESSAGE_BOX',
77 $this->ui->renderer()->render($message_box)
78 );
79 $local_tpl->parseCurrentBlock();
80
81 $this->http->saveResponse(
82 $this->http
83 ->response()
84 ->withStatus($status_code)
85 ->withHeader(ResponseHeader::CONTENT_TYPE, 'text/html')
86 );
87
88 $this->ui->mainTemplate()->setContent($local_tpl->get());
89 $this->ui->mainTemplate()->printToStdout();
90
91 $this->http->close();
92 }
93}
Provides fluid interface to RBAC services.
Definition: UIServices.php:25
Class Services.
Definition: Services.php:38
Responder that renders a full ILIAS error page (UI-Framework MessageBox) and sends it with the approp...
respond(string $error_message, int $status_code, ?Link $back_target=null)
__construct(private readonly GlobalScreenServices $global_screen, private readonly ilLanguage $language, private readonly UIServices $ui, private readonly HTTPServices $http)
$back_target
Definition: error.php:46
special template class to simplify handling of ITX/PEAR
language handling
Util class various functions, usage as namespace.
static secureUrl(string $url)
$http
Definition: deliver.php:30
Interface ResponseHeader.
static http()
Fetches the global http state from ILIAS.