diff --git a/src/App.php b/src/App.php index 585c9b026a..b4f7c520fe 100644 --- a/src/App.php +++ b/src/App.php @@ -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); } /** diff --git a/src/AppHelper.php b/src/AppHelper.php index 103d7ddf91..599c15d041 100644 --- a/src/AppHelper.php +++ b/src/AppHelper.php @@ -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); + } + } }