PageRouter

class \TYPO3\CMS\Core\Routing\PageRouter

Implements
RouterInterface

Page Router - responsible for a page based on a request, by looking up the slug of the page path.

Is also used for generating URLs for pages.

Resolving is done via the "Route Candidate" pattern.

Example:

  • /about-us/team/management/

will look for all pages that have

  • /about-us
  • /about-us/
  • /about-us/team
  • /about-us/team/
  • /about-us/team/management
  • /about-us/team/management/

And create route candidates for that.

Please note: PageRouter does not restrict the HTTP method or is bound to any domain constraints, as the SiteMatcher has done that already.

The concept of the PageRouter is to resolve, and to generate URIs. On top, it is a facade to hide the dependency to symfony and to not expose its logic.

Table of Contents

Interfaces

RouterInterface
Base Router to be used all over the TYPO3 Core. Its base lies around PSR-7 requests + URIs, and special "RouteResult" objects.

Properties

$aspectFactory  : AspectFactory
$cacheHashCalculator  : CacheHashCalculator
$context  : Context
$enhancerFactory  : EnhancerFactory
$eventDispatcher  : EventDispatcherInterface
$requestContextFactory  : RequestContextFactory
$site  : Site

Methods

__construct()  : mixed
A page router is always bound to a specific site.
generateUri()  : UriInterface
API for generating a page uri where the $route parameter is typically an array (a page record) or the page ID
matchRequest()  : RouteResultInterface|PageArguments
Finds a RouteResult based on the given request.
assertMaximumStaticMappableAmount()  : mixed
Asserts that possible amount of items in all static and countable mappers (such as StaticRangeMapper) is limited to 10000 in order to avoid brute-force scenarios and the risk of cache-flooding.
buildPageArguments()  : PageArguments
Builds route arguments. The important part here is to distinguish between static and dynamic arguments. Per default all arguments are dynamic until aspects can be used to really consider them as static (= 1:1 mapping between route value and resulting arguments).
filterProcessedParameters()  : array
Determine parameters that have been processed.
generateCacheHash()  : string
getCacheHashParameters()  : array
getEnhancersForPage()  : EnhancerInterface[]
Fetch possible enhancers + aspects based on the current page configuration and the site configuration put into "routeEnhancers"
getSlugCandidateProvider()  : PageSlugCandidateProvider
isRouteReallyValidForLanguage()  : bool
Request may have been made with default page slug, also we are dealing with a site language variant. To avoid duplicate content, we need to revalidate that the eventually matched language route is really the available page language variant for the current lange. We do this at this late point to minimize the needed database queries instead of checking it for all build page candidates.
matchesPageLimitation()  : bool
Checks whether the current page matches any of the limitToPages conditions.
resolveMountPointParameterIntoPageSlug()  : string
When a MP parameter is given, the mount point parameter is resolved, and the slug of the new page is added while the same parts of the original pagePath is removed (before).
resolveType()  : string
Retrieves type from processed route and modifies remaining query parameters.

Properties

$eventDispatcher

protected EventDispatcherInterface $eventDispatcher

Methods

__construct()

A page router is always bound to a specific site.

public __construct(Site $site[, Context|null $context = null ]) : mixed

Parameters

$site : Site
$context : Context|null = null

generateUri()

API for generating a page uri where the $route parameter is typically an array (a page record) or the page ID

public generateUri(array|string|int|Page $route[, array $parameters = [] ][, string $fragment = '' ][, string $type = '' ]) : UriInterface

Parameters

$route : array|string|int|Page
$parameters : array = []

an array of query parameters which can be built into the URI path, also consider the special handling of "_language"

$fragment : string = ''

additional #my-fragment part

$type : string = ''

see the RouterInterface for possible types

Tags

throws
InvalidRouteArgumentsException

Return values

UriInterface

assertMaximumStaticMappableAmount()

Asserts that possible amount of items in all static and countable mappers (such as StaticRangeMapper) is limited to 10000 in order to avoid brute-force scenarios and the risk of cache-flooding.

protected assertMaximumStaticMappableAmount(Route $route[, array $variableNames = [] ]) : mixed

Parameters

$route : Route
$variableNames : array = []

Tags

throws
OverflowException
todo

with having static route variables, this restriction should be configurable & optional

buildPageArguments()

Builds route arguments. The important part here is to distinguish between static and dynamic arguments. Per default all arguments are dynamic until aspects can be used to really consider them as static (= 1:1 mapping between route value and resulting arguments).

protected buildPageArguments(Route $route, array $results[, array $remainingQueryParameters = [] ]) : PageArguments

Besides that, internal arguments (_route, _controller, _custom, ..) have to be separated since those values are not meant to be used for later processing. Not separating those values might result in invalid cHash.

This method is used during resolving and generation of URLs.

Parameters

$route : Route
$results : array
$remainingQueryParameters : array = []

Return values

PageArguments

filterProcessedParameters()

Determine parameters that have been processed.

protected filterProcessedParameters(Route $route, array $results) : array

Parameters

$route : Route
$results : array

Return values

array

getCacheHashParameters()

protected getCacheHashParameters(int $pageId, PageArguments $arguments) : array

Parameters

$pageId : int
$arguments : PageArguments

Return values

array

getEnhancersForPage()

Fetch possible enhancers + aspects based on the current page configuration and the site configuration put into "routeEnhancers"

protected getEnhancersForPage(int $pageId, SiteLanguage $language[, array $page = [] ]) : EnhancerInterface[]

Parameters

$pageId : int
$language : SiteLanguage
$page : array = []

Return values

EnhancerInterface[]

isRouteReallyValidForLanguage()

Request may have been made with default page slug, also we are dealing with a site language variant. To avoid duplicate content, we need to revalidate that the eventually matched language route is really the available page language variant for the current lange. We do this at this late point to minimize the needed database queries instead of checking it for all build page candidates.

protected isRouteReallyValidForLanguage(Route $route, SiteLanguage $siteLanguage) : bool

This is safe, as we can simply drop the route and having a correct page not found action delivered.

Parameters

$route : Route
$siteLanguage : SiteLanguage

Return values

bool

matchesPageLimitation()

Checks whether the current page matches any of the limitToPages conditions.

protected matchesPageLimitation(array $limitToPages, int $pageId, array $page, SiteLanguage $language, Resolver|null &$resolver) : bool

Each entry in the array is OR-combined:

  • Integer values are matched against the page ID (existing behavior)
  • String values are evaluated as Symfony ExpressionLanguage expressions with access to the page, site and siteLanguage variables

Parameters

$limitToPages : array
$pageId : int
$page : array
$language : SiteLanguage
$resolver : Resolver|null

Return values

bool

resolveMountPointParameterIntoPageSlug()

When a MP parameter is given, the mount point parameter is resolved, and the slug of the new page is added while the same parts of the original pagePath is removed (before).

protected resolveMountPointParameterIntoPageSlug(int $pageId, string $pagePath, array $mountPointPairs, PageRepository $pageRepository) : string

This way, the subpage to a mounted page has now a different "base" (= prefixed with the slug of the mount point).

This is done recursively when multiple mount point parameter pairs

Parameters

$pageId : int
$pagePath : string

the original path of the page

$mountPointPairs : array

an array with MP pairs (like ['13-3', '4-2'] for recursive mount points)

$pageRepository : PageRepository

Return values

string

resolveType()

Retrieves type from processed route and modifies remaining query parameters.

protected resolveType(Route $route, array &$remainingQueryParameters) : string

Parameters

$route : Route
$remainingQueryParameters : array

reference to remaining query parameters

Return values

string
On this page