final class RequestViewHelpers (View source)

Exposes request-local URL, old-input and flash operations to rendered views.

Constants

private OLD_INPUT_NAMESPACE

Methods

__construct(ServerRequestInterface $request, UrlGenerator $urlGenerator, FlashBagInterface|null $flash = null, SessionInterface|null $session = null, callable|null $absoluteUrl = null)

Captures one request and optional default-session state for the renderer's active scope.

mixed
old(string $key, mixed $default = '')

Resolves canonical session old input before flash and caller fallbacks.

mixed
mixed
flash(string $key, mixed $default = null)

Pulls one transient value from the optional flash bag.

mixed
string

Returns the active request path without its query string.

string
string

Returns the active request query string without a leading question mark.

string
string
currentUrl(bool $withQuery = true)

Returns the active request path with an optional query string.

string
string
currentFullUrl(bool $withQuery = true)

Returns an absolute request URL only through the configured safe origin resolver.

string
bool
isUrlActive(string $url, bool $startsWith = false)

Compares a URL against the active path using exact or prefix matching.

bool
bool
isRouteActive(string $route, array $params = [], bool $startsWith = false)

Generates a route URL and compares it with the active request path.

bool

Details

__construct

__construct(ServerRequestInterface $request, UrlGenerator $urlGenerator, FlashBagInterface|null $flash = null, SessionInterface|null $session = null, callable|null $absoluteUrl = null)

Captures one request and optional default-session state for the renderer's active scope.

Parameters

ServerRequestInterface $request
UrlGenerator $urlGenerator
FlashBagInterface|null $flash
SessionInterface|null $session
callable|null $absoluteUrl

old

mixed old(string $key, mixed $default = '')

Resolves canonical session old input before flash and caller fallbacks.

Parameters

string $key
mixed $default

Return Value

mixed

flash

mixed flash(string $key, mixed $default = null)

Pulls one transient value from the optional flash bag.

Parameters

string $key
mixed $default

Return Value

mixed

currentPath

string currentPath()

Returns the active request path without its query string.

Return Value

string

currentQuery

string currentQuery()

Returns the active request query string without a leading question mark.

Return Value

string

currentUrl

string currentUrl(bool $withQuery = true)

Returns the active request path with an optional query string.

Parameters

bool $withQuery

Return Value

string

currentFullUrl

string currentFullUrl(bool $withQuery = true)

Returns an absolute request URL only through the configured safe origin resolver.

Parameters

bool $withQuery

Return Value

string

Exceptions

LogicException

isUrlActive

bool isUrlActive(string $url, bool $startsWith = false)

Compares a URL against the active path using exact or prefix matching.

Parameters

string $url
bool $startsWith

Return Value

bool

isRouteActive

bool isRouteActive(string $route, array $params = [], bool $startsWith = false)

Generates a route URL and compares it with the active request path.

Parameters

string $route
array $params
bool $startsWith

Return Value

bool