UrlGenerator
class UrlGenerator implements UrlGenerator (View source)
Traits
InteractsWithTime |
Macroable |
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 | $forceScheme | 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 callable | $keyResolver | The encryption key 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
int | secondsUntil(DateTimeInterface|DateInterval|int $delay) Get the number of seconds until the given DateTime. | from InteractsWithTime |
int | availableAt(DateTimeInterface|DateInterval|int $delay = 0) Get the "available at" UNIX timestamp. | from InteractsWithTime |
DateTimeInterface|int | parseDateInterval(DateTimeInterface|DateInterval|int $delay) If the given value is an interval, convert it to a DateTime instance. | from InteractsWithTime |
int | currentTime() Get the current system time as a UNIX timestamp. | from InteractsWithTime |
static void | macro(string $name, object|callable $macro) Register a custom macro. | from Macroable |
static void | mixin(object $mixin) Mix another object into the class. | 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|null | getPreviousUrlFromSession() Get the previous URL from the session if possible. | |
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 the URL to an application asset. | |
string | secureAsset(string $path) Generate the URL to a secure asset. | |
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 | removeIndex(string $root) Remove the index.php file from a path. | |
string | formatScheme(bool|null $secure = null) Get the default scheme for a raw URL. | |
string | signedRoute(string $name, array $parameters = [], DateTimeInterface|int $expiration = null, bool $absolute = true) Create a signed route URL for a named route. | |
string | temporarySignedRoute(string $name, DateTimeInterface|int $expiration, array $parameters = [], bool $absolute = true) Create a temporary signed route URL for a named route. | |
bool | hasValidSignature(Request $request) Determine if the given request has a valid signature. | |
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 | formatAction(string|array $action) Format the given controller action. | |
array | formatParameters(mixed|array $parameters) Format the array of URL parameters. | |
array | extractQueryString(string $path) Extract the query string from the given path. | |
string | formatRoot(string $scheme, string $root = null) Get the base URL for the request. | |
string | format(string $root, string $path, Route|null $route = null) Format the given URL segments into a single URL. | |
bool | isValidUrl(string $path) Determine if the given path is a valid URL. | |
RouteUrlGenerator | routeUrl() Get the Route URL generator instance. | |
void | defaults(array $defaults) Set the default named parameters used by the URL generator. | |
array | getDefaultParameters() Get the default named parameters used by the URL generator. | |
void | forceScheme(string $schema) Force the scheme for URLs. | |
void | forceRootUrl(string $root) Set the forced root 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. | |
Closure | pathFormatter() Get the path formatter being used by the URL generator. | |
Request | getRequest() Get the request instance. | |
void | setRequest(Request $request) Set the current request instance. | |
$this | setRoutes(RouteCollection $routes) Set the route collection. | |
Store|null | getSession() Get the session implementation from the resolver. | |
$this | setSessionResolver(callable $sessionResolver) Set the session resolver for the generator. | |
$this | setKeyResolver(callable $keyResolver) Set the encryption key resolver. | |
$this | setRootControllerNamespace(string $rootNamespace) 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 int currentTime()
Get the current system time as a UNIX timestamp.
static void macro(string $name, object|callable $macro)
Register a custom macro.
static void mixin(object $mixin)
Mix another object into the class.
static bool hasMacro(string $name)
Checks if macro is registered.
static mixed __callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
mixed __call(string $method, array $parameters)
Dynamically handle calls to the class.
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.
protected string|null getPreviousUrlFromSession()
Get the previous URL from the session if possible.
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 the URL to an application asset.
string secureAsset(string $path)
Generate the URL to a secure asset.
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.
protected string removeIndex(string $root)
Remove the index.php file from a path.
string formatScheme(bool|null $secure = null)
Get the default scheme for a raw URL.
string signedRoute(string $name, array $parameters = [], DateTimeInterface|int $expiration = null, bool $absolute = true)
Create a signed route URL for a named route.
string temporarySignedRoute(string $name, DateTimeInterface|int $expiration, array $parameters = [], bool $absolute = true)
Create a temporary signed route URL for a named route.
bool hasValidSignature(Request $request)
Determine if the given request has a valid signature.
string route(string $name, mixed $parameters = [], bool $absolute = true)
Get the URL to a named route.
protected 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.
protected string formatAction(string|array $action)
Format the given controller action.
array formatParameters(mixed|array $parameters)
Format the array of URL parameters.
protected array extractQueryString(string $path)
Extract the query string from the given path.
string formatRoot(string $scheme, string $root = null)
Get the base URL for the request.
string format(string $root, string $path, Route|null $route = null)
Format the given URL segments into a single URL.
bool isValidUrl(string $path)
Determine if the given path is a valid URL.
protected RouteUrlGenerator routeUrl()
Get the Route URL generator instance.
void defaults(array $defaults)
Set the default named parameters used by the URL generator.
array getDefaultParameters()
Get the default named parameters used by the URL generator.
void forceScheme(string $schema)
Force the scheme for URLs.
void forceRootUrl(string $root)
Set the forced root 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.
Closure pathFormatter()
Get the path formatter being used by the URL generator.
Request getRequest()
Get the request instance.
void setRequest(Request $request)
Set the current request instance.
$this setRoutes(RouteCollection $routes)
Set the route collection.
protected Store|null getSession()
Get the session implementation from the resolver.
$this setSessionResolver(callable $sessionResolver)
Set the session resolver for the generator.
$this setKeyResolver(callable $keyResolver)
Set the encryption key resolver.
$this setRootControllerNamespace(string $rootNamespace)
Set the root controller namespace.
© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/5.7/Illuminate/Routing/UrlGenerator.html