PHP Class Illuminate\Routing\UrlGenerator

Show file Open project: illuminate/routing Class Usage Examples

Protected Properties

Property Type Description
$cachedRoot string | null A cached copy of the URL root for the current request.
$cachedSchema string | null A cached copy of the URL schema for the current request.
$dontEncode array Characters that should not be URL encoded.
$forceSchema string The forced schema for URLs.
$forcedRoot string The forced URL root.
$formatHostUsing Closure The callback to use to format hosts.
$formatPathUsing Closure The callback to use to format paths.
$request Illuminate\Http\Request The request instance.
$rootNamespace string The root namespace being applied to controller actions.
$routes Illuminate\Routing\RouteCollection The route collection.
$sessionResolver callable The session resolver callable.

Public Methods

Method Description
__construct ( RouteCollection $routes, Illuminate\Http\Request $request ) : void Create a new URL Generator instance.
action ( string $action, mixed $parameters = [], boolean $absolute = true ) : string Get the URL to a controller action.
asset ( string $path, boolean | null $secure = null ) : string Generate the URL to an application asset.
assetFrom ( string $root, string $path, boolean | null $secure = null ) : string Generate the URL to an asset from a custom root domain such as CDN, etc.
current ( ) : string Get the current URL for the request.
forceRootUrl ( string $root ) : void Set the forced root URL.
forceSchema ( string $schema ) : void Force the schema for URLs.
formatHostUsing ( Closur\Closure $callback ) Set a callback to be used to format the host of generated URLs.
formatPathUsing ( Closur\Closure $callback ) Set a callback to be used to format the path of generated URLs.
full ( ) : string Get the full URL for the current request.
getRequest ( ) : Illuminate\Http\Request Get the request instance.
isValidUrl ( string $path ) : boolean Determine if the given path is a valid URL.
pathFormatter ( ) : Closure Get the path formatter being used by the URL generator.
previous ( mixed $fallback = false ) : string Get the URL for the previous request.
route ( string $name, mixed $parameters = [], boolean $absolute = true ) : string Get the URL to a named route.
secure ( string $path, array $parameters = [] ) : string Generate a secure, absolute URL to the given path.
secureAsset ( string $path ) : string Generate the URL to a secure asset.
setRequest ( Illuminate\Http\Request $request ) : void Set the current request instance.
setRootControllerNamespace ( string $rootNamespace ) Set the root controller namespace.
setRoutes ( RouteCollection $routes ) Set the route collection.
setSessionResolver ( callable $sessionResolver ) Set the session resolver for the generator.
to ( string $path, mixed $extra = [], boolean | null $secure = null ) : string Generate an absolute URL to the given path.

Protected Methods

Method Description
addPortToDomain ( string $domain ) : string Add the port to the domain if necessary.
addQueryString ( string $uri, array $parameters ) : mixed | string Add a query string to the URI.
buildCompleteUrl ( string $root, string $path, string $tail = '' ) : string Format the given URL segments into a single URL.
formatDomain ( Illuminate\Routing\Route $route, array &$parameters ) : string Format the domain and port for the route and request.
formatParameters ( mixed | array $parameters ) : array Format the array of URL parameters.
getDomainAndScheme ( Illuminate\Routing\Route $route ) : string Get the domain and scheme for the route.
getNumericParameters ( array $parameters ) : array Get the numeric parameters from a given list.
getPreviousUrlFromSession ( ) : string | null Get the previous URL from the session if possible.
getRootUrl ( string $scheme, string $root = null ) : string Get the base URL for the request.
getRouteDomain ( Illuminate\Routing\Route $route, array &$parameters ) : string Get the formatted domain for a given route.
getRouteQueryString ( array $parameters ) : string Get the query string for a given route.
getRouteRoot ( Illuminate\Routing\Route $route, string $domain ) : string Get the root of the route URL.
getRouteScheme ( Illuminate\Routing\Route $route ) : string Get the scheme for the given route.
getScheme ( boolean | null $secure ) : string Get the scheme for a raw URL.
getSession ( ) : Illuminate\Session\Store | null Get the session implementation from the resolver.
getStringParameters ( array $parameters ) : array Get the string parameters from a given list.
removeIndex ( string $root ) : string Remove the index.php file from a path.
replaceNamedParameters ( string $path, array &$parameters ) : string Replace all of the named parameters in the path.
replaceRoot ( Illuminate\Routing\Route $route, string $domain, array &$parameters ) : string Replace the parameters on the root path.
replaceRoutableParameters ( array $parameters = [] ) : array Replace UrlRoutable parameters with their route parameter.
replaceRouteParameters ( string $path, array &$parameters ) : string Replace all of the wildcard parameters for a route path.
toRoute ( Illuminate\Routing\Route $route, mixed $parameters, boolean $absolute ) : string Get the URL for a given route instance.

