]> git.mxchange.org Git - friendica.git/blob - src/App.php
Move DI dependency for App\Page class
[friendica.git] / src / App.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica;
23
24 use Exception;
25 use Friendica\App\Arguments;
26 use Friendica\App\BaseURL;
27 use Friendica\Capabilities\ICanCreateResponses;
28 use Friendica\Core\Config\Factory\Config;
29 use Friendica\Core\Session\Capability\IHandleSessions;
30 use Friendica\Core\Session\Capability\IHandleUserSessions;
31 use Friendica\Module\Maintenance;
32 use Friendica\Security\Authentication;
33 use Friendica\Core\Config\ValueObject\Cache;
34 use Friendica\Core\Config\Capability\IManageConfigValues;
35 use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
36 use Friendica\Core\L10n;
37 use Friendica\Core\System;
38 use Friendica\Core\Theme;
39 use Friendica\Database\Database;
40 use Friendica\Model\Contact;
41 use Friendica\Model\Profile;
42 use Friendica\Module\Special\HTTPException as ModuleHTTPException;
43 use Friendica\Network\HTTPException;
44 use Friendica\Util\DateTimeFormat;
45 use Friendica\Util\HTTPInputData;
46 use Friendica\Util\HTTPSignature;
47 use Friendica\Util\Profiler;
48 use Friendica\Util\Strings;
49 use Psr\Log\LoggerInterface;
50
51 /**
52  * Our main application structure for the life of this page.
53  *
54  * Primarily deals with the URL that got us here
55  * and tries to make some sense of it, and
56  * stores our page contents and config storage
57  * and anything else that might need to be passed around
58  * before we spit the page out.
59  *
60  */
61 class App
62 {
63         const PLATFORM = 'Friendica';
64         const CODENAME = 'Giant Rhubarb';
65         const VERSION  = '2022.12-dev';
66
67         // Allow themes to control internal parameters
68         // by changing App values in theme.php
69         private $theme_info = [
70                 'videowidth'        => 425,
71                 'videoheight'       => 350,
72                 'events_in_profile' => true
73         ];
74
75         private $user_id       = 0;
76         private $nickname      = '';
77         private $timezone      = '';
78         private $profile_owner = 0;
79         private $contact_id    = 0;
80         private $queue         = [];
81
82         /**
83          * @var App\Mode The Mode of the Application
84          */
85         private $mode;
86
87         /**
88          * @var BaseURL
89          */
90         private $baseURL;
91
92         /** @var string The name of the current theme */
93         private $currentTheme;
94         /** @var string The name of the current mobile theme */
95         private $currentMobileTheme;
96
97         /**
98          * @var IManageConfigValues The config
99          */
100         private $config;
101
102         /**
103          * @var LoggerInterface The logger
104          */
105         private $logger;
106
107         /**
108          * @var Profiler The profiler of this app
109          */
110         private $profiler;
111
112         /**
113          * @var Database The Friendica database connection
114          */
115         private $database;
116
117         /**
118          * @var L10n The translator
119          */
120         private $l10n;
121
122         /**
123          * @var App\Arguments
124          */
125         private $args;
126
127         /**
128          * @var IManagePersonalConfigValues
129          */
130         private $pConfig;
131
132         /**
133          * @var IHandleSessions
134          */
135         private $session;
136
137         /**
138          * Set the user ID
139          *
140          * @param int $user_id
141          * @return void
142          */
143         public function setLoggedInUserId(int $user_id)
144         {
145                 $this->user_id = $user_id;
146         }
147
148         /**
149          * Set the nickname
150          *
151          * @param int $user_id
152          * @return void
153          */
154         public function setLoggedInUserNickname(string $nickname)
155         {
156                 $this->nickname = $nickname;
157         }
158
159         public function isLoggedIn(): bool
160         {
161                 return DI::userSession()->getLocalUserId() && $this->user_id && ($this->user_id == DI::userSession()->getLocalUserId());
162         }
163
164         /**
165          * Check if current user has admin role.
166          *
167          * @return bool true if user is an admin
168          */
169         public function isSiteAdmin(): bool
170         {
171                 $admin_email = $this->config->get('config', 'admin_email');
172
173                 $adminlist = explode(',', str_replace(' ', '', $admin_email));
174
175                 return DI::userSession()->getLocalUserId() && $admin_email && $this->database->exists('user', ['uid' => $this->getLoggedInUserId(), 'email' => $adminlist]);
176         }
177
178         /**
179          * Fetch the user id
180          * @return int User id
181          */
182         public function getLoggedInUserId(): int
183         {
184                 return $this->user_id;
185         }
186
187         /**
188          * Fetch the user nick name
189          * @return string User's nickname
190          */
191         public function getLoggedInUserNickname(): string
192         {
193                 return $this->nickname;
194         }
195
196         /**
197          * Set the profile owner ID
198          *
199          * @param int $owner_id
200          * @return void
201          */
202         public function setProfileOwner(int $owner_id)
203         {
204                 $this->profile_owner = $owner_id;
205         }
206
207         /**
208          * Get the profile owner ID
209          *
210          * @return int
211          */
212         public function getProfileOwner(): int
213         {
214                 return $this->profile_owner;
215         }
216
217         /**
218          * Set the contact ID
219          *
220          * @param int $contact_id
221          * @return void
222          */
223         public function setContactId(int $contact_id)
224         {
225                 $this->contact_id = $contact_id;
226         }
227
228         /**
229          * Get the contact ID
230          *
231          * @return int
232          */
233         public function getContactId(): int
234         {
235                 return $this->contact_id;
236         }
237
238         /**
239          * Set the timezone
240          *
241          * @param string $timezone A valid time zone identifier, see https://www.php.net/manual/en/timezones.php
242          * @return void
243          */
244         public function setTimeZone(string $timezone)
245         {
246                 $this->timezone = (new \DateTimeZone($timezone))->getName();
247                 DateTimeFormat::setLocalTimeZone($this->timezone);
248         }
249
250         /**
251          * Get the timezone
252          *
253          * @return int
254          */
255         public function getTimeZone(): string
256         {
257                 return $this->timezone;
258         }
259
260         /**
261          * Set workerqueue information
262          *
263          * @param array $queue 
264          * @return void 
265          */
266         public function setQueue(array $queue)
267         {
268                 $this->queue = $queue;
269         }
270
271         /**
272          * Fetch workerqueue information
273          *
274          * @return array Worker queue
275          */
276         public function getQueue(): array
277         {
278                 return $this->queue ?? [];
279         }
280
281         /**
282          * Fetch a specific workerqueue field
283          *
284          * @param string $index Work queue record to fetch
285          * @return mixed Work queue item or NULL if not found
286          */
287         public function getQueueValue(string $index)
288         {
289                 return $this->queue[$index] ?? null;
290         }
291
292         public function setThemeInfoValue(string $index, $value)
293         {
294                 $this->theme_info[$index] = $value;
295         }
296
297         public function getThemeInfo()
298         {
299                 return $this->theme_info;
300         }
301
302         public function getThemeInfoValue(string $index, $default = null)
303         {
304                 return $this->theme_info[$index] ?? $default;
305         }
306
307         /**
308          * Returns the current config cache of this node
309          *
310          * @return Cache
311          */
312         public function getConfigCache()
313         {
314                 return $this->config->getCache();
315         }
316
317         /**
318          * The basepath of this app
319          *
320          * @return string Base path from configuration
321          */
322         public function getBasePath(): string
323         {
324                 // Don't use the basepath of the config table for basepath (it should always be the config-file one)
325                 return $this->config->getCache()->get('system', 'basepath');
326         }
327
328         /**
329          * @param Database                    $database The Friendica Database
330          * @param IManageConfigValues         $config   The Configuration
331          * @param App\Mode                    $mode     The mode of this Friendica app
332          * @param BaseURL                     $baseURL  The full base URL of this Friendica app
333          * @param LoggerInterface             $logger   The current app logger
334          * @param Profiler                    $profiler The profiler of this application
335          * @param L10n                        $l10n     The translator instance
336          * @param App\Arguments               $args     The Friendica Arguments of the call
337          * @param IManagePersonalConfigValues $pConfig  Personal configuration
338          * @param IHandleSessions             $session  The Session handler
339          */
340         public function __construct(Database $database, IManageConfigValues $config, App\Mode $mode, BaseURL $baseURL, LoggerInterface $logger, Profiler $profiler, L10n $l10n, Arguments $args, IManagePersonalConfigValues $pConfig, IHandleSessions $session)
341         {
342                 $this->database = $database;
343                 $this->config   = $config;
344                 $this->mode     = $mode;
345                 $this->baseURL  = $baseURL;
346                 $this->profiler = $profiler;
347                 $this->logger   = $logger;
348                 $this->l10n     = $l10n;
349                 $this->args     = $args;
350                 $this->pConfig  = $pConfig;
351                 $this->session  = $session;
352
353                 $this->load();
354         }
355
356         /**
357          * Load the whole app instance
358          */
359         public function load()
360         {
361                 set_time_limit(0);
362
363                 // Normally this constant is defined - but not if "pcntl" isn't installed
364                 if (!defined('SIGTERM')) {
365                         define('SIGTERM', 15);
366                 }
367
368                 // Ensure that all "strtotime" operations do run timezone independent
369                 date_default_timezone_set('UTC');
370
371                 // This has to be quite large to deal with embedded private photos
372                 ini_set('pcre.backtrack_limit', 500000);
373
374                 set_include_path(
375                         get_include_path() . PATH_SEPARATOR
376                         . $this->getBasePath() . DIRECTORY_SEPARATOR . 'include' . PATH_SEPARATOR
377                         . $this->getBasePath() . DIRECTORY_SEPARATOR . 'library' . PATH_SEPARATOR
378                         . $this->getBasePath());
379
380                 $this->profiler->reset();
381
382                 if ($this->mode->has(App\Mode::DBAVAILABLE)) {
383                         $this->profiler->update($this->config);
384
385                         Core\Hook::loadHooks();
386                         $loader = (new Config())->createConfigFileLoader($this->getBasePath(), $_SERVER);
387                         Core\Hook::callAll('load_config', $loader);
388                 }
389
390                 $this->loadDefaultTimezone();
391                 // Register template engines
392                 Core\Renderer::registerTemplateEngine('Friendica\Render\FriendicaSmartyEngine');
393         }
394
395         /**
396          * Loads the default timezone
397          *
398          * Include support for legacy $default_timezone
399          *
400          * @global string $default_timezone
401          */
402         private function loadDefaultTimezone()
403         {
404                 if ($this->config->get('system', 'default_timezone')) {
405                         $timezone = $this->config->get('system', 'default_timezone', 'UTC');
406                 } else {
407                         global $default_timezone;
408                         $timezone = $default_timezone ?? '' ?: 'UTC';
409                 }
410
411                 $this->setTimeZone($timezone);
412         }
413
414         /**
415          * Returns the current theme name. May be overriden by the mobile theme name.
416          *
417          * @return string Current theme name or empty string in installation phase
418          * @throws Exception
419          */
420         public function getCurrentTheme(): string
421         {
422                 if ($this->mode->isInstall()) {
423                         return '';
424                 }
425
426                 // Specific mobile theme override
427                 if (($this->mode->isMobile() || $this->mode->isTablet()) && $this->session->get('show-mobile', true)) {
428                         $user_mobile_theme = $this->getCurrentMobileTheme();
429
430                         // --- means same mobile theme as desktop
431                         if (!empty($user_mobile_theme) && $user_mobile_theme !== '---') {
432                                 return $user_mobile_theme;
433                         }
434                 }
435
436                 if (!$this->currentTheme) {
437                         $this->computeCurrentTheme();
438                 }
439
440                 return $this->currentTheme;
441         }
442
443         /**
444          * Returns the current mobile theme name.
445          *
446          * @return string Mobile theme name or empty string if installer
447          * @throws Exception
448          */
449         public function getCurrentMobileTheme(): string
450         {
451                 if ($this->mode->isInstall()) {
452                         return '';
453                 }
454
455                 if (is_null($this->currentMobileTheme)) {
456                         $this->computeCurrentMobileTheme();
457                 }
458
459                 return $this->currentMobileTheme;
460         }
461
462         /**
463          * Setter for current theme name
464          *
465          * @param string $theme Name of current theme
466          */
467         public function setCurrentTheme(string $theme)
468         {
469                 $this->currentTheme = $theme;
470         }
471
472         /**
473          * Setter for current mobile theme name
474          *
475          * @param string $theme Name of current mobile theme
476          */
477         public function setCurrentMobileTheme(string $theme)
478         {
479                 $this->currentMobileTheme = $theme;
480         }
481
482         /**
483          * Computes the current theme name based on the node settings, the page owner settings and the user settings
484          *
485          * @throws Exception
486          */
487         private function computeCurrentTheme()
488         {
489                 $system_theme = $this->config->get('system', 'theme');
490                 if (!$system_theme) {
491                         throw new Exception($this->l10n->t('No system theme config value set.'));
492                 }
493
494                 // Sane default
495                 $this->setCurrentTheme($system_theme);
496
497                 $page_theme = null;
498                 // Find the theme that belongs to the user whose stuff we are looking at
499                 if (!empty($this->profile_owner) && ($this->profile_owner != DI::userSession()->getLocalUserId())) {
500                         // Allow folks to override user themes and always use their own on their own site.
501                         // This works only if the user is on the same server
502                         $user = $this->database->selectFirst('user', ['theme'], ['uid' => $this->profile_owner]);
503                         if ($this->database->isResult($user) && !DI::userSession()->getLocalUserId()) {
504                                 $page_theme = $user['theme'];
505                         }
506                 }
507
508                 $theme_name = $page_theme ?: $this->session->get('theme', $system_theme);
509
510                 $theme_name = Strings::sanitizeFilePathItem($theme_name);
511                 if ($theme_name
512                     && in_array($theme_name, Theme::getAllowedList())
513                     && (file_exists('view/theme/' . $theme_name . '/style.css')
514                         || file_exists('view/theme/' . $theme_name . '/style.php'))
515                 ) {
516                         $this->setCurrentTheme($theme_name);
517                 }
518         }
519
520         /**
521          * Computes the current mobile theme name based on the node settings, the page owner settings and the user settings
522          */
523         private function computeCurrentMobileTheme()
524         {
525                 $system_mobile_theme = $this->config->get('system', 'mobile-theme', '');
526
527                 // Sane default
528                 $this->setCurrentMobileTheme($system_mobile_theme);
529
530                 $page_mobile_theme = null;
531                 // Find the theme that belongs to the user whose stuff we are looking at
532                 if (!empty($this->profile_owner) && ($this->profile_owner != DI::userSession()->getLocalUserId())) {
533                         // Allow folks to override user themes and always use their own on their own site.
534                         // This works only if the user is on the same server
535                         if (!DI::userSession()->getLocalUserId()) {
536                                 $page_mobile_theme = $this->pConfig->get($this->profile_owner, 'system', 'mobile-theme');
537                         }
538                 }
539
540                 $mobile_theme_name = $page_mobile_theme ?: $this->session->get('mobile-theme', $system_mobile_theme);
541
542                 $mobile_theme_name = Strings::sanitizeFilePathItem($mobile_theme_name);
543                 if ($mobile_theme_name == '---'
544                         ||
545                         in_array($mobile_theme_name, Theme::getAllowedList())
546                         && (file_exists('view/theme/' . $mobile_theme_name . '/style.css')
547                                 || file_exists('view/theme/' . $mobile_theme_name . '/style.php'))
548                 ) {
549                         $this->setCurrentMobileTheme($mobile_theme_name);
550                 }
551         }
552
553         /**
554          * Provide a sane default if nothing is chosen or the specified theme does not exist.
555          *
556          * @return string Current theme's stylsheet path
557          * @throws Exception
558          */
559         public function getCurrentThemeStylesheetPath(): string
560         {
561                 return Core\Theme::getStylesheetPath($this->getCurrentTheme());
562         }
563
564         /**
565          * Sets the base url for use in cmdline programs which don't have
566          * $_SERVER variables
567          */
568         public function checkURL()
569         {
570                 $url = $this->config->get('system', 'url');
571
572                 // if the url isn't set or the stored url is radically different
573                 // than the currently visited url, store the current value accordingly.
574                 // "Radically different" ignores common variations such as http vs https
575                 // and www.example.com vs example.com.
576                 // We will only change the url to an ip address if there is no existing setting
577
578                 if (empty($url) || (!Util\Strings::compareLink($url, $this->baseURL->get())) && (!preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/", $this->baseURL->getHostname()))) {
579                         $this->config->set('system', 'url', $this->baseURL->get());
580                 }
581         }
582
583         /**
584          * Frontend App script
585          *
586          * The App object behaves like a container and a dispatcher at the same time, including a representation of the
587          * request and a representation of the response.
588          *
589          * This probably should change to limit the size of this monster method.
590          *
591          * @param App\Router                  $router
592          * @param IManagePersonalConfigValues $pconfig
593          * @param Authentication              $auth       The Authentication backend of the node
594          * @param App\Page                    $page       The Friendica page printing container
595          * @param HTTPInputData               $httpInput  A library for processing PHP input streams
596          * @param IHandleUserSessions         $userSessions The UserSession class
597          * @param float                       $start_time The start time of the overall script execution
598          *
599          * @throws HTTPException\InternalServerErrorException
600          * @throws \ImagickException
601          */
602         public function runFrontend(App\Router $router, IManagePersonalConfigValues $pconfig, Authentication $auth, App\Page $page, HTTPInputData $httpInput, IHandleUserSessions $userSessions, float $start_time)
603         {
604                 $this->profiler->set($start_time, 'start');
605                 $this->profiler->set(microtime(true), 'classinit');
606
607                 $moduleName = $this->args->getModuleName();
608                 $page->setLogging($this->args->getMethod(), $this->args->getModuleName(), $this->args->getCommand());
609
610                 try {
611                         // Missing DB connection: ERROR
612                         if ($this->mode->has(App\Mode::LOCALCONFIGPRESENT) && !$this->mode->has(App\Mode::DBAVAILABLE)) {
613                                 throw new HTTPException\InternalServerErrorException($this->l10n->t('Apologies but the website is unavailable at the moment.'));
614                         }
615
616                         if (!$this->mode->isInstall()) {
617                                 // Force SSL redirection
618                                 if ($this->baseURL->checkRedirectHttps()) {
619                                         System::externalRedirect($this->baseURL->get() . '/' . $this->args->getQueryString());
620                                 }
621
622                                 Core\Hook::callAll('init_1');
623                         }
624
625                         if ($this->mode->isNormal() && !$this->mode->isBackend()) {
626                                 $requester = HTTPSignature::getSigner('', $_SERVER);
627                                 if (!empty($requester)) {
628                                         Profile::addVisitorCookieForHandle($requester);
629                                 }
630                         }
631
632                         // ZRL
633                         if (!empty($_GET['zrl']) && $this->mode->isNormal() && !$this->mode->isBackend() && !DI::userSession()->getLocalUserId()) {
634                                 // Only continue when the given profile link seems valid
635                                 // Valid profile links contain a path with "/profile/" and no query parameters
636                                 if ((parse_url($_GET['zrl'], PHP_URL_QUERY) == '') &&
637                                         strstr(parse_url($_GET['zrl'], PHP_URL_PATH), '/profile/')) {
638                                         if ($this->session->get('visitor_home') != $_GET['zrl']) {
639                                                 $this->session->set('my_url', $_GET['zrl']);
640                                                 $this->session->set('authenticated', 0);
641
642                                                 $remote_contact = Contact::getByURL($_GET['zrl'], false, ['subscribe']);
643                                                 if (!empty($remote_contact['subscribe'])) {
644                                                         $_SESSION['remote_comment'] = $remote_contact['subscribe'];
645                                                 }
646                                         }
647
648                                         Model\Profile::zrlInit($this);
649                                 } else {
650                                         // Someone came with an invalid parameter, maybe as a DDoS attempt
651                                         // We simply stop processing here
652                                         $this->logger->debug('Invalid ZRL parameter.', ['zrl' => $_GET['zrl']]);
653                                         throw new HTTPException\ForbiddenException();
654                                 }
655                         }
656
657                         if (!empty($_GET['owt']) && $this->mode->isNormal()) {
658                                 $token = $_GET['owt'];
659                                 Model\Profile::openWebAuthInit($token);
660                         }
661
662                         if (!$this->mode->isBackend()) {
663                                 $auth->withSession($this);
664                         }
665
666                         if (empty($_SESSION['authenticated'])) {
667                                 header('X-Account-Management-Status: none');
668                         }
669
670                         /*
671                          * check_config() is responsible for running update scripts. These automatically
672                          * update the DB schema whenever we push a new one out. It also checks to see if
673                          * any addons have been added or removed and reacts accordingly.
674                          */
675
676                         // in install mode, any url loads install module
677                         // but we need "view" module for stylesheet
678                         if ($this->mode->isInstall() && $moduleName !== 'install') {
679                                 $this->baseURL->redirect('install');
680                         } else {
681                                 $this->checkURL();
682                                 Core\Update::check($this->getBasePath(), false, $this->mode);
683                                 Core\Addon::loadAddons();
684                                 Core\Hook::loadHooks();
685                         }
686
687                         // Compatibility with the Android Diaspora client
688                         if ($moduleName == 'stream') {
689                                 $this->baseURL->redirect('network?order=post');
690                         }
691
692                         if ($moduleName == 'conversations') {
693                                 $this->baseURL->redirect('message');
694                         }
695
696                         if ($moduleName == 'commented') {
697                                 $this->baseURL->redirect('network?order=comment');
698                         }
699
700                         if ($moduleName == 'liked') {
701                                 $this->baseURL->redirect('network?order=comment');
702                         }
703
704                         if ($moduleName == 'activity') {
705                                 $this->baseURL->redirect('network?conv=1');
706                         }
707
708                         if (($moduleName == 'status_messages') && ($this->args->getCommand() == 'status_messages/new')) {
709                                 $this->baseURL->redirect('bookmarklet');
710                         }
711
712                         if (($moduleName == 'user') && ($this->args->getCommand() == 'user/edit')) {
713                                 $this->baseURL->redirect('settings');
714                         }
715
716                         if (($moduleName == 'tag_followings') && ($this->args->getCommand() == 'tag_followings/manage')) {
717                                 $this->baseURL->redirect('search');
718                         }
719
720                         // Initialize module that can set the current theme in the init() method, either directly or via App->setProfileOwner
721                         $page['page_title'] = $moduleName;
722
723                         // The "view" module is required to show the theme CSS
724                         if (!$this->mode->isInstall() && !$this->mode->has(App\Mode::MAINTENANCEDISABLED) && $moduleName !== 'view') {
725                                 $module = $router->getModule(Maintenance::class);
726                         } else {
727                                 // determine the module class and save it to the module instance
728                                 // @todo there's an implicit dependency due SESSION::start(), so it has to be called here (yet)
729                                 $module = $router->getModule();
730                         }
731
732                         // Processes data from GET requests
733                         $httpinput = $httpInput->process();
734                         $input     = array_merge($httpinput['variables'], $httpinput['files'], $request ?? $_REQUEST);
735
736                         // Let the module run it's internal process (init, get, post, ...)
737                         $timestamp = microtime(true);
738                         $response = $module->run($input);
739                         $this->profiler->set(microtime(true) - $timestamp, 'content');
740                         if ($response->getHeaderLine(ICanCreateResponses::X_HEADER) === ICanCreateResponses::TYPE_HTML) {
741                                 $page->run($this, $this->baseURL, $this->args, $this->mode, $response, $this->l10n, $this->profiler, $this->config, $pconfig, $userSessions->getLocalUserId());
742                         } else {
743                                 $page->exit($response);
744                         }
745                 } catch (HTTPException $e) {
746                         (new ModuleHTTPException())->rawContent($e);
747                 }
748                 $page->logRuntime($this->config, 'runFrontend');
749         }
750
751         /**
752          * Automatically redirects to relative or absolute URL
753          * Should only be used if it isn't clear if the URL is either internal or external
754          *
755          * @param string $toUrl The target URL
756          *
757          * @throws HTTPException\InternalServerErrorException
758          */
759         public function redirect(string $toUrl)
760         {
761                 if (!empty(parse_url($toUrl, PHP_URL_SCHEME))) {
762                         Core\System::externalRedirect($toUrl);
763                 } else {
764                         $this->baseURL->redirect($toUrl);
765                 }
766         }
767 }