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 51
__construct(ConnectionResolverInterface $resolver, string|null $connection, string $table, int $minutes, Container|null $container = null)
Create a new database session handler instance.
at line 61
bool
open(string $savePath, string $sessionName)
No description
at line 66
bool
close()
No description
at line 74
string
create_sid()
Create a new session ID.
at line 82
bool
validateId(string $id)
Determine if the session ID exists.
at line 87
false|string
read(string $sessionId)
No description
at line 113
protected bool
expired(object $session)
Determine if the session is expired.
at line 119
bool
write(string $sessionId, string $data)
No description
at line 147
protected bool
performInsert(string $sessionId, array $payload)
Perform an insert operation on the session ID.
at line 166
protected int
performUpdate(string $sessionId, array $payload)
Perform an update operation on the session ID.
at line 174
protected array
getDefaultPayload(string $sessionId, string $data)
Get the default payload for the session.
at line 203
protected DatabaseSessionHandler
addRequestInformation(array $payload)
Add the request information to the session payload.
at line 218
protected string|null
ipAddress()
Get the IP address for the current request.
at line 226
protected string
userAgent()
Get the user agent for the current request.
at line 231
bool
destroy(string $sessionId)
No description
at line 238
int
gc(int $lifetime)
No description
at line 246
bool
supportsUserSessionManagement()
Determine if the handler supports user session management.
at line 256
Collection
userSessions(string $authProvider, int|string $userId)
Get the active sessions for the given user.
at line 286
bool
destroyUserSession(string $authProvider, int|string $userId, string $sessionId)
Destroy an active session belonging to the given user.
at line 308
int
destroyUserSessions(string $authProvider, int|string $userId, array $except = [])
Destroy the active sessions belonging to the given user.
at line 331
protected int
activeAfter()
Get the exclusive lower boundary for active sessions.
at line 339
protected Builder
getQuery()
Get a fresh query builder instance for the table.
at line 347
ConnectionInterface
connection()
Get the underlying database connection.
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.
at line 369
SessionHandlerInterface
setExists(bool $value)
Set the existence state for the session.
at line 383
bool
getExists()
Get the existence state for the session.
at line 391
protected bool|null
existenceState()
Get the raw existence state for the current session record.
at line 399
protected DatabaseSessionHandler
setExpired(bool $value)
Set whether the current session record is expired.
at line 409
protected bool
getExpired()
Determine if the current session record is expired.
at line 417
protected void
forgetRecordState()
Forget the current session record state.
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.