class DatabaseSessionHandler implements 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.

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.

__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

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|null
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 $data)

Get the default payload for the session.

addUserInformation(array $payload)

Add the user information to the session payload.

mixed
userId()

Get the currently authenticated user's ID.

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

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.

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 41
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 57
protected int currentTime()

Get the current system time as a UNIX timestamp.

Return Value

int

in InteractsWithTime at line 65
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

at line 40
__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 50
bool open(string $savePath, string $sessionName)

No description

Parameters

string $savePath
string $sessionName

Return Value

bool

at line 55
bool close()

No description

Return Value

bool

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

No description

Parameters

string $sessionId

Return Value

false|string

at line 82
protected bool expired(object $session)

Determine if the session is expired.

Parameters

object $session

Return Value

bool

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

No description

Parameters

string $sessionId
string $data

Return Value

bool

at line 115
protected bool|null performInsert(string $sessionId, array $payload)

Perform an insert operation on the session ID.

Parameters

string $sessionId
array $payload

Return Value

bool|null

at line 131
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 139
protected array getDefaultPayload(string $data)

Get the default payload for the session.

Parameters

string $data

Return Value

array

at line 159
protected DatabaseSessionHandler addUserInformation(array $payload)

Add the user information to the session payload.

Parameters

array $payload

Return Value

DatabaseSessionHandler

at line 171
protected mixed userId()

Get the currently authenticated user's ID.

Return Value

mixed

at line 179
protected DatabaseSessionHandler addRequestInformation(array $payload)

Add the request information to the session payload.

Parameters

array $payload

Return Value

DatabaseSessionHandler

at line 194
protected string|null ipAddress()

Get the IP address for the current request.

Return Value

string|null

at line 202
protected string userAgent()

Get the user agent for the current request.

Return Value

string

at line 207
bool destroy(string $sessionId)

No description

Parameters

string $sessionId

Return Value

bool

at line 214
int gc(int $lifetime)

No description

Parameters

int $lifetime

Return Value

int

at line 222
protected Builder getQuery()

Get a fresh query builder instance for the table.

Return Value

Builder

at line 230
ConnectionInterface connection()

Get the underlying database connection.

Return Value

ConnectionInterface

at line 242
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 252
SessionHandlerInterface setExists(bool $value)

Set the existence state for the session.

Parameters

bool $value

Return Value

SessionHandlerInterface

at line 262
bool getExists()

Get the existence state for the session.

Return Value

bool

at line 273
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