UrlGenerator
class UrlGenerator implements UrlGenerator (View source)
Traits
Properties
static protected array | $macros | The registered string macros. |
from Macroable |
protected RouteCollectionInterface | $routes | The route collection. |
|
protected Request | $request | The request instance. |
|
protected string | $assetRoot | The asset root URL. |
|
protected string | $forcedRoot | The forced URL root. |
|
protected string | $forceScheme | The forced scheme for URLs. |
|
protected string|null | $cachedRoot | A cached copy of the URL root for the current request. |
|
protected string|null | $cachedScheme | A cached copy of the URL scheme for the current request. |
|
protected string | $rootNamespace | The root namespace being applied to controller actions. |
|
protected callable | $sessionResolver | The session resolver callable. |
|
protected callable | $keyResolver | The encryption key resolver callable. |
|
protected callable | $missingNamedRouteResolver | The missing named route resolver callable. |
|
protected Closure | $formatHostUsing | The callback to use to format hosts. |
|
protected Closure | $formatPathUsing | The callback to use to format paths. |
|
protected RouteUrlGenerator|null | $routeGenerator | The route URL generator instance. |
Methods
Get the number of seconds until the given DateTime.
If the given value is an interval, convert it to a DateTime instance.
Given a start time, format the total run time for human readability.
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Create a new URL Generator instance.
Get the full URL for the current request.
Get the current URL for the request.
Get the URL for the previous request.
Get the previous path info for the request.
Get the previous URL from the session if possible.
Generate an absolute URL to the given path.
Generate an absolute URL with the given query parameters.
Generate a secure, absolute URL to the given path.
Generate the URL to an application asset.
Generate the URL to a secure asset.
Generate the URL to an asset from a custom root domain such as CDN, etc.
Remove the index.php file from a path.
Get the default scheme for a raw URL.
Create a signed route URL for a named route.
Ensure the given signed route parameters are not reserved.
Create a temporary signed route URL for a named route.
Determine if the given request has a valid signature.
Determine if the given request has a valid signature for a relative URL.
Determine if the signature from the given request matches the URL.
Determine if the expires timestamp from the given request is not from the past.
Get the URL to a named route.
Get the URL to a controller action.
Format the given controller action.
Format the array of URL parameters.
Extract the query string from the given path.
Get the base URL for the request.
Determine if the given path is a valid URL.
Get the Route URL generator instance.
Set the default named parameters used by the URL generator.
Get the default named parameters used by the URL generator.
Force the scheme for URLs.
Force the use of the HTTPS scheme for all generated URLs.
Set the URL origin for all generated URLs.
Set the URL origin for all generated asset URLs.
Get the path formatter being used by the URL generator.
Get the request instance.
Get the session implementation from the resolver.
Set the session resolver for the generator.
Set the encryption key resolver.
Clone a new instance of the URL generator with a different encryption key resolver.
Set the callback that should be used to attempt to resolve missing named routes.
Get the root controller namespace.
Set the root controller namespace.
Details
protected int
secondsUntil(DateTimeInterface|DateInterval|int $delay)
Get the number of seconds until the given DateTime.
protected int
availableAt(DateTimeInterface|DateInterval|int $delay = 0)
Get the "available at" UNIX timestamp.
protected DateTimeInterface|int
parseDateInterval(DateTimeInterface|DateInterval|int $delay)
If the given value is an interval, convert it to a DateTime instance.
protected string
runTimeForHumans(float $startTime, float $endTime = null)
Given a start time, format the total run time for human readability.
__construct(RouteCollectionInterface $routes, Request $request, string|null $assetRoot = null)
Create a new URL Generator instance.
protected string|null
getPreviousUrlFromSession()
Get the previous URL from the session if possible.
string
to(string $path, mixed $extra = [], bool|null $secure = null)
Generate an absolute URL to the given path.
string
query(string $path, array $query = [], mixed $extra = [], bool|null $secure = null)
Generate an absolute URL with the given query parameters.
string
secure(string $path, array $parameters = [])
Generate a secure, absolute URL to the given path.
string
assetFrom(string $root, string $path, bool|null $secure = null)
Generate the URL to an asset from a custom root domain such as CDN, etc.
string
signedRoute(string $name, mixed $parameters = [], DateTimeInterface|DateInterval|int|null $expiration = null, bool $absolute = true)
Create a signed route URL for a named route.
protected void
ensureSignedRouteParametersAreNotReserved(mixed $parameters)
Ensure the given signed route parameters are not reserved.
string
temporarySignedRoute(string $name, DateTimeInterface|DateInterval|int $expiration, array $parameters = [], bool $absolute = true)
Create a temporary signed route URL for a named route.
bool
hasValidSignature(Request $request, bool $absolute = true, Closure|array $ignoreQuery = [])
Determine if the given request has a valid signature.
bool
hasValidRelativeSignature(Request $request, Closure|array $ignoreQuery = [])
Determine if the given request has a valid signature for a relative URL.
bool
hasCorrectSignature(Request $request, bool $absolute = true, Closure|array $ignoreQuery = [])
Determine if the signature from the given request matches the URL.
bool
signatureHasNotExpired(Request $request)
Determine if the expires timestamp from the given request is not from the past.
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
action(string|array $action, mixed $parameters = [], bool $absolute = true)
Get the URL to a controller action.
string
format(string $root, string $path, Route|null $route = null)
Format the given URL segments into a single URL.
$this
formatHostUsing(Closure $callback)
Set a callback to be used to format the host of generated URLs.
$this
formatPathUsing(Closure $callback)
Set a callback to be used to format the path of generated URLs.
UrlGenerator
withKeyResolver(callable $keyResolver)
Clone a new instance of the URL generator with a different encryption key resolver.
$this
resolveMissingNamedRoutesUsing(callable $missingNamedRouteResolver)
Set the callback that should be used to attempt to resolve missing named routes.