]> git.mxchange.org Git - friendica.git/blob - src/App.php
Refactor dynamic App::getProfiler() to static DI::profiler()
[friendica.git] / src / App.php
1 <?php
2 /**
3  * @file src/App.php
4  */
5 namespace Friendica;
6
7 use Exception;
8 use Friendica\App\Arguments;
9 use Friendica\App\BaseURL;
10 use Friendica\App\Page;
11 use Friendica\App\Authentication;
12 use Friendica\Core\Config\Cache\ConfigCache;
13 use Friendica\Core\Config\Configuration;
14 use Friendica\Core\Config\PConfiguration;
15 use Friendica\Core\L10n\L10n;
16 use Friendica\Core\Session;
17 use Friendica\Core\System;
18 use Friendica\Core\Theme;
19 use Friendica\Database\Database;
20 use Friendica\Model\Profile;
21 use Friendica\Module\Security\Login;
22 use Friendica\Module\Special\HTTPException as ModuleHTTPException;
23 use Friendica\Network\HTTPException;
24 use Friendica\Util\ConfigFileLoader;
25 use Friendica\Util\HTTPSignature;
26 use Friendica\Util\Profiler;
27 use Friendica\Util\Strings;
28 use Psr\Log\LoggerInterface;
29
30 /**
31  *
32  * class: App
33  *
34  * @brief Our main application structure for the life of this page.
35  *
36  * Primarily deals with the URL that got us here
37  * and tries to make some sense of it, and
38  * stores our page contents and config storage
39  * and anything else that might need to be passed around
40  * before we spit the page out.
41  *
42  */
43 class App
44 {
45         /** @deprecated 2019.09 - use App\Arguments->getQueryString() */
46         public $query_string;
47         /**
48          * @var Page The current page environment
49          */
50         public $page;
51         public $profile;
52         public $profile_uid;
53         public $user;
54         public $cid;
55         public $contact;
56         public $contacts;
57         public $page_contact;
58         public $content;
59         public $data = [];
60         /** @deprecated 2019.09 - use App\Arguments->getCommand() */
61         public $cmd = '';
62         /** @deprecated 2019.09 - use App\Arguments->getArgv() or Arguments->get() */
63         public $argv;
64         /** @deprecated 2019.09 - use App\Arguments->getArgc() */
65         public $argc;
66         /** @deprecated 2019.09 - Use App\Module->getName() instead */
67         public $module;
68         public $timezone;
69         public $interactive = true;
70         public $identities;
71         /** @deprecated 2019.09 - Use App\Mode->isMobile() instead */
72         public $is_mobile;
73         /** @deprecated 2019.09 - Use App\Mode->isTable() instead */
74         public $is_tablet;
75         public $theme_info = [];
76         public $category;
77         // Allow themes to control internal parameters
78         // by changing App values in theme.php
79
80         public $sourcename              = '';
81         public $videowidth              = 425;
82         public $videoheight             = 350;
83         public $force_max_items         = 0;
84         public $theme_events_in_profile = true;
85         public $queue;
86
87         /**
88          * @var App\Mode The Mode of the Application
89          */
90         private $mode;
91
92         /**
93          * @var BaseURL
94          */
95         private $baseURL;
96
97         /** @var string The name of the current theme */
98         private $currentTheme;
99         /** @var string The name of the current mobile theme */
100         private $currentMobileTheme;
101
102         /**
103          * @var Configuration The config
104          */
105         private $config;
106
107         /**
108          * @var LoggerInterface The logger
109          */
110         private $logger;
111
112         /**
113          * @var Profiler The profiler of this app
114          */
115         private $profiler;
116
117         /**
118          * @var Database The Friendica database connection
119          */
120         private $database;
121
122         /**
123          * @var L10n The translator
124          */
125         private $l10n;
126
127         /**
128          * @var App\Arguments
129          */
130         private $args;
131
132         /**
133          * @var Core\Process The process methods
134          */
135         private $process;
136
137         /**
138          * Returns the current config cache of this node
139          *
140          * @return ConfigCache
141          */
142         public function getConfigCache()
143         {
144                 return $this->config->getCache();
145         }
146
147         /**
148          * The basepath of this app
149          *
150          * @return string
151          */
152         public function getBasePath()
153         {
154                 // Don't use the basepath of the config table for basepath (it should always be the config-file one)
155                 return $this->config->getCache()->get('system', 'basepath');
156         }
157
158         /**
159          * Returns the Mode of the Application
160          *
161          * @return App\Mode The Application Mode
162          */
163         public function getMode()
164         {
165                 return $this->mode;
166         }
167
168         /**
169          * Returns the Database of the Application
170          *
171          * @return Database
172          */
173         public function getDBA()
174         {
175                 return $this->database;
176         }
177
178         /**
179          * @deprecated 2019.09 - use Page->registerStylesheet instead
180          * @see        Page::registerStylesheet()
181          */
182         public function registerStylesheet($path)
183         {
184                 $this->page->registerStylesheet($path);
185         }
186
187         /**
188          * @deprecated 2019.09 - use Page->registerFooterScript instead
189          * @see        Page::registerFooterScript()
190          */
191         public function registerFooterScript($path)
192         {
193                 $this->page->registerFooterScript($path);
194         }
195
196         /**
197          * @param Database        $database The Friendica Database
198          * @param Configuration   $config   The Configuration
199          * @param App\Mode        $mode     The mode of this Friendica app
200          * @param BaseURL         $baseURL  The full base URL of this Friendica app
201          * @param LoggerInterface $logger   The current app logger
202          * @param Profiler        $profiler The profiler of this application
203          * @param L10n            $l10n     The translator instance
204          * @param App\Arguments   $args     The Friendica Arguments of the call
205          * @param Core\Process    $process  The process methods
206          */
207         public function __construct(Database $database, Configuration $config, App\Mode $mode, BaseURL $baseURL, LoggerInterface $logger, Profiler $profiler, L10n $l10n, Arguments $args, App\Module $module, App\Page $page, Core\Process $process)
208         {
209                 $this->database = $database;
210                 $this->config   = $config;
211                 $this->mode     = $mode;
212                 $this->baseURL  = $baseURL;
213                 $this->profiler = $profiler;
214                 $this->logger   = $logger;
215                 $this->l10n     = $l10n;
216                 $this->args     = $args;
217                 $this->process  = $process;
218
219                 $this->cmd          = $args->getCommand();
220                 $this->argv         = $args->getArgv();
221                 $this->argc         = $args->getArgc();
222                 $this->query_string = $args->getQueryString();
223                 $this->module       = $module->getName();
224                 $this->page         = $page;
225
226                 $this->is_mobile = $mode->isMobile();
227                 $this->is_tablet = $mode->isTablet();
228
229                 $this->load();
230         }
231
232         /**
233          * Load the whole app instance
234          */
235         public function load()
236         {
237                 set_time_limit(0);
238
239                 // This has to be quite large to deal with embedded private photos
240                 ini_set('pcre.backtrack_limit', 500000);
241
242                 set_include_path(
243                         get_include_path() . PATH_SEPARATOR
244                         . $this->getBasePath() . DIRECTORY_SEPARATOR . 'include' . PATH_SEPARATOR
245                         . $this->getBasePath() . DIRECTORY_SEPARATOR . 'library' . PATH_SEPARATOR
246                         . $this->getBasePath());
247
248                 $this->profiler->reset();
249
250                 if ($this->mode->has(App\Mode::DBAVAILABLE)) {
251                         $this->profiler->update($this->config);
252
253                         Core\Hook::loadHooks();
254                         $loader = new ConfigFileLoader($this->getBasePath());
255                         Core\Hook::callAll('load_config', $loader);
256                 }
257
258                 $this->loadDefaultTimezone();
259                 // Register template engines
260                 Core\Renderer::registerTemplateEngine('Friendica\Render\FriendicaSmartyEngine');
261         }
262
263         /**
264          * Loads the default timezone
265          *
266          * Include support for legacy $default_timezone
267          *
268          * @global string $default_timezone
269          */
270         private function loadDefaultTimezone()
271         {
272                 if ($this->config->get('system', 'default_timezone')) {
273                         $this->timezone = $this->config->get('system', 'default_timezone');
274                 } else {
275                         global $default_timezone;
276                         $this->timezone = !empty($default_timezone) ? $default_timezone : 'UTC';
277                 }
278
279                 if ($this->timezone) {
280                         date_default_timezone_set($this->timezone);
281                 }
282         }
283
284         /**
285          * Returns the scheme of the current call
286          *
287          * @return string
288          *
289          * @deprecated 2019.06 - use BaseURL->getScheme() instead
290          */
291         public function getScheme()
292         {
293                 return $this->baseURL->getScheme();
294         }
295
296         /**
297          * Retrieves the Friendica instance base URL
298          *
299          * @param bool $ssl Whether to append http or https under BaseURL::SSL_POLICY_SELFSIGN
300          *
301          * @return string Friendica server base URL
302          *
303          * @deprecated 2019.09 - use BaseUrl->get($ssl) instead
304          */
305         public function getBaseURL($ssl = false)
306         {
307                 return $this->baseURL->get($ssl);
308         }
309
310         /**
311          * @brief      Initializes the baseurl components
312          *
313          * Clears the baseurl cache to prevent inconsistencies
314          *
315          * @param string $url
316          *
317          * @deprecated 2019.06 - use BaseURL->saveByURL($url) instead
318          */
319         public function setBaseURL($url)
320         {
321                 $this->baseURL->saveByURL($url);
322         }
323
324         /**
325          * Returns the current hostname
326          *
327          * @return string
328          *
329          * @deprecated 2019.06 - use BaseURL->getHostname() instead
330          */
331         public function getHostName()
332         {
333                 return $this->baseURL->getHostname();
334         }
335
336         /**
337          * Returns the sub-path of the full URL
338          *
339          * @return string
340          *
341          * @deprecated 2019.06 - use BaseURL->getUrlPath() instead
342          */
343         public function getURLPath()
344         {
345                 return $this->baseURL->getUrlPath();
346         }
347
348         /**
349          * @brief      Removes the base url from an url. This avoids some mixed content problems.
350          *
351          * @param string $origURL
352          *
353          * @return string The cleaned url
354          *
355          * @deprecated 2019.09 - Use BaseURL->remove() instead
356          * @see        BaseURL::remove()
357          */
358         public function removeBaseURL(string $origURL)
359         {
360                 return $this->baseURL->remove($origURL);
361         }
362
363         /**
364          * Returns the current UserAgent as a String
365          *
366          * @return string the UserAgent as a String
367          * @throws HTTPException\InternalServerErrorException
368          */
369         public function getUserAgent()
370         {
371                 return
372                         FRIENDICA_PLATFORM . " '" .
373                         FRIENDICA_CODENAME . "' " .
374                         FRIENDICA_VERSION . '-' .
375                         DB_UPDATE_VERSION . '; ' .
376                         $this->getBaseURL();
377         }
378
379         /**
380          * @deprecated 2019.09 - use Core\Process->isMaxProcessesReached() instead
381          */
382         public function isMaxProcessesReached()
383         {
384                 return $this->process->isMaxProcessesReached();
385         }
386
387         /**
388          * @deprecated 2019.09 - use Core\Process->isMinMemoryReached() instead
389          */
390         public function isMinMemoryReached()
391         {
392                 return $this->process->isMinMemoryReached();
393         }
394
395         /**
396          * @deprecated 2019.09 - use Core\Process->isMaxLoadReached() instead
397          */
398         public function isMaxLoadReached()
399         {
400                 return $this->process->isMaxLoadReached();
401         }
402
403         /**
404          * Generates the site's default sender email address
405          *
406          * @return string
407          * @throws HTTPException\InternalServerErrorException
408          */
409         public function getSenderEmailAddress()
410         {
411                 $sender_email = $this->config->get('config', 'sender_email');
412                 if (empty($sender_email)) {
413                         $hostname = $this->baseURL->getHostname();
414                         if (strpos($hostname, ':')) {
415                                 $hostname = substr($hostname, 0, strpos($hostname, ':'));
416                         }
417
418                         $sender_email = 'noreply@' . $hostname;
419                 }
420
421                 return $sender_email;
422         }
423
424         /**
425          * Returns the current theme name. May be overriden by the mobile theme name.
426          *
427          * @return string
428          * @throws Exception
429          */
430         public function getCurrentTheme()
431         {
432                 if ($this->mode->isInstall()) {
433                         return '';
434                 }
435
436                 // Specific mobile theme override
437                 if (($this->mode->isMobile() || $this->mode->isTablet()) && Core\Session::get('show-mobile', true)) {
438                         $user_mobile_theme = $this->getCurrentMobileTheme();
439
440                         // --- means same mobile theme as desktop
441                         if (!empty($user_mobile_theme) && $user_mobile_theme !== '---') {
442                                 return $user_mobile_theme;
443                         }
444                 }
445
446                 if (!$this->currentTheme) {
447                         $this->computeCurrentTheme();
448                 }
449
450                 return $this->currentTheme;
451         }
452
453         /**
454          * Returns the current mobile theme name.
455          *
456          * @return string
457          * @throws Exception
458          */
459         public function getCurrentMobileTheme()
460         {
461                 if ($this->mode->isInstall()) {
462                         return '';
463                 }
464
465                 if (is_null($this->currentMobileTheme)) {
466                         $this->computeCurrentMobileTheme();
467                 }
468
469                 return $this->currentMobileTheme;
470         }
471
472         public function setCurrentTheme($theme)
473         {
474                 $this->currentTheme = $theme;
475         }
476
477         public function setCurrentMobileTheme($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 ($this->profile_uid && ($this->profile_uid != local_user())) {
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_uid]);
503                         if ($this->database->isResult($user) && !Core\PConfig::get(local_user(), 'system', 'always_my_theme')) {
504                                 $page_theme = $user['theme'];
505                         }
506                 }
507
508                 $theme_name = $page_theme ?: Core\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 ($this->profile_uid && ($this->profile_uid != local_user())) {
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 (!Core\PConfig::get(local_user(), 'system', 'always_my_theme')) {
536                                 $page_mobile_theme = Core\PConfig::get($this->profile_uid, 'system', 'mobile-theme');
537                         }
538                 }
539
540                 $mobile_theme_name = $page_mobile_theme ?: Core\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          * @brief Return full URL to theme which is currently in effect.
555          *
556          * Provide a sane default if nothing is chosen or the specified theme does not exist.
557          *
558          * @return string
559          * @throws Exception
560          */
561         public function getCurrentThemeStylesheetPath()
562         {
563                 return Core\Theme::getStylesheetPath($this->getCurrentTheme());
564         }
565
566         /**
567          * @deprecated 2019.09 - use App\Mode->isAjax() instead
568          * @see        App\Mode::isAjax()
569          */
570         public function isAjax()
571         {
572                 return $this->mode->isAjax();
573         }
574
575         /**
576          * @deprecated use Arguments->get() instead
577          *
578          * @see        App\Arguments
579          */
580         public function getArgumentValue($position, $default = '')
581         {
582                 return $this->args->get($position, $default);
583         }
584
585         /**
586          * Sets the base url for use in cmdline programs which don't have
587          * $_SERVER variables
588          */
589         public function checkURL()
590         {
591                 $url = $this->config->get('system', 'url');
592
593                 // if the url isn't set or the stored url is radically different
594                 // than the currently visited url, store the current value accordingly.
595                 // "Radically different" ignores common variations such as http vs https
596                 // and www.example.com vs example.com.
597                 // We will only change the url to an ip address if there is no existing setting
598
599                 if (empty($url) || (!Util\Strings::compareLink($url, $this->getBaseURL())) && (!preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/", $this->baseURL->getHostname()))) {
600                         $this->config->set('system', 'url', $this->getBaseURL());
601                 }
602         }
603
604         /**
605          * Frontend App script
606          *
607          * The App object behaves like a container and a dispatcher at the same time, including a representation of the
608          * request and a representation of the response.
609          *
610          * This probably should change to limit the size of this monster method.
611          *
612          * @param App\Module     $module The determined module
613          * @param App\Router     $router
614          * @param PConfiguration $pconfig
615          * @param Authentication $auth The Authentication backend of the node
616          * @throws HTTPException\InternalServerErrorException
617          * @throws \ImagickException
618          */
619         public function runFrontend(App\Module $module, App\Router $router, PConfiguration $pconfig, Authentication $auth)
620         {
621                 $moduleName = $module->getName();
622
623                 try {
624                         // Missing DB connection: ERROR
625                         if ($this->mode->has(App\Mode::LOCALCONFIGPRESENT) && !$this->mode->has(App\Mode::DBAVAILABLE)) {
626                                 throw new HTTPException\InternalServerErrorException('Apologies but the website is unavailable at the moment.');
627                         }
628
629                         // Max Load Average reached: ERROR
630                         if ($this->process->isMaxProcessesReached() || $this->process->isMaxLoadReached()) {
631                                 header('Retry-After: 120');
632                                 header('Refresh: 120; url=' . $this->baseURL->get() . "/" . $this->args->getQueryString());
633
634                                 throw new HTTPException\ServiceUnavailableException('The node is currently overloaded. Please try again later.');
635                         }
636
637                         if (!$this->mode->isInstall()) {
638                                 // Force SSL redirection
639                                 if ($this->baseURL->checkRedirectHttps()) {
640                                         System::externalRedirect($this->baseURL->get() . '/' . $this->args->getQueryString());
641                                 }
642
643                                 Core\Hook::callAll('init_1');
644                         }
645
646                         // Exclude the backend processes from the session management
647                         if ($this->mode->isBackend()) {
648                                 Core\Worker::executeIfIdle();
649                         }
650
651                         if ($this->mode->isNormal()) {
652                                 $requester = HTTPSignature::getSigner('', $_SERVER);
653                                 if (!empty($requester)) {
654                                         Profile::addVisitorCookieForHandle($requester);
655                                 }
656                         }
657
658                         // ZRL
659                         if (!empty($_GET['zrl']) && $this->mode->isNormal()) {
660                                 if (!local_user()) {
661                                         // Only continue when the given profile link seems valid
662                                         // Valid profile links contain a path with "/profile/" and no query parameters
663                                         if ((parse_url($_GET['zrl'], PHP_URL_QUERY) == "") &&
664                                             strstr(parse_url($_GET['zrl'], PHP_URL_PATH), "/profile/")) {
665                                                 if (Core\Session::get('visitor_home') != $_GET["zrl"]) {
666                                                         Core\Session::set('my_url', $_GET['zrl']);
667                                                         Core\Session::set('authenticated', 0);
668                                                 }
669
670                                                 Model\Profile::zrlInit($this);
671                                         } else {
672                                                 // Someone came with an invalid parameter, maybe as a DDoS attempt
673                                                 // We simply stop processing here
674                                                 $this->logger->debug('Invalid ZRL parameter.', ['zrl' => $_GET['zrl']]);
675                                                 throw new HTTPException\ForbiddenException();
676                                         }
677                                 }
678                         }
679
680                         if (!empty($_GET['owt']) && $this->mode->isNormal()) {
681                                 $token = $_GET['owt'];
682                                 Model\Profile::openWebAuthInit($token);
683                         }
684
685                         $auth->withSession($this);
686
687                         if (empty($_SESSION['authenticated'])) {
688                                 header('X-Account-Management-Status: none');
689                         }
690
691                         $_SESSION['sysmsg']       = Core\Session::get('sysmsg', []);
692                         $_SESSION['sysmsg_info']  = Core\Session::get('sysmsg_info', []);
693                         $_SESSION['last_updated'] = Core\Session::get('last_updated', []);
694
695                         /*
696                          * check_config() is responsible for running update scripts. These automatically
697                          * update the DB schema whenever we push a new one out. It also checks to see if
698                          * any addons have been added or removed and reacts accordingly.
699                          */
700
701                         // in install mode, any url loads install module
702                         // but we need "view" module for stylesheet
703                         if ($this->mode->isInstall() && $moduleName !== 'install') {
704                                 $this->internalRedirect('install');
705                         } elseif (!$this->mode->isInstall() && !$this->mode->has(App\Mode::MAINTENANCEDISABLED) && $moduleName !== 'maintenance') {
706                                 $this->internalRedirect('maintenance');
707                         } else {
708                                 $this->checkURL();
709                                 Core\Update::check($this->getBasePath(), false, $this->mode);
710                                 Core\Addon::loadAddons();
711                                 Core\Hook::loadHooks();
712                         }
713
714                         // Compatibility with the Android Diaspora client
715                         if ($moduleName == 'stream') {
716                                 $this->internalRedirect('network?order=post');
717                         }
718
719                         if ($moduleName == 'conversations') {
720                                 $this->internalRedirect('message');
721                         }
722
723                         if ($moduleName == 'commented') {
724                                 $this->internalRedirect('network?order=comment');
725                         }
726
727                         if ($moduleName == 'liked') {
728                                 $this->internalRedirect('network?order=comment');
729                         }
730
731                         if ($moduleName == 'activity') {
732                                 $this->internalRedirect('network?conv=1');
733                         }
734
735                         if (($moduleName == 'status_messages') && ($this->args->getCommand() == 'status_messages/new')) {
736                                 $this->internalRedirect('bookmarklet');
737                         }
738
739                         if (($moduleName == 'user') && ($this->args->getCommand() == 'user/edit')) {
740                                 $this->internalRedirect('settings');
741                         }
742
743                         if (($moduleName == 'tag_followings') && ($this->args->getCommand() == 'tag_followings/manage')) {
744                                 $this->internalRedirect('search');
745                         }
746
747                         // Initialize module that can set the current theme in the init() method, either directly or via App->profile_uid
748                         $this->page['page_title'] = $moduleName;
749
750                         // determine the module class and save it to the module instance
751                         // @todo there's an implicit dependency due SESSION::start(), so it has to be called here (yet)
752                         $module = $module->determineClass($this->args, $router, $this->config);
753
754                         // Let the module run it's internal process (init, get, post, ...)
755                         $module->run($this->l10n, $this, $this->logger, $_SERVER, $_POST);
756                 } catch (HTTPException $e) {
757                         ModuleHTTPException::rawContent($e);
758                 }
759
760                 $this->page->run($this, $this->baseURL, $this->mode, $module, $this->l10n, $this->config, $pconfig);
761         }
762
763         /**
764          * @deprecated 2019.12 use BaseUrl::redirect instead
765          * @see BaseURL::redirect()
766          */
767         public function internalRedirect($toUrl = '', $ssl = false)
768         {
769                 $this->baseURL->redirect($toUrl, $ssl);
770         }
771
772         /**
773          * Automatically redirects to relative or absolute URL
774          * Should only be used if it isn't clear if the URL is either internal or external
775          *
776          * @param string $toUrl The target URL
777          *
778          * @throws HTTPException\InternalServerErrorException
779          */
780         public function redirect($toUrl)
781         {
782                 if (!empty(parse_url($toUrl, PHP_URL_SCHEME))) {
783                         Core\System::externalRedirect($toUrl);
784                 } else {
785                         $this->baseURL->redirect($toUrl);
786                 }
787         }
788 }