class DatabaseSessionHandler implements CanManageUserSessions, ExistenceAwareInterface, SessionHandlerInterface

Traits

Constants

protected DATABASE_EXISTS_CONTEXT_KEY_PREFIX

Context key prefix for whether the session record exists in the database.

Suffixed with the handler's object ID so multiple handler instances within the same coroutine maintain independent existence state.

protected DATABASE_EXPIRED_CONTEXT_KEY_PREFIX

Context key prefix for whether the session record is expired.

Suffixed with the handler's object ID so multiple handler instances within the same coroutine maintain independent expiration state.

Methods

int
secondsUntil(DateInterval|DateTimeInterface|int $delay)

Get the number of seconds until the given DateTime.

int
availableAt(DateInterval|DateTimeInterface|int|null $delay = 0)

Get the "available at" UNIX timestamp.

parseDateInterval(DateInterval|DateTimeInterface|int|null $delay)

If the given value is an interval, convert it to a DateTime instance.

int
currentTime()

Get the current system time as a UNIX timestamp.

string
runTimeForHumans(float $startTime, float|null $endTime = null)

Given a start time, format the total run time for human readability.

void
validateAuthProvider(string $authProvider)

Validate an authentication provider supplied to the handler.

array
normalizeSessionIds(array $sessionIds)

Validate and deduplicate session identifiers supplied to the handler.

__construct(ConnectionResolverInterface $resolver, string|null $connection, string $table, int $minutes, Container|null $container = null)

Create a new database session handler instance.

bool
open(string $savePath, string $sessionName)

No description

bool
close()

No description

string
create_sid()

Create a new session ID.

bool
validateId(string $id)

Determine if the session ID exists.

false|string
read(string $sessionId)

No description

bool
expired(object $session)

Determine if the session is expired.

bool
write(string $sessionId, string $data)

No description

bool
performInsert(string $sessionId, array $payload)

Perform an insert operation on the session ID.

int
performUpdate(string $sessionId, array $payload)

Perform an update operation on the session ID.

array
getDefaultPayload(string $sessionId, string $data)

Get the default payload for the session.

addRequestInformation(array $payload)

Add the request information to the session payload.

string|null
ipAddress()

Get the IP address for the current request.

string
userAgent()

Get the user agent for the current request.

bool
destroy(string $sessionId)

No description

int
gc(int $lifetime)

No description

bool
supportsUserSessionManagement()

Determine if the handler supports user session management.

userSessions(string $authProvider, int|string $userId)

Get the active sessions for the given user.

bool
destroyUserSession(string $authProvider, int|string $userId, string $sessionId)

Destroy an active session belonging to the given user.

int
destroyUserSessions(string $authProvider, int|string $userId, array $except = [])

Destroy the active sessions belonging to the given user.

int
activeAfter()

Get the exclusive lower boundary for active sessions.

getQuery()

Get a fresh query builder instance for the table.

connection()

Get the underlying database connection.

setContainer(Container $container)

Set the application instance used by the handler.

setExists(bool $value)

Set the existence state for the session.

bool
getExists()

Get the existence state for the session.

bool|null
existenceState()

Get the raw existence state for the current session record.

setExpired(bool $value)

Set whether the current session record is expired.

bool
getExpired()

Determine if the current session record is expired.

void
forgetRecordState()

Forget the current session record state.

void
__clone()

Reset this handler's existence state when it is cloned.

Details

in InteractsWithTime at line 17
protected int secondsUntil(DateInterval|DateTimeInterface|int $delay)

Get the number of seconds until the given DateTime.

Parameters

DateInterval|DateTimeInterface|int $delay

Return Value

int

in InteractsWithTime at line 29
protected int availableAt(DateInterval|DateTimeInterface|int|null $delay = 0)

Get the "available at" UNIX timestamp.

Parameters

DateInterval|DateTimeInterface|int|null $delay

Return Value

int

in InteractsWithTime at line 47
protected DateTimeInterface|int parseDateInterval(DateInterval|DateTimeInterface|int|null $delay)

If the given value is an interval, convert it to a DateTime instance.

Parameters

DateInterval|DateTimeInterface|int|null $delay

Return Value

DateTimeInterface|int

in InteractsWithTime at line 63
protected int currentTime()

Get the current system time as a UNIX timestamp.

Return Value

int

in InteractsWithTime at line 71
protected string runTimeForHumans(float $startTime, float|null $endTime = null)

Given a start time, format the total run time for human readability.

Parameters

float $startTime
float|null $endTime

Return Value

string

protected void validateAuthProvider(string $authProvider)

