extract redirect method into AppHelper

This commit is contained in:
Art4 2024-11-08 12:13:20 +00:00
parent 470c47f45c
commit 85f74c80e8
2 changed files with 32 additions and 6 deletions

View 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);
}
/**

View 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);
}
}
}