Method Details

__construct() public method

Create a new URL Generator instance.
public __construct ( RouteCollection $routes, Illuminate\Http\Request $request ) : void
$routes RouteCollection
$request Illuminate\Http\Request
return void

action() public method

Get the URL to a controller action.
public action ( string $action, mixed $parameters = [], boolean $absolute = true ) : string
$action string
$parameters mixed
$absolute boolean
return string

addPortToDomain() protected method

Add the port to the domain if necessary.
protected addPortToDomain ( string $domain ) : string
$domain string
return string

addQueryString() protected method

Add a query string to the URI.
protected addQueryString ( string $uri, array $parameters ) : mixed | string
$uri string
$parameters array
return mixed | string

asset() public method

Generate the URL to an application asset.
public asset ( string $path, boolean | null $secure = null ) : string
$path string
$secure boolean | null
return string

assetFrom() public method

Generate the URL to an asset from a custom root domain such as CDN, etc.
public assetFrom ( string $root, string $path, boolean | null $secure = null ) : string
$root string
$path string
$secure boolean | null
return string

buildCompleteUrl() protected method

Format the given URL segments into a single URL.
protected buildCompleteUrl ( string $root, string $path, string $tail = '' ) : string
$root string
$path string
$tail string
return string

current() public method

Get the current URL for the request.
public current ( ) : string
return string

forceRootUrl() public method

Set the forced root URL.
public forceRootUrl ( string $root ) : void
$root string
return void

forceSchema() public method

Force the schema for URLs.
public forceSchema ( string $schema ) : void
$schema string
return void

formatDomain() protected method

Format the domain and port for the route and request.
protected formatDomain ( Illuminate\Routing\Route $route, array &$parameters ) : string
$route Illuminate\Routing\Route
$parameters array
return string

formatHostUsing() public method

Set a callback to be used to format the host of generated URLs.
public formatHostUsing ( Closur\Closure $callback )
$callback Closur\Closure

formatParameters() protected method

Format the array of URL parameters.
protected formatParameters ( mixed | array $parameters ) : array
$parameters mixed | array
return array

formatPathUsing() public method

Set a callback to be used to format the path of generated URLs.
public formatPathUsing ( Closur\Closure $callback )
$callback Closur\Closure

full() public method

Get the full URL for the current request.
public full ( ) : string
return string

getDomainAndScheme() protected method

Get the domain and scheme for the route.
protected getDomainAndScheme ( Illuminate\Routing\Route $route ) : string
$route Illuminate\Routing\Route
return string

getNumericParameters() protected method

Get the numeric parameters from a given list.
protected getNumericParameters ( array $parameters ) : array
$parameters array
return array

getPreviousUrlFromSession() protected method

Get the previous URL from the session if possible.
protected getPreviousUrlFromSession ( ) : string | null
return string | null

getRequest() public method

Get the request instance.
public getRequest ( ) : Illuminate\Http\Request
return Illuminate\Http\Request

getRootUrl() protected method

Get the base URL for the request.
protected getRootUrl ( string $scheme, string $root = null ) : string
$scheme string
$root string
return string

getRouteDomain() protected method

Get the formatted domain for a given route.
protected getRouteDomain ( Illuminate\Routing\Route $route, array &$parameters ) : string
$route Illuminate\Routing\Route
$parameters array
return string

getRouteQueryString() protected method

Get the query string for a given route.
protected getRouteQueryString ( array $parameters ) : string
$parameters array
return string

getRouteRoot() protected method

Get the root of the route URL.
protected getRouteRoot ( Illuminate\Routing\Route $route, string $domain ) : string
$route Illuminate\Routing\Route
$domain string
return string

getRouteScheme() protected method

Get the scheme for the given route.
protected getRouteScheme ( Illuminate\Routing\Route $route ) : string
$route Illuminate\Routing\Route
return string

