class DatabaseSessionHandler implements ExistenceAwareInterface, SessionHandlerInterface (View source)

Traits

Properties

protected ConnectionInterface $connection

The database connection instance.

protected string $table

The name of the session table.

protected int $minutes

The number of minutes the session should be valid.

protected Container $container

The container instance.

protected bool $exists

The existence state of the session.

Methods

int
secondsUntil(DateTimeInterface|DateInterval|int $delay)

Get the number of seconds until the given DateTime.

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

Get the "available at" UNIX timestamp.

parseDateInterval(DateTimeInterface|DateInterval|int $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.

void
__construct(ConnectionInterface $connection, string $table, int $minutes, Container $container = null)

Create a new database session handler instance.

bool
open($savePath, $sessionName)

{@inheritdoc}

bool
close()

{@inheritdoc}

string|false
read($sessionId)

{@inheritdoc}

bool
expired(stdClass $session)

Determine if the session is expired.

bool
write($sessionId, $data)

{@inheritdoc}

bool|null
performInsert(string $sessionId, array<string,mixed> $payload)

Perform an insert operation on the session ID.

int
performUpdate(string $sessionId, array<string,mixed> $payload)

Perform an update operation on the session ID.

array
getDefaultPayload(string $data)

Get the default payload for the session.

$this
addUserInformation(array $payload)

Add the user information to the session payload.

mixed
userId()

Get the currently authenticated user's ID.

$this
addRequestInformation(array $payload)

Add the request information to the session payload.

string
ipAddress()

Get the IP address for the current request.

string
userAgent()

Get the user agent for the current request.

bool
destroy($sessionId)

{@inheritdoc}

int|false
gc($lifetime)

{@inheritdoc}

getQuery()

Get a fresh query builder instance for the table.

$this
setContainer(Application $container)

Set the application instance used by the handler.

setExists(bool $value)

Set the existence state for the session.

Details

protected int secondsUntil(DateTimeInterface|DateInterval|int $delay)

Get the number of seconds until the given DateTime.

Parameters

DateTimeInterface|DateInterval|int $delay

Return Value

int

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

Get the "available at" UNIX timestamp.

Parameters

DateTimeInterface|DateInterval|int $delay

Return Value

int

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

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

Parameters

DateTimeInterface|DateInterval|int $delay

Return Value

DateTimeInterface|int

protected int currentTime()

Get the current system time as a UNIX timestamp.

Return Value

int

void __construct(ConnectionInterface $connection, string $table, int $minutes, Container $container = null)

Create a new database session handler instance.

Parameters

ConnectionInterface $connection
string $table
int $minutes
Container $container

Return Value

void

bool open($savePath, $sessionName)

{@inheritdoc}

Parameters

$savePath
$sessionName

Return Value

bool

bool close()

{@inheritdoc}

Return Value

bool

string|false read($sessionId)

{@inheritdoc}

Parameters

$sessionId

Return Value

string|false

protected bool expired(stdClass $session)

Determine if the session is expired.

Parameters

stdClass $session

Return Value

bool

bool write($sessionId, $data)

{@inheritdoc}

Parameters

$sessionId
$data

Return Value

bool

protected bool|null performInsert(string $sessionId, array<string,mixed> $payload)

Perform an insert operation on the session ID.

Parameters

string $sessionId
array<string,mixed> $payload

Return Value

bool|null

protected int performUpdate(string $sessionId, array<string,mixed> $payload)

Perform an update operation on the session ID.

Parameters

string $sessionId
array<string,mixed> $payload

Return Value

int

protected array getDefaultPayload(string $data)

Get the default payload for the session.

Parameters

string $data

Return Value

array

protected $this addUserInformation(array $payload)

Add the user information to the session payload.

Parameters

array $payload

Return Value

$this

protected mixed userId()

Get the currently authenticated user's ID.

Return Value

mixed

protected $this addRequestInformation(array $payload)

Add the request information to the session payload.

Parameters

array $payload

Return Value

$this

protected string ipAddress()

Get the IP address for the current request.

Return Value

string

protected string userAgent()

Get the user agent for the current request.

Return Value

string

bool destroy($sessionId)

{@inheritdoc}

Parameters

$sessionId

Return Value

bool

int|false gc($lifetime)

{@inheritdoc}

Parameters

$lifetime

Return Value

int|false

protected Builder getQuery()

Get a fresh query builder instance for the table.

Return Value

Builder

$this setContainer(Application $container)

Set the application instance used by the handler.

Parameters

Application $container

Return Value

$this

SessionHandlerInterface setExists(bool $value)

Set the existence state for the session.

Parameters

bool $value

Return Value

SessionHandlerInterface