trait GuardHelpers

These methods are typically the same across all guards.

In Hypervel, guards are process-global singletons (cached in AuthManager::$guards), so per-request user state cannot be stored as instance properties. Each guard must implement its own coroutine-safe user(), setUser(), and hasUser() using Context. This trait provides only the methods that are truly universal across all guards.

Properties

protected null|TProvider $provider

The user provider implementation.

Methods

authenticate()

Determine if the current user is authenticated. If not, throw an exception.

bool
check()

Determine if the current user is authenticated.

bool
guest()

Determine if the current user is a guest.

int|string|null
id()

Get the ID for the currently authenticated user.

getProvider()

Get the user provider used by the guard.

void
setProvider(UserProvider $provider)

Set the user provider used by the guard.

string
contextKey(string $key)

Get this guard's coroutine context key for the given entry.

Details

at line 55
Authenticatable authenticate()

Determine if the current user is authenticated. If not, throw an exception.

Return Value

Authenticatable

Exceptions

AuthenticationException

at line 63
bool check()

Determine if the current user is authenticated.

Return Value

bool

at line 71
bool guest()

Determine if the current user is a guest.

Return Value

bool

at line 79
int|string|null id()

Get the ID for the currently authenticated user.

Return Value

int|string|null

at line 89
UserProvider|null getProvider()

Get the user provider used by the guard.

Return Value

UserProvider|null

at line 102
void setProvider(UserProvider $provider)

Set the user provider used by the guard.

The provider is stored on the worker-lifetime guard and affects every subsequent request.

Parameters

UserProvider $provider

Return Value

void

at line 111
protected string contextKey(string $key)

Get this guard's coroutine context key for the given entry.

Parameters

string $key

Return Value

string