RedirectService

readonly class \TYPO3\CMS\Redirects\Service\RedirectService

Creates a proper URL to redirect from a matched redirect of a request

Table of Contents

Methods

__construct()  : mixed
getTargetUrl()  : UriInterface|null
matchRedirect()  : array|null
Checks against all available redirects "flat" or "regexp", and against starttime/endtime
addQueryParams()  : Uri
Adds query parameters to a Uri object
bootFrontendController()  : ContentObjectRenderer
Finishing booting up, after that the following properties are available.
fetchRedirects()  : array
Fetches all redirects from cache, with fallback to rebuild cache from the DB if caches was empty, grouped by the domain does NOT take starttime/endtime into account, as it is cached.
getFirstActiveRedirectFromPossibleRedirects()  : array|null
Checks all possible redirects and return the first possible and active redirect if available.
getUriFromCustomLinkDetails()  : UriInterface|null
Called when TypoScriptis available, so typolink is used to generate the URL
isRedirectActive()  : bool
Check if a redirect record matches the starttime and endtime and disable restrictions
replaceRegExpCaptureGroup()  : array
resolveLinkDetailsFromLinkTarget()  : array
Check if the current request is actually a redirect, and then process the redirect.
resolveSite()  : SiteInterface|null
If no site is given, try to find a valid site for the target page or record

Methods

__construct()

public __construct(RedirectCacheService $redirectCacheService, LinkService $linkService, SiteFinder $siteFinder, EventDispatcherInterface $eventDispatcher, PageInformationFactory $pageInformationFactory, FrontendTypoScriptFactory $frontendTypoScriptFactory, PhpFrontend $typoScriptCache, LoggerInterface $logger, TypoLinkCodecService $typoLinkCodecService, Locales $locales, Context $context, PageTsConfigFactory $pageTsConfigFactory, ConnectionPool $connectionPool, TcaSchemaFactory $tcaSchemaFactory) : mixed

Parameters

$redirectCacheService : RedirectCacheService
$linkService : LinkService
$siteFinder : SiteFinder
$eventDispatcher : EventDispatcherInterface
$pageInformationFactory : PageInformationFactory
$frontendTypoScriptFactory : FrontendTypoScriptFactory
$typoScriptCache : PhpFrontend
$logger : LoggerInterface
$typoLinkCodecService : TypoLinkCodecService
$locales : Locales
$context : Context
$pageTsConfigFactory : PageTsConfigFactory
$connectionPool : ConnectionPool
$tcaSchemaFactory : TcaSchemaFactory

getTargetUrl()

public getTargetUrl(array $matchedRedirect, ServerRequestInterface $request) : UriInterface|null

Parameters

$matchedRedirect : array
$request : ServerRequestInterface

Return values

UriInterface|null

matchRedirect()

Checks against all available redirects "flat" or "regexp", and against starttime/endtime

public matchRedirect(string $domain, string $path[, string $query = '' ]) : array|null

Parameters

$domain : string
$path : string
$query : string = ''

Return values

array|null

addQueryParams()

Adds query parameters to a Uri object

protected addQueryParams(array $queryParams, Uri $url) : Uri

Parameters

$queryParams : array
$url : Uri

Return values

Uri

bootFrontendController()

Finishing booting up, after that the following properties are available.

protected bootFrontendController(SiteInterface $site, array $queryParams, ServerRequestInterface $originalRequest) : ContentObjectRenderer

Instantiating is done by the middleware stack (see Configuration/RequestMiddlewares.php) so a link to a page can be generated.

Parameters

$site : SiteInterface
$queryParams : array
$originalRequest : ServerRequestInterface

Tags

todo:

This messes quite a bit with dependencies here. RedirectService is called by an early middleware before state has been set up at all. The code thus has to hop through various loops later middlewares would usually do.

Return values

ContentObjectRenderer

fetchRedirects()

Fetches all redirects from cache, with fallback to rebuild cache from the DB if caches was empty, grouped by the domain does NOT take starttime/endtime into account, as it is cached.

protected fetchRedirects(string $sourceHost) : array

Parameters

$sourceHost : string

Return values

array

getFirstActiveRedirectFromPossibleRedirects()

Checks all possible redirects and return the first possible and active redirect if available.

protected getFirstActiveRedirectFromPossibleRedirects(array $possibleRedirects) : array|null

Parameters

$possibleRedirects : array

Return values

array|null

getUriFromCustomLinkDetails()

Called when TypoScriptis available, so typolink is used to generate the URL

protected getUriFromCustomLinkDetails(array $redirectRecord, SiteInterface|null $site, array $linkDetails, array $queryParams, ServerRequestInterface $originalRequest) : UriInterface|null

Parameters

$redirectRecord : array
$site : SiteInterface|null
$linkDetails : array
$queryParams : array
$originalRequest : ServerRequestInterface

Return values

UriInterface|null

isRedirectActive()

Check if a redirect record matches the starttime and endtime and disable restrictions

protected isRedirectActive(array $redirectRecord) : bool

Parameters

$redirectRecord : array

Return values

bool —

whether the redirect is active and should be used for redirecting the current request

replaceRegExpCaptureGroup()

protected replaceRegExpCaptureGroup(array $matchedRedirect, UriInterface $uri, array $linkDetails) : array

Parameters

$matchedRedirect : array
$uri : UriInterface
$linkDetails : array

Return values

array

resolveLinkDetailsFromLinkTarget()

Check if the current request is actually a redirect, and then process the redirect.

protected resolveLinkDetailsFromLinkTarget(string $redirectTarget) : array

Parameters

$redirectTarget : string

Return values

array —

the link details from the linkService

On this page