mirror of
https://github.com/friendica/friendica
synced 2025-01-18 16:24:27 +00:00
extract redirect method into AppHelper
This commit is contained in:
parent
470c47f45c
commit
85f74c80e8
2 changed files with 32 additions and 6 deletions
11
src/App.php
11
src/App.php
|
@ -19,6 +19,7 @@ use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||||
use Friendica\Database\Definition\DbaDefinition;
|
use Friendica\Database\Definition\DbaDefinition;
|
||||||
use Friendica\Database\Definition\ViewDefinition;
|
use Friendica\Database\Definition\ViewDefinition;
|
||||||
use Friendica\Module\Maintenance;
|
use Friendica\Module\Maintenance;
|
||||||
|
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||||
use Friendica\Security\Authentication;
|
use Friendica\Security\Authentication;
|
||||||
use Friendica\Core\Config\ValueObject\Cache;
|
use Friendica\Core\Config\ValueObject\Cache;
|
||||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||||
|
@ -614,17 +615,15 @@ class App
|
||||||
* Automatically redirects to relative or absolute URL
|
* Automatically redirects to relative or absolute URL
|
||||||
* Should only be used if it isn't clear if the URL is either internal or external
|
* 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
|
* @param string $toUrl The target URL
|
||||||
*
|
*
|
||||||
* @throws HTTPException\InternalServerErrorException
|
* @throws InternalServerErrorException
|
||||||
*/
|
*/
|
||||||
public function redirect(string $toUrl)
|
public function redirect(string $toUrl)
|
||||||
{
|
{
|
||||||
if (!empty(parse_url($toUrl, PHP_URL_SCHEME))) {
|
$this->appHelper->redirect($toUrl);
|
||||||
Core\System::externalRedirect($toUrl);
|
|
||||||
} else {
|
|
||||||
$this->baseURL->redirect($toUrl);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -9,14 +9,17 @@ namespace Friendica;
|
||||||
|
|
||||||
use DateTimeZone;
|
use DateTimeZone;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use Friendica\App\BaseURL;
|
||||||
use Friendica\App\Mode;
|
use Friendica\App\Mode;
|
||||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||||
use Friendica\Core\Config\ValueObject\Cache;
|
use Friendica\Core\Config\ValueObject\Cache;
|
||||||
use Friendica\Core\L10n;
|
use Friendica\Core\L10n;
|
||||||
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
|
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
|
||||||
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||||
|
use Friendica\Core\System;
|
||||||
use Friendica\Core\Theme;
|
use Friendica\Core\Theme;
|
||||||
use Friendica\Database\Database;
|
use Friendica\Database\Database;
|
||||||
|
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||||
use Friendica\Util\DateTimeFormat;
|
use Friendica\Util\DateTimeFormat;
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
|
|
||||||
|
@ -68,6 +71,11 @@ final class AppHelper
|
||||||
*/
|
*/
|
||||||
private $mode;
|
private $mode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var BaseURL
|
||||||
|
*/
|
||||||
|
private $baseURL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var L10n The translator
|
* @var L10n The translator
|
||||||
*/
|
*/
|
||||||
|
@ -87,6 +95,7 @@ final class AppHelper
|
||||||
Database $database,
|
Database $database,
|
||||||
IManageConfigValues $config,
|
IManageConfigValues $config,
|
||||||
Mode $mode,
|
Mode $mode,
|
||||||
|
BaseURL $baseURL,
|
||||||
L10n $l10n,
|
L10n $l10n,
|
||||||
IManagePersonalConfigValues $pConfig,
|
IManagePersonalConfigValues $pConfig,
|
||||||
IHandleUserSessions $session
|
IHandleUserSessions $session
|
||||||
|
@ -95,6 +104,7 @@ final class AppHelper
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->mode = $mode;
|
$this->mode = $mode;
|
||||||
$this->l10n = $l10n;
|
$this->l10n = $l10n;
|
||||||
|
$this->baseURL = $baseURL;
|
||||||
$this->pConfig = $pConfig;
|
$this->pConfig = $pConfig;
|
||||||
$this->session = $session;
|
$this->session = $session;
|
||||||
}
|
}
|
||||||
|
@ -371,4 +381,21 @@ final class AppHelper
|
||||||
$this->setCurrentMobileTheme($mobile_theme_name);
|
$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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue