]> git.mxchange.org Git - friendica.git/commitdiff
extract redirect method into AppHelper
authorArt4 <art4@wlabs.de>
Fri, 8 Nov 2024 12:13:20 +0000 (12:13 +0000)
committerArt4 <art4@wlabs.de>
Fri, 8 Nov 2024 12:13:20 +0000 (12:13 +0000)
src/App.php
src/AppHelper.php

index 585c9b026a2268dc4aa9df88fcff3f2661c150c3..b4f7c520fe98fc18b019d93f2086e725d8b07b65 100644 (file)
@@ -19,6 +19,7 @@ use Friendica\Core\Session\Capability\IHandleUserSessions;
 use Friendica\Database\Definition\DbaDefinition;
 use Friendica\Database\Definition\ViewDefinition;
 use Friendica\Module\Maintenance;
+use Friendica\Network\HTTPException\InternalServerErrorException;
 use Friendica\Security\Authentication;
 use Friendica\Core\Config\ValueObject\Cache;
 use Friendica\Core\Config\Capability\IManageConfigValues;
@@ -614,17 +615,15 @@ class App
         * Automatically redirects to relative or absolute URL
         * Should only be used if it isn't clear if the URL is either internal or external
         *
+        * @deprecated 2024.12 Use AppHelper::redirect() instead
+        *
         * @param string $toUrl The target URL
         *
-        * @throws HTTPException\InternalServerErrorException
+        * @throws InternalServerErrorException
         */
        public function redirect(string $toUrl)
        {
-               if (!empty(parse_url($toUrl, PHP_URL_SCHEME))) {
-                       Core\System::externalRedirect($toUrl);
-               } else {
-                       $this->baseURL->redirect($toUrl);
-               }
+               $this->appHelper->redirect($toUrl);
        }
 
        /**
index 103d7ddf91df8c8fdba68e0219661e43c03cd2b4..599c15d041ac66d6e0135263d9cb2778bebc6bb5 100644 (file)
@@ -9,14 +9,17 @@ namespace Friendica;
 
 use DateTimeZone;
 use Exception;
+use Friendica\App\BaseURL;
 use Friendica\App\Mode;
 use Friendica\Core\Config\Capability\IManageConfigValues;
 use Friendica\Core\Config\ValueObject\Cache;
 use Friendica\Core\L10n;
 use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
 use Friendica\Core\Session\Capability\IHandleUserSessions;
+use Friendica\Core\System;
 use Friendica\Core\Theme;
 use Friendica\Database\Database;
+use Friendica\Network\HTTPException\InternalServerErrorException;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Strings;
 
@@ -68,6 +71,11 @@ final class AppHelper
         */
        private $mode;
 
+       /**
+        * @var BaseURL
+        */
+       private $baseURL;
+
        /**
         * @var L10n The translator
         */
@@ -87,6 +95,7 @@ final class AppHelper
                Database $database,
                IManageConfigValues $config,
                Mode $mode,
+               BaseURL $baseURL,
                L10n $l10n,
                IManagePersonalConfigValues $pConfig,
                IHandleUserSessions $session
@@ -95,6 +104,7 @@ final class AppHelper
                $this->config = $config;
                $this->mode = $mode;
                $this->l10n = $l10n;
+               $this->baseURL = $baseURL;
                $this->pConfig = $pConfig;
                $this->session = $session;
        }
@@ -371,4 +381,21 @@ final class AppHelper
                        $this->setCurrentMobileTheme($mobile_theme_name);
                }
        }
+
+       /**
+        * Automatically redirects to relative or absolute URL
+        * Should only be used if it isn't clear if the URL is either internal or external
+        *
+        * @param string $toUrl The target URL
+        *
+        * @throws InternalServerErrorException
+        */
+       public function redirect(string $toUrl)
+       {
+               if (!empty(parse_url($toUrl, PHP_URL_SCHEME))) {
+                       System::externalRedirect($toUrl);
+               } else {
+                       $this->baseURL->redirect($toUrl);
+               }
+       }
 }