interface Guard

Defines the contract for an authentication guard. A guard owns the notion of "who is authenticated right now" for a single request, resolving the current user from the underlying session and delegating user retrieval and credential checks to a UserProvider. Implementations are responsible for reading and writing authentication state (session, and optionally remember-me persistence) so that callers interact with a Principal rather than with storage details directly.

Methods

bool
check()

Determines whether a user is currently authenticated.

Principal|null
user()

Retrieves the currently authenticated user. Implementations typically resolve the user once per request and cache the result.

mixed
id()

Retrieves the identifier of the currently authenticated user without requiring the full user object to be used by the caller.

bool
validate(array $credentials)

Validates a set of credentials without logging the user in or modifying any authentication state.

void
login(Principal $user, bool $remember = false)

Logs the given user in, establishing authentication state for the current request and subsequent ones. When $remember is true, implementations should also persist a remember-me token.

Principal|null
loginUsingId(mixed $id)

Resolves a user by identifier and logs them in.

void
logout()

Logs the current user out, clearing authentication state for the request and removing any persisted remember-me token.

Details

at line 21
bool check()

Determines whether a user is currently authenticated.

Return Value

bool

True if a user is resolved for the current request, otherwise false.

at line 30
Principal|null user()

Retrieves the currently authenticated user. Implementations typically resolve the user once per request and cache the result.

Return Value

Principal|null

The authenticated user, or null if no user is authenticated.

at line 39
mixed id()

Retrieves the identifier of the currently authenticated user without requiring the full user object to be used by the caller.

Return Value

mixed

The authenticated user's identifier, or null if no user is authenticated.

at line 49
bool validate(array $credentials)

Validates a set of credentials without logging the user in or modifying any authentication state.

Parameters

array $credentials

The credentials to validate (e.g. ['username' => ..., 'password' => ...]).

Return Value

bool

True if the credentials are valid, otherwise false.

at line 61
void login(Principal $user, bool $remember = false)

Logs the given user in, establishing authentication state for the current request and subsequent ones. When $remember is true, implementations should also persist a remember-me token.

Parameters

Principal $user

The user to authenticate.

bool $remember

Whether to persist a remember-me token so the user remains logged in across sessions. Defaults to false.

Return Value

void

at line 70
Principal|null loginUsingId(mixed $id)

Resolves a user by identifier and logs them in.

Parameters

mixed $id

The identifier of the user to authenticate.

Return Value

Principal|null

The authenticated user, or null if no user matches the given identifier.

at line 78
void logout()

Logs the current user out, clearing authentication state for the request and removing any persisted remember-me token.

Return Value

void