DatabaseSessionHandler
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
Get the number of seconds until the given DateTime.
Get the "available at" UNIX timestamp.
If the given value is an interval, convert it to a DateTime instance.
Given a start time, format the total run time for human readability.
Validate an authentication provider supplied to the handler.
Validate and deduplicate session identifiers supplied to the handler.
Create a new database session handler instance.
No description
No description
Create a new session ID.
Determine if the session ID exists.
No description
Determine if the session is expired.
No description
Perform an insert operation on the session ID.
Perform an update operation on the session ID.
Get the default payload for the session.
Add the request information to the session payload.
Get the IP address for the current request.
Get the user agent for the current request.
No description
No description
Determine if the handler supports user session management.
Get the active sessions for the given user.
Destroy an active session belonging to the given user.
Destroy the active sessions belonging to the given user.
Get the exclusive lower boundary for active sessions.
Get the underlying database connection.
Set the existence state for the session.
Get the existence state for the session.
Get the raw existence state for the current session record.
Set whether the current session record is expired.
Determine if the current session record is expired.
Forget the current session record state.
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.
in
InteractsWithTime at line 29
protected int
availableAt(DateInterval|DateTimeInterface|int|null $delay = 0)
Get the "available at" UNIX timestamp.
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.
in
InteractsWithTime at line 63
protected int
currentTime()
Get the current system time as a UNIX timestamp.
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.
in
ValidatesUserSessionArguments at line 15
protected void
validateAuthProvider(string $authProvider)
Validate an authentication provider supplied to the handler.
in
ValidatesUserSessionArguments at line 28
protected array
normalizeSessionIds(array $sessionIds)
Validate and deduplicate session identifiers supplied to the handler.
at line 52
__construct(ConnectionResolverInterface $resolver, string|null $connection, string $table, int $minutes, Container|null $container = null)
Create a new database session handler instance.
at line 62
bool
open(string $savePath, string $sessionName)
No description
at line 67
bool
close()
No description
at line 75
string
create_sid()
Create a new session ID.
at line 83
bool
validateId(string $id)
Determine if the session ID exists.
at line 88
false|string
read(string $sessionId)
No description
at line 114
protected bool
expired(object $session)
Determine if the session is expired.
at line 120
bool
write(string $sessionId, string $data)
No description
at line 148
protected bool
performInsert(string $sessionId, array $payload)
Perform an insert operation on the session ID.
at line 167
protected int
performUpdate(string $sessionId, array $payload)
Perform an update operation on the session ID.
at line 175
protected array
getDefaultPayload(string $sessionId, string $data)
Get the default payload for the session.
at line 206
protected DatabaseSessionHandler
addRequestInformation(array $payload)
Add the request information to the session payload.
at line 221
protected string|null
ipAddress()
Get the IP address for the current request.
at line 229
protected string
userAgent()
Get the user agent for the current request.
at line 234
bool
destroy(string $sessionId)
No description
at line 241
int
gc(int $lifetime)
No description
at line 249
bool
supportsUserSessionManagement()
Determine if the handler supports user session management.
at line 259
Collection
userSessions(string $authProvider, int|string $userId)
Get the active sessions for the given user.
at line 289
bool
destroyUserSession(string $authProvider, int|string $userId, string $sessionId)
Destroy an active session belonging to the given user.
at line 311
int
destroyUserSessions(string $authProvider, int|string $userId, array $except = [])
Destroy the active sessions belonging to the given user.
at line 334
protected int
activeAfter()
Get the exclusive lower boundary for active sessions.
at line 342
protected Builder
getQuery()
Get a fresh query builder instance for the table.
at line 350
ConnectionInterface
connection()
Get the underlying database connection.
at line 364
DatabaseSessionHandler
setContainer(Container $container)
Set the application instance used by the handler.
Mutating the container on a shared handler during request handling can expose the wrong request or authentication state to concurrent coroutines.
at line 377
SessionHandlerInterface
setExists(bool $value)
Set the existence state for the session.
at line 391
bool
getExists()
Get the existence state for the session.
at line 399
protected bool|null
existenceState()
Get the raw existence state for the current session record.
at line 409
protected DatabaseSessionHandler
setExpired(bool $value)
Set whether the current session record is expired.
at line 419
protected bool
getExpired()
Determine if the current session record is expired.
at line 427
protected void
forgetRecordState()
Forget the current session record state.
at line 441
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.