Validate an authentication provider supplied to the handler.

Parameters

string $authProvider

Return Value

void

protected array normalizeSessionIds(array $sessionIds)

Validate and deduplicate session identifiers supplied to the handler.

Parameters

array $sessionIds

Return Value

array

at line 51
__construct(ConnectionResolverInterface $resolver, string|null $connection, string $table, int $minutes, Container|null $container = null)

Create a new database session handler instance.

Parameters

ConnectionResolverInterface $resolver

the database connection resolver instance

string|null $connection

the database connection that should be used

string $table

the name of the session table

int $minutes

the number of minutes the session should be valid

Container|null $container

at line 61
bool open(string $savePath, string $sessionName)

No description

Parameters

string $savePath
string $sessionName

Return Value

bool

at line 66
bool close()

No description

Return Value

bool

at line 74
string create_sid()

Create a new session ID.

Return Value

string

at line 82
bool validateId(string $id)

Determine if the session ID exists.

Parameters

string $id

Return Value

bool

at line 87
false|string read(string $sessionId)

No description

Parameters

string $sessionId

Return Value

false|string

at line 113
protected bool expired(object $session)

Determine if the session is expired.

Parameters

object $session

Return Value

bool

at line 119
bool write(string $sessionId, string $data)

No description

Parameters

string $sessionId
string $data

Return Value

bool

at line 147
protected bool performInsert(string $sessionId, array $payload)

Perform an insert operation on the session ID.

Parameters

string $sessionId
array $payload

Return Value

bool

at line 166
protected int performUpdate(string $sessionId, array $payload)

Perform an update operation on the session ID.

Parameters

string $sessionId
array $payload

Return Value

int

at line 174
protected array getDefaultPayload(string $sessionId, string $data)

Get the default payload for the session.

Parameters

string $sessionId
string $data

Return Value

array

at line 203
protected DatabaseSessionHandler addRequestInformation(array $payload)

Add the request information to the session payload.

Parameters

array $payload

Return Value

DatabaseSessionHandler

at line 218
protected string|null ipAddress()

Get the IP address for the current request.

Return Value

string|null

at line 226
protected string userAgent()

Get the user agent for the current request.

Return Value

string

at line 231
bool destroy(string $sessionId)

No description

Parameters

string $sessionId

Return Value

bool

at line 238
int gc(int $lifetime)

No description

Parameters

int $lifetime

Return Value

int

at line 246
bool supportsUserSessionManagement()

Determine if the handler supports user session management.

Return Value

bool

at line 256
Collection userSessions(string $authProvider, int|string $userId)

Get the active sessions for the given user.

Parameters

string $authProvider
int|string $userId

Return Value

Collection

at line 286
bool destroyUserSession(string $authProvider, int|string $userId, string $sessionId)

Destroy an active session belonging to the given user.

Parameters

string $authProvider
int|string $userId
string $sessionId

Return Value

bool

at line 308
int destroyUserSessions(string $authProvider, int|string $userId, array $except = [])

Destroy the active sessions belonging to the given user.

Parameters

string $authProvider
int|string $userId
array $except

Return Value

int

at line 331
protected int activeAfter()

Get the exclusive lower boundary for active sessions.

Return Value

int

at line 339
protected Builder getQuery()

Get a fresh query builder instance for the table.

Return Value

Builder

at line 347
ConnectionInterface connection()

Get the underlying database connection.

Return Value

ConnectionInterface

at line 359
DatabaseSessionHandler setContainer(Container $container)

Set the application instance used by the handler.

Boot or tests only. Mutating the container on a shared handler during request handling can expose the wrong request or authentication state to concurrent coroutines.

Parameters

Container $container

Return Value

DatabaseSessionHandler

at line 369
SessionHandlerInterface setExists(bool $value)

Set the existence state for the session.

Parameters

bool $value

Return Value

SessionHandlerInterface

at line 383
bool getExists()

Get the existence state for the session.

Return Value

bool

at line 391
protected bool|null existenceState()

Get the raw existence state for the current session record.

Return Value

bool|null

at line 399
protected DatabaseSessionHandler setExpired(bool $value)

Set whether the current session record is expired.

Parameters

bool $value

Return Value

DatabaseSessionHandler

at line 409
protected bool getExpired()

Determine if the current session record is expired.

Return Value

bool

at line 417
protected void forgetRecordState()

Forget the current session record state.

Return Value

void

at line 431
void __clone()

Reset this handler's existence state when it is cloned.

PHP reuses freed object IDs, so a clone can land on a released handler's ID and must not inherit its existence state.

Return Value

void