getScheme() protected method

Get the scheme for a raw URL.
protected getScheme ( boolean | null $secure ) : string
$secure boolean | null
return string

getSession() protected method

Get the session implementation from the resolver.
protected getSession ( ) : Illuminate\Session\Store | null
return Illuminate\Session\Store | null

getStringParameters() protected method

Get the string parameters from a given list.
protected getStringParameters ( array $parameters ) : array
$parameters array
return array

isValidUrl() public method

Determine if the given path is a valid URL.
public isValidUrl ( string $path ) : boolean
$path string
return boolean

pathFormatter() public method

Get the path formatter being used by the URL generator.
public pathFormatter ( ) : Closure
return Closure

previous() public method

Get the URL for the previous request.
public previous ( mixed $fallback = false ) : string
$fallback mixed
return string

removeIndex() protected method

Remove the index.php file from a path.
protected removeIndex ( string $root ) : string
$root string
return string

replaceNamedParameters() protected method

Replace all of the named parameters in the path.
protected replaceNamedParameters ( string $path, array &$parameters ) : string
$path string
$parameters array
return string

replaceRoot() protected method

Replace the parameters on the root path.
protected replaceRoot ( Illuminate\Routing\Route $route, string $domain, array &$parameters ) : string
$route Illuminate\Routing\Route
$domain string
$parameters array
return string

replaceRoutableParameters() protected method

Replace UrlRoutable parameters with their route parameter.
protected replaceRoutableParameters ( array $parameters = [] ) : array
$parameters array
return array

replaceRouteParameters() protected method

Replace all of the wildcard parameters for a route path.
protected replaceRouteParameters ( string $path, array &$parameters ) : string
$path string
$parameters array
return string

route() public method

Get the URL to a named route.
public route ( string $name, mixed $parameters = [], boolean $absolute = true ) : string
$name string
$parameters mixed
$absolute boolean
return string

secure() public method

Generate a secure, absolute URL to the given path.
public secure ( string $path, array $parameters = [] ) : string
$path string
$parameters array
return string

secureAsset() public method

Generate the URL to a secure asset.
public secureAsset ( string $path ) : string
$path string
return string

setRequest() public method

Set the current request instance.
public setRequest ( Illuminate\Http\Request $request ) : void
$request Illuminate\Http\Request
return void

setRootControllerNamespace() public method

Set the root controller namespace.
public setRootControllerNamespace ( string $rootNamespace )
$rootNamespace string

setRoutes() public method

Set the route collection.
public setRoutes ( RouteCollection $routes )
$routes RouteCollection

setSessionResolver() public method

Set the session resolver for the generator.
public setSessionResolver ( callable $sessionResolver )
$sessionResolver callable

to() public method

Generate an absolute URL to the given path.
public to ( string $path, mixed $extra = [], boolean | null $secure = null ) : string
$path string
$extra mixed
$secure boolean | null
return string

toRoute() protected method

Get the URL for a given route instance.
protected toRoute ( Illuminate\Routing\Route $route, mixed $parameters, boolean $absolute ) : string
$route Illuminate\Routing\Route
$parameters mixed
$absolute boolean
return string

Property Details

$cachedRoot protected property

A cached copy of the URL root for the current request.
protected string|null $cachedRoot
return string | null

$cachedSchema protected property

A cached copy of the URL schema for the current request.
protected string|null $cachedSchema
return string | null

$dontEncode protected property

Characters that should not be URL encoded.
protected array $dontEncode
return array

$forceSchema protected property

The forced schema for URLs.
protected string $forceSchema
return string

$forcedRoot protected property

The forced URL root.
protected string $forcedRoot
return string

$formatHostUsing protected property

The callback to use to format hosts.
protected Closure $formatHostUsing
return Closure

$formatPathUsing protected property

The callback to use to format paths.
protected Closure $formatPathUsing
return Closure

$request protected property

The request instance.
protected Request,Illuminate\Http $request
return Illuminate\Http\Request

$rootNamespace protected property

The root namespace being applied to controller actions.
protected string $rootNamespace
return string

$routes protected property

The route collection.
protected RouteCollection,Illuminate\Routing $routes
return Illuminate\Routing\RouteCollection

$sessionResolver protected property

The session resolver callable.
protected callable $sessionResolver
return callable