Documentation

UrlGenerator extends UrlGenerator
in package

Table of Contents

$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.
$forcedRoot  : string
The forced URL root.
$forceScheme  : string
The forced schema for URLs.
$formatHostUsing  : Closure
The callback to use to format hosts.
$formatPathUsing  : Closure
The callback to use to format paths.
$macros  : array<string|int, mixed>
The registered string macros.
$request  : Request
The request instance.
$rootNamespace  : string
The root namespace being applied to controller actions.
$routeGenerator  : RouteUrlGenerator|null
The route URL generator instance.
$routes  : RouteCollection
The route collection.
$sessionResolver  : callable
The session resolver callable.
__call()  : mixed
Dynamically handle calls to the class.
__callStatic()  : mixed
Dynamically handle calls to the class.
__construct()  : void
Create a new URL Generator instance.
action()  : string
Get the URL to a controller action.
asset()  : string
Generate the URL to an application asset.
assetFrom()  : string
Generate the URL to an asset from a custom root domain such as CDN, etc.
buildUrl()  : string
Build a URL from an array returned from a `parse_url` call.
current()  : string
Get the current URL for the request.
defaults()  : void
Set the default named parameters used by the URL generator.
forceRootUrl()  : void
Set the forced root URL.
forceScheme()  : void
Force the scheme for URLs.
format()  : string
Format the given URL segments into a single URL.
formatHostUsing()  : $this
Set a callback to be used to format the host of generated URLs.
formatParameters()  : array<string|int, mixed>
Format the array of URL parameters.
formatPathUsing()  : $this
Set a callback to be used to format the path of generated URLs.
formatRoot()  : string
Get the base URL for the request.
formatScheme()  : string
Get the default scheme for a raw URL.
full()  : string
Get the full URL for the current request.
getDefaultParameters()  : array<string|int, mixed>
Get the default named parameters used by the URL generator.
getRequest()  : Request
Get the request instance.
hasMacro()  : bool
Checks if macro is registered.
isValidUrl()  : bool
Determine if the given path is a valid URL.
macro()  : void
Register a custom macro.
mixin()  : void
Mix another object into the class.
pathFormatter()  : Closure
Get the path formatter being used by the URL generator.
previous()  : string
Get the URL for the previous request.
route()  : string
Get the URL to a named route.
secure()  : string
Generate a secure, absolute URL to the given path.
secureAsset()  : string
Generate the URL to a secure asset.
setRequest()  : void
Set the current request instance.
setRootControllerNamespace()  : $this
Set the root controller namespace.
setRoutes()  : $this
Set the route collection.
setSessionResolver()  : $this
Set the session resolver for the generator.
to()  : string
Generate an absolute URL to the given path.
extractQueryString()  : array<string|int, mixed>
Extract the query string from the given path.
formatAction()  : string
Format the given controller action.
getPreviousUrlFromSession()  : string|null
Get the previous URL from the session if possible.
getSession()  : Store|null
Get the session implementation from the resolver.
removeIndex()  : string
Remove the index.php file from a path.
routeUrl()  : RouteUrlGenerator
Get the Route URL generator instance.
toRoute()  : string
Get the URL for a given route instance.

Properties

$cachedRoot

A cached copy of the URL root for the current request.

protected string|null $cachedRoot

$cachedSchema

A cached copy of the URL schema for the current request.

protected string|null $cachedSchema

$forcedRoot

The forced URL root.

protected string $forcedRoot

$forceScheme

The forced schema for URLs.

protected string $forceScheme

$formatHostUsing

The callback to use to format hosts.

protected Closure $formatHostUsing

$formatPathUsing

The callback to use to format paths.

protected Closure $formatPathUsing

$macros

The registered string macros.

protected static array<string|int, mixed> $macros = []

$rootNamespace

The root namespace being applied to controller actions.

protected string $rootNamespace

$sessionResolver

The session resolver callable.

protected callable $sessionResolver

Methods

__call()

Dynamically handle calls to the class.

public __call(string $method, array<string|int, mixed> $parameters) : mixed
Parameters
$method : string
$parameters : array<string|int, mixed>
Tags
throws
BadMethodCallException
Return values
mixed

__callStatic()

Dynamically handle calls to the class.

public static __callStatic(string $method, array<string|int, mixed> $parameters) : mixed
Parameters
$method : string
$parameters : array<string|int, mixed>
Tags
throws
BadMethodCallException
Return values
mixed

action()

Get the URL to a controller action.

public action(string $action[, mixed $parameters = [] ][, bool $absolute = true ]) : string
Parameters
$action : string
$parameters : mixed = []
$absolute : bool = true
Tags
throws
InvalidArgumentException
Return values
string

asset()

Generate the URL to an application asset.

public asset(string $path[, bool|null $secure = null ]) : string
Parameters
$path : string
$secure : bool|null = null
Return values
string

assetFrom()

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

public assetFrom(string $root, string $path[, bool|null $secure = null ]) : string
Parameters
$root : string
$path : string
$secure : bool|null = null
Return values
string

buildUrl()

Build a URL from an array returned from a `parse_url` call.

public static buildUrl(array<string|int, mixed> $url[, array<string|int, mixed> $replace = [] ][, mixed $flags = HTTP_URL_REPLACE ][, array<string|int, mixed> &$newUrl = [] ]) : string

This function serves as a counterpart to the parse_url method available in PHP, and a userland implementation of the http_build_query method provided by the PECL HTTP module. This allows a developer to parse a URL to an array and make adjustments to the URL parts before combining them into a valid URL reference string.

