class UrlGenerator implements UrlGenerator (View source)

Traits

Properties

static protected array $macros The registered string macros. from Macroable
protected RouteCollection $routes The route collection.
protected Request $request The request instance.
protected string $forcedRoot The forced URL root.
protected string $forceSchema The forced schema for URLs.
protected string|null $cachedRoot A cached copy of the URL root for the current request.
protected string|null $cachedSchema A cached copy of the URL schema for the current request.
protected string $rootNamespace The root namespace being applied to controller actions.
protected callable $sessionResolver The session resolver callable.
protected array $dontEncode Characters that should not be URL encoded.

Methods

static void
macro(string $name, callable $macro)

Register a custom macro.

from Macroable
static bool
hasMacro(string $name)

Checks if macro is registered.

from Macroable
static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

from Macroable
mixed
__call(string $method, array $parameters)

Dynamically handle calls to the class.

from Macroable
void
__construct(RouteCollection $routes, Request $request)

Create a new URL Generator instance.

string
full()

Get the full URL for the current request.

string
current()

Get the current URL for the request.

string
previous(mixed $fallback = false)

Get the URL for the previous request.

string
to(string $path, mixed $extra = [], bool $secure = null)

Generate an absolute URL to the given path.

string
secure(string $path, array $parameters = [])

Generate a secure, absolute URL to the given path.

string
asset(string $path, bool $secure = null)

Generate a URL to an application asset.

string
assetFrom(string $root, string $path, bool|null $secure = null)

Generate a URL to an asset from a custom root domain such as CDN, etc.

string
removeIndex(string $root)

Remove the index.php file from a path.

string
secureAsset(string $path)

Generate a URL to a secure asset.

string
getScheme(bool|null $secure)

Get the scheme for a raw URL.

void
forceSchema(string $schema)

Force the schema for URLs.

string
route(string $name, mixed $parameters = [], bool $absolute = true)

Get the URL to a named route.

string
toRoute(Route $route, mixed $parameters, bool $absolute)

Get the URL for a given route instance.

string
replaceRoot(Route $route, string $domain, array $parameters)

Replace the parameters on the root path.

string
replaceRouteParameters(string $path, array $parameters)

Replace all of the wildcard parameters for a route path.

string
replaceNamedParameters(string $path, array $parameters)

Replace all of the named parameters in the path.

mixed|string
addQueryString(string $uri, array $parameters)

Add a query string to the URI.

array
formatParameters(mixed|array $parameters)

Format the array of URL parameters.

array
replaceRoutableParameters(array $parameters = [])

Replace UrlRoutable parameters with their route parameter.

string
getRouteQueryString(array $parameters)

Get the query string for a given route.

array
getStringParameters(array $parameters)

Get the string parameters from a given list.

array
getNumericParameters(array $parameters)

Get the numeric parameters from a given list.

string
getRouteDomain(Route $route, array $parameters)

Get the formatted domain for a given route.

string
formatDomain(Route $route, array $parameters)

Format the domain and port for the route and request.

string
getDomainAndScheme(Route $route)

Get the domain and scheme for the route.

string
addPortToDomain(string $domain)

Add the port to the domain if necessary.

string
getRouteRoot(Route $route, string $domain)

Get the root of the route URL.

string
getRouteScheme(Route $route)

Get the scheme for the given route.

string
action(string $action, mixed $parameters = [], bool $absolute = true)

Get the URL to a controller action.

string
getRootUrl(string $scheme, string $root = null)

Get the base URL for the request.

void
forceRootUrl(string $root)

Set the forced root URL.

bool
isValidUrl(string $path)

Determine if the given path is a valid URL.

string
trimUrl(string $root, string $path, string $tail = '')

Format the given URL segments into a single URL.

getRequest()

Get the request instance.

void
setRequest(Request $request)

Set the current request instance.

$this
setRoutes(RouteCollection $routes)

Set the route collection.

string|null
getPreviousUrlFromSession()

Get the previous URL from the session if possible.

Store|null
getSession()

Get the session implementation from the resolver.

$this
setSessionResolver(callable $sessionResolver)

Set the session resolver for the generator.

$this
setRootControllerNamespace(string $rootNamespace)

Set the root controller namespace.

Details

static void macro(string $name, callable $macro)

Register a custom macro.

Parameters

string $name
callable $macro

Return Value

void

static bool hasMacro(string $name)

Checks if macro is registered.

Parameters

string $name

Return Value

bool

static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

void __construct(RouteCollection $routes, Request $request)

Create a new URL Generator instance.

Parameters

RouteCollection $routes
Request $request

Return Value

void

string full()

Get the full URL for the current request.

Return Value

string

string current()

Get the current URL for the request.

Return Value

string

string previous(mixed $fallback = false)

Get the URL for the previous request.

Parameters

mixed $fallback

Return Value

string

string to(string $path, mixed $extra = [], bool $secure = null)

Generate an absolute URL to the given path.

Parameters

string $path
mixed $extra
bool $secure

