UriBuilder

class \TYPO3\CMS\Backend\Routing\UriBuilder

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.

Attributes

#[Autoconfigure]
$public: true

Table of Contents

Constants

ABSOLUTE_PATH  : mixed = 'absolute'
Generates an absolute path
ABSOLUTE_URL  : mixed = 'url'
Generates an absolute URL
SHAREABLE_URL  : mixed = 'share'
Generates an absolute url for URL sharing

Properties

$formProtectionFactory  : FormProtectionFactory
$generated  : array<non-empty-string, UriInterface>
$requestContext  : RequestContext|null
$requestContextFactory  : RequestContextFactory
$router  : Router

Methods

__construct()  : mixed
Loads the router to fetch the available routes from the Router to be used for generating routes
buildUriFromRequest()  : UriInterface
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.
buildUriFromRoute()  : UriInterface
Generates a URL or path for a specific route based on the given parameters.
buildUriFromRoutePath()  : UriInterface
Generates a URL or path for a specific route based on the given route.
buildUriWithRedirect()  : UriInterface
Creates a link to a page with a route targetted as a redirect, if a "deep link" is possible.
setRequestContext()  : void
buildUri()  : UriInterface
Internal method building a Uri object, merging the GET parameters array into a flat queryString

Constants

ABSOLUTE_PATH

Generates an absolute path

public mixed ABSOLUTE_PATH = 'absolute'

ABSOLUTE_URL

Generates an absolute URL

public mixed ABSOLUTE_URL = 'url'

SHAREABLE_URL

Generates an absolute url for URL sharing

public mixed SHAREABLE_URL = 'share'

Properties

$generated

protected array<non-empty-string, UriInterface> $generated = []

$requestContext

protected RequestContext|null $requestContext = null

Methods

buildUriFromRequest()

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.

public buildUriFromRequest(ServerRequestInterface $request[, array $parameters = [] ][, string $referenceType = self::ABSOLUTE_PATH ]) : UriInterface

Parameters

$request : ServerRequestInterface
$parameters : array = []
$referenceType : string = self::ABSOLUTE_PATH

Return values

UriInterface

buildUriFromRoute()

Generates a URL or path for a specific route based on the given parameters.

public buildUriFromRoute(string $name[, array $parameters = [] ][, string $referenceType = self::ABSOLUTE_PATH ]) : UriInterface

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

$name : string

The name of the route

$parameters : array = []

An array of parameters

$referenceType : string = self::ABSOLUTE_PATH

The type of reference to be generated (one of the constants)

Tags

throws
RouteNotFoundException

If the named route doesn't exist

Return values

UriInterface —

The generated Uri

buildUriFromRoutePath()

Generates a URL or path for a specific route based on the given route.

public buildUriFromRoutePath(string $pathInfo[, array $parameters = [] ][, string $referenceType = self::ABSOLUTE_PATH ]) : UriInterface

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

$pathInfo : string

The path to the route

$parameters : array = []

An array of parameters

$referenceType : string = self::ABSOLUTE_PATH

The type of reference to be generated (one of the constants)

Tags

throws
RouteNotFoundException

If the named route doesn't exist

throws
ResourceNotFoundException

If no route matches the path info

Return values

UriInterface —

The generated Uri

buildUriWithRedirect()

Creates a link to a page with a route targetted as a redirect, if a "deep link" is possible.

public buildUriWithRedirect(string $name[, array $parameters = [] ][, RouteRedirect|null $redirect = null ][, string $referenceType = self::ABSOLUTE_PATH ]) : UriInterface

Currently works just fine for URLs built for "main" and "login" pages.

Parameters

$name : string
$parameters : array = []
$redirect : RouteRedirect|null = null
$referenceType : string = self::ABSOLUTE_PATH

Tags

throws
RouteNotFoundException

Return values

UriInterface

setRequestContext()

public setRequestContext(RequestContext $requestContext) : void

Parameters

$requestContext : RequestContext

buildUri()

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

protected buildUri(string $routeName, array $parameters, string $referenceType) : UriInterface

Parameters

$routeName : string

The route name in the collection

$parameters : array

An array of GET parameters

$referenceType : string

The type of reference to be generated (one of the constants)

Return values

UriInterface
On this page