Based off of the implentation at https://github.com/jakeasmith/http_build_url/blob/master/src/http_build_url.php.

Parameters
$url : array<string|int, mixed>

The URL parts, as an array. Must match the structure returned from a parse_url call.

$replace : array<string|int, mixed> = []

The URL replacement parts. Allows a developer to replace certain sections of the URL with a different value.

$flags : mixed = HTTP_URL_REPLACE

A bitmask of binary or'ed HTTP_URL constants. By default, this is set to HTTP_URL_REPLACE.

$newUrl : array<string|int, mixed> = []

If set, this will be filled with the array parts of the composed URL, similar to the return value of parse_url.

Return values
string

The generated URL as a string

current()

Get the current URL for the request.

public current() : string
Return values
string

defaults()

Set the default named parameters used by the URL generator.

public defaults(array<string|int, mixed> $defaults) : void
Parameters
$defaults : array<string|int, mixed>
Return values
void

forceRootUrl()

Set the forced root URL.

public forceRootUrl(string $root) : void
Parameters
$root : string
Return values
void

forceScheme()

Force the scheme for URLs.

public forceScheme(string $schema) : void
Parameters
$schema : string
Return values
void

format()

Format the given URL segments into a single URL.

public format(string $root, string $path) : string
Parameters
$root : string
$path : string
Return values
string

formatHostUsing()

Set a callback to be used to format the host of generated URLs.

public formatHostUsing(Closure $callback) : $this
Parameters
$callback : Closure
Return values
$this

formatParameters()

Format the array of URL parameters.

public formatParameters(mixed|array<string|int, mixed> $parameters) : array<string|int, mixed>
Parameters
$parameters : mixed|array<string|int, mixed>
Return values
array<string|int, mixed>

formatPathUsing()

Set a callback to be used to format the path of generated URLs.

public formatPathUsing(Closure $callback) : $this
Parameters
$callback : Closure
Return values
$this

formatRoot()

Get the base URL for the request.

public formatRoot(string $scheme[, string $root = null ]) : string
Parameters
$scheme : string
$root : string = null
Return values
string

formatScheme()

Get the default scheme for a raw URL.

public formatScheme(bool|null $secure) : string
Parameters
$secure : bool|null
Return values
string

full()

Get the full URL for the current request.

public full() : string
Return values
string

getDefaultParameters()

Get the default named parameters used by the URL generator.

public getDefaultParameters() : array<string|int, mixed>
Return values
array<string|int, mixed>

hasMacro()

Checks if macro is registered.

public static hasMacro(string $name) : bool
Parameters
$name : string
Return values
bool

isValidUrl()

Determine if the given path is a valid URL.

public isValidUrl(string $path) : bool
Parameters
$path : string
Return values
bool

macro()

Register a custom macro.

public static macro(string $name, object|callable $macro) : void
Parameters
$name : string
$macro : object|callable
Return values
void

mixin()

Mix another object into the class.

public static mixin(object $mixin) : void
Parameters
$mixin : object
Return values
void

pathFormatter()

Get the path formatter being used by the URL generator.

public pathFormatter() : Closure
Return values
Closure

previous()

Get the URL for the previous request.

public previous([mixed $fallback = false ]) : string
Parameters
$fallback : mixed = false
Return values
string

route()

Get the URL to a named route.

public route(string $name[, mixed $parameters = [] ][, bool $absolute = true ]) : string
Parameters
$name : string
$parameters : mixed = []
$absolute : bool = true
Tags
throws
InvalidArgumentException
Return values
string

secure()

Generate a secure, absolute URL to the given path.

public secure(string $path[, array<string|int, mixed> $parameters = [] ]) : string
Parameters
$path : string
$parameters : array<string|int, mixed> = []
Return values
string

secureAsset()

Generate the URL to a secure asset.

public secureAsset(string $path) : string
Parameters
$path : string
Return values
string

setRequest()

Set the current request instance.

public setRequest(Request $request) : void
Parameters
$request : Request
Return values
void

setRootControllerNamespace()

Set the root controller namespace.

public setRootControllerNamespace(string $rootNamespace) : $this
Parameters
$rootNamespace : string
Return values
$this

setSessionResolver()

Set the session resolver for the generator.

public setSessionResolver(callable $sessionResolver) : $this
Parameters
$sessionResolver : callable
Return values
$this

to()

Generate an absolute URL to the given path.

public to(string $path[, mixed $extra = [] ][, bool|null $secure = null ]) : string
Parameters
$path : string
$extra : mixed = []
$secure : bool|null = null
Return values
string

extractQueryString()

Extract the query string from the given path.

protected extractQueryString(string $path) : array<string|int, mixed>
Parameters
$path : string
Return values
array<string|int, mixed>

formatAction()

Format the given controller action.

protected formatAction(string $action) : string
Parameters
$action : string
Return values
string

getPreviousUrlFromSession()

Get the previous URL from the session if possible.

protected getPreviousUrlFromSession() : string|null
Return values
string|null

getSession()

Get the session implementation from the resolver.

protected getSession() : Store|null
Return values
Store|null

removeIndex()

Remove the index.php file from a path.

protected removeIndex(string $root) : string
Parameters
$root : string
Return values
string

toRoute()

Get the URL for a given route instance.

protected toRoute(Route $route, mixed $parameters, bool $absolute) : string
Parameters
$route : Route
$parameters : mixed
$absolute : bool
Tags
throws
UrlGenerationException
Return values
string

Search results