class PathValidator implements PathValidatorInterface (View source)

Provides a default path validator and access checker.

Properties

protected AccessAwareRouterInterface $accessAwareRouter

The access aware router.

protected UrlMatcherInterface $accessUnawareRouter

A router implementation which does not check access.

protected AccountInterface $account

The current user.

protected InboundPathProcessorInterface $pathProcessor

The path processor.

Methods

__construct(AccessAwareRouterInterface $access_aware_router, UrlMatcherInterface $access_unaware_router, AccountInterface $account, InboundPathProcessorInterface $path_processor)

Creates a new PathValidator.

bool
isValid(string $path)

Checks if the URL path is valid and accessible by the current user.

Url|false
getUrlIfValid(string $path)

Returns a URL object, if the path is valid and accessible.

Url|false
getUrlIfValidWithoutAccessCheck(string $path)

Returns a URL object, if the path is valid.

getUrl($path, $access_check)

Helper for getUrlIfValid() and getUrlIfValidWithoutAccessCheck().

array|bool
getPathAttributes(string $path, Request $request, bool $access_check)

Gets the matched attributes for a given path.

Details

__construct(AccessAwareRouterInterface $access_aware_router, UrlMatcherInterface $access_unaware_router, AccountInterface $account, InboundPathProcessorInterface $path_processor)

Creates a new PathValidator.

Parameters

AccessAwareRouterInterface $access_aware_router

The access aware router.

UrlMatcherInterface $access_unaware_router

A router implementation which does not check access.

AccountInterface $account

The current user.

InboundPathProcessorInterface $path_processor

The path processor;

bool isValid(string $path)

Checks if the URL path is valid and accessible by the current user.

Parameters

string $path

The path to check.

Return Value

bool

TRUE if the path is valid.

Url|false getUrlIfValid(string $path)

Returns a URL object, if the path is valid and accessible.

Parameters

string $path

The path to check.

Return Value

Url|false

The url object, or FALSE if the path is not valid.

Url|false getUrlIfValidWithoutAccessCheck(string $path)

Returns a URL object, if the path is valid.

Unlike getUrlIfValid(), access check is not performed. Do not use this method if the $path is about to be presented to a user.

Parameters

string $path

The path to check.

Return Value

Url|false

The url object, or FALSE if the path is not valid.

protected getUrl($path, $access_check)

Helper for getUrlIfValid() and getUrlIfValidWithoutAccessCheck().

Parameters

$path
$access_check

protected array|bool getPathAttributes(string $path, Request $request, bool $access_check)

Gets the matched attributes for a given path.

Parameters

string $path

The path to check.

Request $request

A request object with the given path.

bool $access_check

If FALSE then skip access check and check only whether the path is valid.

Return Value

array|bool

An array of request attributes of FALSE if an exception was thrown.