Skip to content

Firewall

A named, path-matched set of authenticators plus the entry point that handles a failed authentication attempt for that path — the runtime counterpart of a security.xml <firewall> element.

final class Firewall

Since1.0.0
SourceFirewall.php

public function __construct(string $name, string $pattern, array<AuthenticatorInterface> $authenticators, EntryPointInterface $entryPoint, bool $stateless = false, bool $sessionless = false): mixed

Session axis: no session is started at all for requests under this firewall.

ParameterTypeDescription
$namestringA diagnostic name for this firewall (e.g. “api”, “main”).
$patternstringA PCRE pattern (without delimiters) matched against the request path.
$authenticatorsarray``<AuthenticatorInterface>Tried in order; the first one whose supports() matches wins.
$entryPointEntryPointInterfaceProduces the failure response when authentication is required but absent/invalid.
$statelessboolIdentity axis: re-derived from the credential every request rather than read back from the session.
$sessionlessboolSession axis: no session is started at all for requests under this firewall.

Returns mixed

MethodDescription
canonicalize(string $path): stringCollapse a request path to the form a filesystem-style resolver would reach: fully percent-decoded, backslashes treated as separators, duplicate slashes collapsed, and ./.. segments resolved.
getAuthenticators(): array<AuthenticatorInterface>
getEntryPoint(): EntryPointInterface
getName(): string
isSessionless(): boolSession axis: no session is started at all for requests under this firewall (pure machine-to-machine surfaces).
isStateless(): boolIdentity axis: re-derived from the credential every request rather than read back from the session as the source of truth.
matches(string $path): boolWhether $path falls under this firewall.

public static function canonicalize(string $path): string

Collapse a request path to the form a filesystem-style resolver would reach: fully percent-decoded, backslashes treated as separators, duplicate slashes collapsed, and ./.. segments resolved.

The raw request path.

ParameterTypeDescription
$pathstringThe raw request path.

Returns string — The normalized path, always starting with /.

public function getAuthenticators(): array<AuthenticatorInterface>

Returns array``<AuthenticatorInterface> — This firewall’s authenticator chain, in try order.

public function getEntryPoint(): EntryPointInterface

Returns EntryPointInterface — The entry point for a failed authentication attempt on this firewall.

public function getName(): string

Returns string — This firewall’s diagnostic name.

public function isSessionless(): bool

Session axis: no session is started at all for requests under this firewall (pure machine-to-machine surfaces).

Returns bool — True if this firewall is sessionless, otherwise false.

public function isStateless(): bool

Identity axis: re-derived from the credential every request rather than read back from the session as the source of truth.

Returns bool — True if this firewall is stateless, otherwise false.

public function matches(string $path): bool

Whether $path falls under this firewall.

The request path to test (e.g. $request->getUri()->getPath()).

ParameterTypeDescription
$pathstringThe request path to test (e.g. $request->getUri()->getPath()).

Returns bool — True if $path matches this firewall’s pattern, otherwise false.