Documentation

CanUseSession

Table of Contents

$dbTable  : string
$shouldRefresh  : bool
$token  : string|null
__construct()  : mixed
byToken()  : Session|APIKey|null
A session by its token, whichever kind the token opens
byUser()  : array<string|int, static>
All active sessions of a user, of the kind the called class stands for
canExpire()  : bool
Whether the session is subject to expiring at all
created()  : string|null
device()  : string|null
The user agent the session was started from, or null when none was sent
expiresAt()  : string|null
The point in time the session becomes unusable, or null when it cannot expire
extend()  : void
extendedSeconds()  : int|null
invalidate()  : void
ipCreation()  : string|null
The address the session was created from, or null when it was not known
ipLast()  : string|null
The address the session was last used from, or null while it is unused
isExpired()  : bool
lastTwoFactor()  : string|null
When this session last passed a two factor check, or null while it never did
lastUsed()  : string|null
When the session was last used, or null while it is unused
loadObject()  : mixed
name()  : string|null
reason()  : string|null
Why the session was created, e.g. an impersonation, or null
recordTwoFactor()  : void
Stamps a freshly passed two factor check on the session
remainingTwoFactorTries()  : int
How many wrong two factor codes this session may still send. At zero it is signed out rather than asked again.
requireRenew()  : bool
Whether this session has to pass two factor again before it is let near a guarded action.
resetTwoFactorTries()  : void
Hands the session its full budget of two factor tries back
setCanExpire()  : void
Subjects the session to expiring, or exempts it from it. A session that cannot expire is not invalidated on use, so an already expired one becomes usable again by turning this off.
setExpiresAt()  : void
Fixes the point in time the session expires, or hands it back to the computed lifetime when null is passed. A fixed expiry replaces that lifetime, so extending the session no longer moves it.
setExtensionTime()  : void
setName()  : void
Names the session, or removes its name when null is passed
spendTwoFactorTry()  : int
Spends one of the tries on a wrong code and answers how many are left
storedToken()  : string
token()  : string|null
userId()  : int|null
userIdExec()  : int|null
refreshOnNextUse()  : void

Properties

Methods

__construct()

public __construct(array<string|int, mixed> $data[, string|null $token = null ]) : mixed
Parameters
$data : array<string|int, mixed>
$token : string|null = null
Return values
mixed —

byToken()

A session by its token, whichever kind the token opens

public static byToken(string $token) : Session|APIKey|null

A token does not say what it opens, so the row picks the class. This is the entry point of the authentication, which has to resolve both kinds - an api key must not be measured against the login timeout.

Parameters
$token : string
Return values
Session|APIKey|null —

byUser()

All active sessions of a user, of the kind the called class stands for

public static byUser(User $user) : array<string|int, static>
Parameters
$user : User

The user whose sessions are returned

Return values
array<string|int, static> —

canExpire()

Whether the session is subject to expiring at all

public canExpire() : bool
Return values
bool —

created()

public created() : string|null
Return values
string|null —

device()

The user agent the session was started from, or null when none was sent

public device() : string|null
Return values
string|null —

expiresAt()

The point in time the session becomes unusable, or null when it cannot expire

public expiresAt([bool $refresh = true ]) : string|null

A fixed expiry wins over the computed lifetime, so neither the configured timeout nor an extension has a say once one is set. A session that cannot expire outranks both - it never becomes unusable at all.

Parameters
$refresh : bool = true
Return values
string|null —

extend()

public extend(int $seconds) : void
Parameters
$seconds : int
Return values
void —

extendedSeconds()

public extendedSeconds() : int|null
Return values
int|null —

invalidate()

public invalidate() : void
Return values
void —

ipCreation()

The address the session was created from, or null when it was not known

public ipCreation() : string|null
Return values
string|null —

ipLast()

The address the session was last used from, or null while it is unused

public ipLast() : string|null
Return values
string|null —

isExpired()

public isExpired() : bool
Return values
bool —

lastTwoFactor()

When this session last passed a two factor check, or null while it never did

public lastTwoFactor() : string|null
Return values
string|null —

lastUsed()

When the session was last used, or null while it is unused

public lastUsed() : string|null
Return values
string|null —

loadObject()

public loadObject(array<string|int, mixed> $data) : mixed
Parameters
$data : array<string|int, mixed>
Return values
mixed —

name()

public name() : string|null
Return values
string|null —

reason()

Why the session was created, e.g. an impersonation, or null

public reason() : string|null
Return values
string|null —

recordTwoFactor()

Stamps a freshly passed two factor check on the session

public recordTwoFactor() : void
Return values
void —

remainingTwoFactorTries()

How many wrong two factor codes this session may still send. At zero it is signed out rather than asked again.

public remainingTwoFactorTries() : int
Return values
int —

requireRenew()

Whether this session has to pass two factor again before it is let near a guarded action.

public requireRenew([int|null $freshnessSeconds = null ]) : bool

False for an account that carries no two factor - there is nothing to renew and the visitor could never satisfy it. Otherwise true while the session never passed a check, or once the last one aged past two_factor_freshness_seconds. An api key starts without a stamp, so it stays stale for an account with two factor until it passes a renewal.

Parameters
$freshnessSeconds : int|null = null
Return values
bool —

resetTwoFactorTries()

Hands the session its full budget of two factor tries back

public resetTwoFactorTries() : void
Return values
void —

setCanExpire()

Subjects the session to expiring, or exempts it from it. A session that cannot expire is not invalidated on use, so an already expired one becomes usable again by turning this off.

public setCanExpire(bool $canExpire) : void

The column stores the exemption, so it is inverted here once.

Parameters
$canExpire : bool
Return values
void —

setExpiresAt()

Fixes the point in time the session expires, or hands it back to the computed lifetime when null is passed. A fixed expiry replaces that lifetime, so extending the session no longer moves it.

public setExpiresAt(DateTime|null $expiresAt) : void
Parameters
$expiresAt : DateTime|null
Return values
void —

setExtensionTime()

public setExtensionTime(int $seconds) : void
Parameters
$seconds : int
Return values
void —

setName()

Names the session, or removes its name when null is passed

public setName(string|null $name) : void
Parameters
$name : string|null
Return values
void —

spendTwoFactorTry()

Spends one of the tries on a wrong code and answers how many are left

public spendTwoFactorTry() : int
Return values
int —

storedToken()

public storedToken() : string
Return values
string —

token()

public token() : string|null
Return values
string|null —

userId()

public userId() : int|null
Return values
int|null —

userIdExec()

public userIdExec() : int|null
Return values
int|null —

refreshOnNextUse()

protected refreshOnNextUse() : void
Return values
void —

Search results