‪TYPO3CMS  ‪main
TYPO3\CMS\Redirects\Service\RedirectService Class Reference

Public Member Functions

 __construct (private readonly RedirectCacheService $redirectCacheService, private readonly LinkService $linkService, private readonly SiteFinder $siteFinder, private readonly EventDispatcherInterface $eventDispatcher, private readonly PageInformationFactory $pageInformationFactory, private readonly FrontendTypoScriptFactory $frontendTypoScriptFactory, #[Autowire(service:'cache.typoscript')] private readonly PhpFrontend $typoScriptCache, private readonly LoggerInterface $logger,)
 
 matchRedirect (string $domain, string $path, string $query='')
 
 getTargetUrl (array $matchedRedirect, ServerRequestInterface $request)
 

Protected Member Functions

bool isRedirectActive (array $redirectRecord)
 
 fetchRedirects (string $sourceHost)
 
array resolveLinkDetailsFromLinkTarget (string $redirectTarget)
 
 resolveSite (array $linkDetails, ?SiteInterface $site)
 
 addQueryParams (array $queryParams, Uri $url)
 
 getUriFromCustomLinkDetails (array $redirectRecord, ?SiteInterface $site, array $linkDetails, array $queryParams, ServerRequestInterface $originalRequest)
 
 bootFrontendController (SiteInterface $site, array $queryParams, ServerRequestInterface $originalRequest)
 
 replaceRegExpCaptureGroup (array $matchedRedirect, UriInterface $uri, array $linkDetails)
 
 getFirstActiveRedirectFromPossibleRedirects (array $possibleRedirects)
 

Private Member Functions

 getExpressionMatcherVariables (SiteInterface $site, ServerRequestInterface $request, TypoScriptFrontendController $controller)
 
 cleanupTSFE ()
 

Detailed Description

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

due to some possible refactorings

Definition at line 54 of file RedirectService.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Redirects\Service\RedirectService::__construct ( private readonly RedirectCacheService  $redirectCacheService,
private readonly LinkService  $linkService,
private readonly SiteFinder  $siteFinder,
private readonly EventDispatcherInterface  $eventDispatcher,
private readonly PageInformationFactory  $pageInformationFactory,
private readonly FrontendTypoScriptFactory  $frontendTypoScriptFactory,
# private readonly PhpFrontend  $typoScriptCache[Autowire(service:'cache.typoscript')],
private readonly LoggerInterface  $logger 
)

Definition at line 56 of file RedirectService.php.

Member Function Documentation

◆ addQueryParams()

TYPO3\CMS\Redirects\Service\RedirectService::addQueryParams ( array  $queryParams,
Uri  $url 
)
protected

Adds query parameters to a Uri object

Definition at line 321 of file RedirectService.php.

References TYPO3\CMS\Webhooks\Message\$url.

Referenced by TYPO3\CMS\Redirects\Service\RedirectService\getTargetUrl().

◆ bootFrontendController()

TYPO3\CMS\Redirects\Service\RedirectService::bootFrontendController ( SiteInterface  $site,
array  $queryParams,
ServerRequestInterface  $originalRequest 
)
protected

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

Instantiating is done by the middleware stack (see Configuration/RequestMiddlewares.php)

  • ‪TSFE->sys_page
  • ‪TSFE->config
  • ‪TSFE->cObj

So a link to a page can be generated.

Todo:
‪: This messes quite a bit with dependencies here. RedirectService is called by an early middleware before TSFE has been set up at all. The code thus has to hop through various loops later middlewares would usually do. The overall scenario of needing a partially set up TSFE for target redirect calculation is quite unfortunate here and should be sorted out differently by further refactoring the link building and reducing TSFE dependencies.

Definition at line 396 of file RedirectService.php.

References $GLOBALS, TYPO3\CMS\Redirects\Service\RedirectService\getExpressionMatcherVariables(), and TYPO3\CMS\Core\Site\Entity\SiteInterface\getRootPageId().

Referenced by TYPO3\CMS\Redirects\Service\RedirectService\getUriFromCustomLinkDetails().

◆ cleanupTSFE()

TYPO3\CMS\Redirects\Service\RedirectService::cleanupTSFE ( )
private
Todo:
‪: Needs to vanish. The existence of this method is a side-effect of the technical debt that a TSFE has to be set up for link generation, see the comment on bootFrontendController() for more details.

Definition at line 501 of file RedirectService.php.

References $GLOBALS.

Referenced by TYPO3\CMS\Redirects\Service\RedirectService\getUriFromCustomLinkDetails().

◆ fetchRedirects()

TYPO3\CMS\Redirects\Service\RedirectService::fetchRedirects ( string  $sourceHost)
protected

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.

Definition at line 199 of file RedirectService.php.

Referenced by TYPO3\CMS\Redirects\Service\RedirectService\matchRedirect().

◆ getExpressionMatcherVariables()

TYPO3\CMS\Redirects\Service\RedirectService::getExpressionMatcherVariables ( SiteInterface  $site,
ServerRequestInterface  $request,
TypoScriptFrontendController  $controller 
)
private

◆ getFirstActiveRedirectFromPossibleRedirects()

TYPO3\CMS\Redirects\Service\RedirectService::getFirstActiveRedirectFromPossibleRedirects ( array  $possibleRedirects)
protected

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

Definition at line 485 of file RedirectService.php.

References TYPO3\CMS\Redirects\Service\RedirectService\isRedirectActive().

Referenced by TYPO3\CMS\Redirects\Service\RedirectService\matchRedirect().

◆ getTargetUrl()

◆ getUriFromCustomLinkDetails()

TYPO3\CMS\Redirects\Service\RedirectService::getUriFromCustomLinkDetails ( array  $redirectRecord,
?SiteInterface  $site,
array  $linkDetails,
array  $queryParams,
ServerRequestInterface  $originalRequest 
)
protected

◆ isRedirectActive()

bool TYPO3\CMS\Redirects\Service\RedirectService::isRedirectActive ( array  $redirectRecord)
protected

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

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

Definition at line 189 of file RedirectService.php.

References $GLOBALS.

Referenced by TYPO3\CMS\Redirects\Service\RedirectService\getFirstActiveRedirectFromPossibleRedirects().

◆ matchRedirect()

TYPO3\CMS\Redirects\Service\RedirectService::matchRedirect ( string  $domain,
string  $path,
string  $query = '' 
)

◆ replaceRegExpCaptureGroup()

TYPO3\CMS\Redirects\Service\RedirectService::replaceRegExpCaptureGroup ( array  $matchedRedirect,
UriInterface  $uri,
array  $linkDetails 
)
protected

◆ resolveLinkDetailsFromLinkTarget()

array TYPO3\CMS\Redirects\Service\RedirectService::resolveLinkDetailsFromLinkTarget ( string  $redirectTarget)
protected

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

Returns
‪array the link details from the linkService

Definition at line 209 of file RedirectService.php.

References TYPO3\CMS\Core\LinkHandling\LinkService\TYPE_FILE, TYPO3\CMS\Core\LinkHandling\LinkService\TYPE_FOLDER, TYPO3\CMS\Core\LinkHandling\LinkService\TYPE_UNKNOWN, and TYPO3\CMS\Core\LinkHandling\LinkService\TYPE_URL.

Referenced by TYPO3\CMS\Redirects\Service\RedirectService\getTargetUrl().

◆ resolveSite()

TYPO3\CMS\Redirects\Service\RedirectService::resolveSite ( array  $linkDetails,
?SiteInterface  $site 
)
protected

If no site is given, try to find a valid site for the target page

Definition at line 306 of file RedirectService.php.

References TYPO3\CMS\Core\LinkHandling\LinkService\TYPE_PAGE.

Referenced by TYPO3\CMS\Redirects\Service\RedirectService\getTargetUrl().