Return Value

string

string secure(string $path, array $parameters = [])

Generate a secure, absolute URL to the given path.

Parameters

string $path
array $parameters

Return Value

string

string asset(string $path, bool $secure = null)

Generate a URL to an application asset.

Parameters

string $path
bool $secure

Return Value

string

string assetFrom(string $root, string $path, bool|null $secure = null)

Generate a URL to an asset from a custom root domain such as CDN, etc.

Parameters

string $root
string $path
bool|null $secure

Return Value

string

protected string removeIndex(string $root)

Remove the index.php file from a path.

Parameters

string $root

Return Value

string

string secureAsset(string $path)

Generate a URL to a secure asset.

Parameters

string $path

Return Value

string

protected string getScheme(bool|null $secure)

Get the scheme for a raw URL.

Parameters

bool|null $secure

Return Value

string

void forceSchema(string $schema)

Force the schema for URLs.

Parameters

string $schema

Return Value

void

string route(string $name, mixed $parameters = [], bool $absolute = true)

Get the URL to a named route.

Parameters

string $name
mixed $parameters
bool $absolute

Return Value

string

Exceptions

InvalidArgumentException

protected string toRoute(Route $route, mixed $parameters, bool $absolute)

Get the URL for a given route instance.

Parameters

Route $route
mixed $parameters
bool $absolute

Return Value

string

Exceptions

UrlGenerationException

protected string replaceRoot(Route $route, string $domain, array $parameters)

Replace the parameters on the root path.

Parameters

Route $route
string $domain
array $parameters

Return Value

string

protected string replaceRouteParameters(string $path, array $parameters)

Replace all of the wildcard parameters for a route path.

Parameters

string $path
array $parameters

Return Value

string

protected string replaceNamedParameters(string $path, array $parameters)

Replace all of the named parameters in the path.

Parameters

string $path
array $parameters

Return Value

string

protected mixed|string addQueryString(string $uri, array $parameters)

Add a query string to the URI.

Parameters

string $uri
array $parameters

Return Value

mixed|string

protected array formatParameters(mixed|array $parameters)

Format the array of URL parameters.

Parameters

mixed|array $parameters

Return Value

array

protected array replaceRoutableParameters(array $parameters = [])

Replace UrlRoutable parameters with their route parameter.

Parameters

array $parameters

Return Value

array

protected string getRouteQueryString(array $parameters)

Get the query string for a given route.

Parameters

array $parameters

Return Value

string

protected array getStringParameters(array $parameters)

Get the string parameters from a given list.

Parameters

array $parameters

Return Value

array

protected array getNumericParameters(array $parameters)

Get the numeric parameters from a given list.

Parameters

array $parameters

Return Value

array

protected string getRouteDomain(Route $route, array $parameters)

Get the formatted domain for a given route.

Parameters

Route $route
array $parameters

Return Value

string

protected string formatDomain(Route $route, array $parameters)

Format the domain and port for the route and request.

Parameters

Route $route
array $parameters

Return Value

string

protected string getDomainAndScheme(Route $route)

Get the domain and scheme for the route.

Parameters

Route $route

Return Value

string

protected string addPortToDomain(string $domain)

Add the port to the domain if necessary.

Parameters

string $domain

Return Value

string

protected string getRouteRoot(Route $route, string $domain)

Get the root of the route URL.

Parameters

Route $route
string $domain

Return Value

string

protected string getRouteScheme(Route $route)

Get the scheme for the given route.

Parameters

Route $route

Return Value

string

string action(string $action, mixed $parameters = [], bool $absolute = true)

Get the URL to a controller action.

Parameters

string $action
mixed $parameters
bool $absolute

Return Value

string

Exceptions

InvalidArgumentException

protected string getRootUrl(string $scheme, string $root = null)

Get the base URL for the request.

Parameters

string $scheme
string $root

Return Value

string

void forceRootUrl(string $root)

Set the forced root URL.

Parameters

string $root

Return Value

void

bool isValidUrl(string $path)

Determine if the given path is a valid URL.

Parameters

string $path

Return Value

bool

protected string trimUrl(string $root, string $path, string $tail = '')

Format the given URL segments into a single URL.

Parameters

string $root
string $path
string $tail

Return Value

string

Request getRequest()

Get the request instance.

Return Value

Request

void setRequest(Request $request)

Set the current request instance.

Parameters

Request $request

Return Value

void

$this setRoutes(RouteCollection $routes)

Set the route collection.

Parameters

RouteCollection $routes

Return Value

$this

protected string|null getPreviousUrlFromSession()

Get the previous URL from the session if possible.

Return Value

string|null

protected Store|null getSession()

Get the session implementation from the resolver.

Return Value

Store|null

$this setSessionResolver(callable $sessionResolver)

Set the session resolver for the generator.

Parameters

callable $sessionResolver

Return Value

$this

$this setRootControllerNamespace(string $rootNamespace)

Set the root controller namespace.

Parameters

string $rootNamespace

Return Value

$this