‪TYPO3CMS  ‪main
TYPO3\CMS\Backend\Routing\UriBuilder Class Reference
Inheritance diagram for TYPO3\CMS\Backend\Routing\UriBuilder:
TYPO3\CMS\Core\SingletonInterface

Public Member Functions

 __construct (protected readonly Router $router, protected readonly FormProtectionFactory $formProtectionFactory, protected readonly RequestContextFactory $requestContextFactory)
 
 setRequestContext (RequestContext $requestContext)
 
UriInterface buildUriFromRoutePath ($pathInfo, $parameters=[], $referenceType=self::ABSOLUTE_PATH)
 
 buildUriWithRedirect (string $name, array $parameters=[], RouteRedirect $redirect=null, string $referenceType=self::ABSOLUTE_PATH)
 
 buildUriFromRequest (ServerRequestInterface $request, array $parameters=[], string $referenceType=self::ABSOLUTE_PATH)
 
UriInterface buildUriFromRoute ($name, $parameters=[], $referenceType=self::ABSOLUTE_PATH)
 

Public Attributes

const ABSOLUTE_URL = 'url'
 
const ABSOLUTE_PATH = 'absolute'
 
const SHAREABLE_URL = 'share'
 

Protected Member Functions

 buildUri (string $routeName, array $parameters, string $referenceType)
 

Protected Attributes

array $generated = []
 
RequestContext null $requestContext = null
 

Detailed Description

Main UrlGenerator for creating URLs for the Backend. Generates a URL based on an identifier defined by Configuration/Backend/Routes.php of an extension, and adds some more parameters to the URL.

Currently only available and useful when called from Router->generate() as the information about possible routes needs to be handed over.

Definition at line 43 of file UriBuilder.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Backend\Routing\UriBuilder::__construct ( protected readonly Router  $router,
protected readonly FormProtectionFactory  $formProtectionFactory,
protected readonly RequestContextFactory  $requestContextFactory 
)

Loads the router to fetch the available routes from the Router to be used for generating routes

Definition at line 69 of file UriBuilder.php.

Member Function Documentation

◆ buildUri()

TYPO3\CMS\Backend\Routing\UriBuilder::buildUri ( string  $routeName,
array  $parameters,
string  $referenceType 
)
protected

Internal method building a Uri object, merging the GET parameters array into a flat queryString

Parameters
string$routeName‪The route name in the collection
array$parameters‪An array of GET parameters
string$referenceType‪The type of reference to be generated (one of the constants)

Definition at line 187 of file UriBuilder.php.

References $GLOBALS, TYPO3\CMS\Backend\Routing\UriBuilder\$requestContext, TYPO3\CMS\Webhooks\Message\$url, TYPO3\CMS\Core\Http\ServerRequestFactory\fromGlobals(), TYPO3\CMS\Core\Core\Environment\isCli(), and TYPO3\CMS\Core\Core\SystemEnvironmentBuilder\REQUESTTYPE_BE.

Referenced by TYPO3\CMS\Backend\Routing\UriBuilder\buildUriFromRoute().

◆ buildUriFromRequest()

TYPO3\CMS\Backend\Routing\UriBuilder::buildUriFromRequest ( ServerRequestInterface  $request,
array  $parameters = [],
string  $referenceType = self::ABSOLUTE_PATH 
)

A shorthand function to link to e.g. the same as in the current request, so the internal attribute "route" is properly covered and does not need to be exposed all the time.

Definition at line 131 of file UriBuilder.php.

References TYPO3\CMS\Backend\Routing\UriBuilder\buildUriFromRoute().

◆ buildUriFromRoute()

UriInterface TYPO3\CMS\Backend\Routing\UriBuilder::buildUriFromRoute (   $name,
  $parameters = [],
  $referenceType = self::ABSOLUTE_PATH 
)

Generates a URL or path for a specific route based on the given parameters. When the route is configured with "access=public" then the token generation is left out.

If there is no route with the given name, the generator throws the RouteNotFoundException.

Parameters
string$name‪The name of the route
array$parameters‪An array of parameters
string$referenceType‪The type of reference to be generated (one of the constants)
Returns
‪UriInterface The generated Uri
Exceptions
RouteNotFoundException‪If the named route doesn't exist

Definition at line 152 of file UriBuilder.php.

References TYPO3\CMS\Backend\Routing\UriBuilder\buildUri().

Referenced by TYPO3\CMS\Backend\Backend\ToolbarItems\ClearCacheToolbarItem\__construct(), TYPO3\CMS\Backend\Routing\UriBuilder\buildUriFromRequest(), TYPO3\CMS\Backend\Routing\UriBuilder\buildUriFromRoutePath(), and TYPO3\CMS\Backend\Routing\UriBuilder\buildUriWithRedirect().

◆ buildUriFromRoutePath()

UriInterface TYPO3\CMS\Backend\Routing\UriBuilder::buildUriFromRoutePath (   $pathInfo,
  $parameters = [],
  $referenceType = self::ABSOLUTE_PATH 
)

Generates a URL or path for a specific route based on the given route. Currently used to link to the current script, it is encouraged to use "buildUriFromRoute" if possible.

If there is no route with the given name, the generator throws the RouteNotFoundException.

Parameters
string$pathInfo‪The path to the route
array$parameters‪An array of parameters
string$referenceType‪The type of reference to be generated (one of the constants)
Returns
‪UriInterface The generated Uri
Exceptions
RouteNotFoundException‪If the named route doesn't exist

Definition at line 95 of file UriBuilder.php.

References TYPO3\CMS\Backend\Routing\UriBuilder\buildUriFromRoute().

◆ buildUriWithRedirect()

TYPO3\CMS\Backend\Routing\UriBuilder::buildUriWithRedirect ( string  $name,
array  $parameters = [],
RouteRedirect  $redirect = null,
string  $referenceType = self::ABSOLUTE_PATH 
)

Creates a link to a page with a route targetted as a redirect, if a "deep link" is possible. Currently works just fine for URLs built for "main" and "login" pages.

Parameters
RouteRedirect | null$redirect
Exceptions
RouteNotFoundException

this is experimental API used for creating logins to redirect to a different route

Definition at line 109 of file UriBuilder.php.

References TYPO3\CMS\Backend\Routing\UriBuilder\buildUriFromRoute().

◆ setRequestContext()

TYPO3\CMS\Backend\Routing\UriBuilder::setRequestContext ( RequestContext  $requestContext)

Member Data Documentation

◆ $generated

array TYPO3\CMS\Backend\Routing\UriBuilder::$generated = []
protected

Definition at line 63 of file UriBuilder.php.

◆ $requestContext

RequestContext null TYPO3\CMS\Backend\Routing\UriBuilder::$requestContext = null
protected

◆ ABSOLUTE_PATH

const TYPO3\CMS\Backend\Routing\UriBuilder::ABSOLUTE_PATH = 'absolute'

◆ ABSOLUTE_URL

◆ SHAREABLE_URL

const TYPO3\CMS\Backend\Routing\UriBuilder::SHAREABLE_URL = 'share'