Session
Session
Session controller helper for managing authentication state.
This helper provides methods for authenticating users, logging out, and committing authentication state to the response during the controller shutdown phase. It utilizes an authentication adapter, which can be configured via application configuration, to perform authentication operations.
Usage: $this->session->authenticate($identity, $password); $this->session->logout(); // Authentication state is automatically committed on shutdown.
Properties
config
The session configuration array.
private array $configauth
private Adapter $authMethods
__construct
Setup the session helper with configuration during the helper import phase.
public __construct(array $sessionConfig): voidParameters
| Parameter | Type | Description |
|---|---|---|
$sessionConfig | array |
shutdown
Commits authentication state to the response during controller shutdown.
public shutdown(Response $response): voidIf an authentication adapter is set, this method calls its commit method, passing the current response object. This ensures any authentication-related changes are persisted before the response is sent.
Parameters
| Parameter | Type | Description |
|---|---|---|
$response | Response | the response object to commit authentication state to |
authenticate
Authenticates a user using the provided identity and password.
public authenticate(string $identity, string $credential): ResultThis method uses the configured authentication adapter to verify the user's credentials. If authentication is successful, the authentication result is stored as an attribute in the current request.
Parameters
| Parameter | Type | Description |
|---|---|---|
$identity | string | the user's identity (e.g., username or email) |
$credential | string | the user's password |
logout
Logs out the current authenticated user.
public logout(): boolThis method checks if an authentication adapter is set. If so, it attempts to call the logout method on the adapter. If the adapter does not support logout, no action is taken.
prepare
Prepares the authentication adapter instance.
private prepare(): voidThis method checks if the authentication adapter is already set. If not, it attempts to instantiate the adapter using the configuration provided. Throws an exception if no adapter is configured.
Generated by Hazaar API Doc Generator on Sun, 01 Mar 2026 09:22:26 +0000