master

laravel/framework

Last updated at: 29/12/2023 09:21

UrlGenerator.php

TLDR

This file, UrlGenerator.php, is an interface for generating URLs in the Laravel framework. It defines several methods for different types of URL generation, including generating URLs for the current request, generating secure URLs, generating URLs for named routes, and more.

Methods

current

This method returns the current URL for the request.

previous

This method returns the URL for the previous request. It takes an optional parameter $fallback that specifies a fallback URL to use if there is no previous request.

to

This method generates an absolute URL to the given path. It takes the path as the first parameter and optional parameters $extra and $secure to specify additional URL parameters and the secure flag respectively.

secure

This method generates a secure, absolute URL to the given path. It takes the path as the first parameter and an optional array of parameters $parameters.

asset

This method generates the URL to an application asset. It takes the asset path as the first parameter and an optional $secure flag to specify if the URL should be secure.

route

This method generates the URL to a named route. It takes the route name as the first parameter and optional parameters $parameters and $absolute to specify additional URL parameters and whether the URL should be absolute.

signedRoute

This method creates a signed route URL for a named route. It takes the route name as the first parameter and optional parameters $parameters, $expiration, and $absolute to specify additional URL parameters, expiration time of the signed route, and whether the URL should be absolute.

temporarySignedRoute

This method creates a temporary signed route URL for a named route. It takes the route name as the first parameter, $expiration to specify the expiration time of the signed route, and optional parameters $parameters and $absolute to specify additional URL parameters and whether the URL should be absolute.

action

This method generates the URL to a controller action. It takes the action as either a string or an array of controller and method names, optional parameters $parameters, and $absolute flag to specify additional URL parameters and whether the URL should be absolute.

getRootControllerNamespace

This method returns the root controller namespace.

setRootControllerNamespace

This method sets the root controller namespace. It takes the root namespace as the first parameter and returns $this.

<?php

namespace Illuminate\Contracts\Routing;

interface UrlGenerator
{
    /**
     * Get the current URL for the request.
     *
     * @return string
     */
    public function current();

    /**
     * Get the URL for the previous request.
     *
     * @param  mixed  $fallback
     * @return string
     */
    public function previous($fallback = false);

    /**
     * Generate an absolute URL to the given path.
     *
     * @param  string  $path
     * @param  mixed  $extra
     * @param  bool|null  $secure
     * @return string
     */
    public function to($path, $extra = [], $secure = null);

    /**
     * Generate a secure, absolute URL to the given path.
     *
     * @param  string  $path
     * @param  array  $parameters
     * @return string
     */
    public function secure($path, $parameters = []);

    /**
     * Generate the URL to an application asset.
     *
     * @param  string  $path
     * @param  bool|null  $secure
     * @return string
     */
    public function asset($path, $secure = null);

    /**
     * Get the URL to a named route.
     *
     * @param  string  $name
     * @param  mixed  $parameters
     * @param  bool  $absolute
     * @return string
     *
     * @throws \InvalidArgumentException
     */
    public function route($name, $parameters = [], $absolute = true);

    /**
     * Create a signed route URL for a named route.
     *
     * @param  string  $name
     * @param  mixed  $parameters
     * @param  \DateTimeInterface|\DateInterval|int|null  $expiration
     * @param  bool  $absolute
     * @return string
     *
     * @throws \InvalidArgumentException
     */
    public function signedRoute($name, $parameters = [], $expiration = null, $absolute = true);

    /**
     * Create a temporary signed route URL for a named route.
     *
     * @param  string  $name
     * @param  \DateTimeInterface|\DateInterval|int  $expiration
     * @param  array  $parameters
     * @param  bool  $absolute
     * @return string
     */
    public function temporarySignedRoute($name, $expiration, $parameters = [], $absolute = true);

    /**
     * Get the URL to a controller action.
     *
     * @param  string|array  $action
     * @param  mixed  $parameters
     * @param  bool  $absolute
     * @return string
     */
    public function action($action, $parameters = [], $absolute = true);

    /**
     * Get the root controller namespace.
     *
     * @return string
     */
    public function getRootControllerNamespace();

    /**
     * Set the root controller namespace.
     *
     * @param  string  $rootNamespace
     * @return $this
     */
    public function setRootControllerNamespace($rootNamespace);
}