Skip to content

Internals Redirect Redirect

Stefan Crkvenjakov edited this page Oct 7, 2026 · 1 revision

redirect\Redirect

Framework Internals · Subsystem overview · Developer guide

Source: awt_src/classes/redirect/Redirect.php · Snapshot 8411f4287706.

Redirect stores a target consumed by the web bootstrap. Breadcrumbs keeps the last rendered page in the PHP session.

Imports and dependencies

use redirect\breadcrumbs\BreadCrumbs;

Redirect

Declaration and architectural role

class Redirect extends BreadCrumbs

Source description (behavioral corrections are recorded in Known discrepancies):

The Redirect class extends the BreadCrumbs class and is responsible for managing redirection logic, including routing, custom redirects, and going back to the previous page.

Constants, enum cases, traits and properties

Declarations below preserve visibility, type, default and modifiers exactly. A typed property without an initializer remains uninitialized until its constructor or another method assigns it. Mutable fields belong to this instance unless marked static; readonly fields can be initialized once. Constructor-promoted properties are also listed below.

Member Declaration Purpose or source contract
$routes public array $routes = []; Used by setRoutes(), route().
$redirectTo public string $redirectTo; Used by route(), back(), redirect(), getRedirectTo().

Method index

Method Signature
__construct public function __construct()
setRoutes public function setRoutes(array $routes): void
route public function route(string $name): self
back public function back(): self
redirect public function redirect(string $path): self
getRedirectTo public function getRedirectTo(): string

__construct

Source line 16

public function __construct()

Computes or delegates the operation shown below; no explicit receiver property assignment or throw occurs in this method.

Implementation, validation guards and interaction order
public function __construct()
    {
        parent::__construct();
    }

setRoutes

Source line 30

public function setRoutes(array $routes): void

Parameters

Parameter Type, modifiers and default Purpose
$routes array $routes An associative array of routes.

Sets the routes for the redirection logic.

This method assigns an array of routes to the $routes property. Each route is a key-value pair where the key is the route name, and the value is the corresponding URL.

@param array $routes An associative array of routes.

State writes: $this->routes.

Implementation, validation guards and interaction order
/**
     * Sets the routes for the redirection logic.
     *
     * This method assigns an array of routes to the `$routes` property.
     * Each route is a key-value pair where the key is the route name,
     * and the value is the corresponding URL.
     *
     * @param array $routes An associative array of routes.
     */
    public function setRoutes(array $routes): void
    {
        $this->routes = $routes;
    }

route

Source line 45

public function route(string $name): self

Parameters

Parameter Type, modifiers and default Purpose
$name string $name The name of the route.

Sets the redirection URL based on a named route.

This method accepts a route name, retrieves the corresponding URL from the $routes array, and assigns it to the $redirectTo property.

@param string $name The name of the route. @return self Returns the instance of the Redirect class to allow method chaining.

State writes: $this->redirectTo.

Return expressions (including local callbacks): $this.

Implementation, validation guards and interaction order
/**
     * Sets the redirection URL based on a named route.
     *
     * This method accepts a route name, retrieves the corresponding URL from the `$routes` array,
     * and assigns it to the `$redirectTo` property.
     *
     * @param string $name The name of the route.
     * @return self Returns the instance of the Redirect class to allow method chaining.
     */
    public function route(string $name): self
    {
        $this->redirectTo = $this->routes[$name];
        return $this;
    }

back

Source line 59

public function back(): self

Sets the redirection URL to the last visited page.

This method retrieves the last visited page URL (via the getLast() method inherited from BreadCrumbs) and assigns it to the $redirectTo property.

@return self Returns the instance of the Redirect class to allow method chaining.

State writes: $this->redirectTo.

Return expressions (including local callbacks): $this.

Implementation, validation guards and interaction order
/**
     * Sets the redirection URL to the last visited page.
     *
     * This method retrieves the last visited page URL (via the `getLast()` method inherited
     * from BreadCrumbs) and assigns it to the `$redirectTo` property.
     *
     * @return self Returns the instance of the Redirect class to allow method chaining.
     */
    public function back(): self
    {
        $this->redirectTo = $this->getLast();
        return $this;
    }

redirect

Source line 73

public function redirect(string $path): self

Parameters

Parameter Type, modifiers and default Purpose
$path string $path The URL to which the user should be redirected.

Manually sets the redirection URL to a specific path.

This method directly assigns a given path (or URL) to the $redirectTo property.

@param string $path The URL to which the user should be redirected. @return self Returns the instance of the Redirect class to allow method chaining.

State writes: $this->redirectTo.

Return expressions (including local callbacks): $this.

Implementation, validation guards and interaction order
/**
     * Manually sets the redirection URL to a specific path.
     *
     * This method directly assigns a given path (or URL) to the `$redirectTo` property.
     *
     * @param string $path The URL to which the user should be redirected.
     * @return self Returns the instance of the Redirect class to allow method chaining.
     */
    public function redirect(string $path): self
    {
        $this->redirectTo = $path;
        return $this;
    }

getRedirectTo

Source line 87

public function getRedirectTo(): string

Retrieves the current redirection URL.

This method returns the value of the $redirectTo property, which contains the URL to which the user will be redirected.

@return string The URL to redirect to.

Return expressions (including local callbacks): $this->redirectTo.

Implementation, validation guards and interaction order
/**
     * Retrieves the current redirection URL.
     *
     * This method returns the value of the `$redirectTo` property, which contains
     * the URL to which the user will be redirected.
     *
     * @return string The URL to redirect to.
     */
    public function getRedirectTo(): string
    {
        return $this->redirectTo;
    }

Related types

Clone this wiki locally