class Session

Provides access to session sections as well as session settings and management methods.

Traits

Strict class for better experience.

Constants

DEFAULT_FILE_LIFETIME

Default file lifetime

SECURITY_OPTIONS

Methods

__construct(IRequest $request, IResponse $response)

No description

void
start()

Starts and initializes session data.

bool
isStarted()

Has been session started?

void
close()

Ends the current session and store session data.

void
destroy()

Destroys all data registered to a session.

bool
exists()

Does session exists for the current request?

void
regenerateId()

Regenerates the session ID.

string
getId()

Returns the current session ID. Don't make dependencies, can be changed for each request.

setName(string $name)

Sets the session name to a specified one.

string
getName()

Gets the session name.

getSection(string $section, string $class = SessionSection::class)

Returns specified session section.

bool
hasSection(string $section)

Checks if a session section exist and is not empty.

getIterator()

Iteration over all sections.

void
clean()

Cleans and minimizes meta structures. This method is called automatically on shutdown, do not call it directly.

setOptions(array $options)

Sets session options.

array
getOptions()

Returns all session options.

setExpiration(string|null $time)

Sets the amount of time (like '20 minutes') allowed between requests before the session will be terminated, null means "until the browser is closed".

setCookieParameters(string $path, string $domain = null, bool $secure = null, string $samesite = null)

Sets the session cookie parameters.

array
getCookieParameters() deprecated

No description

setSavePath(string $path)

Sets path of the directory used to save session data.

setHandler(SessionHandlerInterface $handler)

Sets user session handler.

Details

at line 57
__construct(IRequest $request, IResponse $response)

Parameters

IRequest $request
IResponse $response

at line 71
void start()

Starts and initializes session data.

Return Value

void

Exceptions

InvalidStateException

at line 152
bool isStarted()

Has been session started?

Return Value

bool

at line 161
void close()

Ends the current session and store session data.

Return Value

void

at line 174
void destroy()

Destroys all data registered to a session.

Return Value

void

at line 193
bool exists()

Does session exists for the current request?

Return Value

bool

at line 203
void regenerateId()

Regenerates the session ID.

Return Value

void

Exceptions

InvalidStateException

at line 223
string getId()

Returns the current session ID. Don't make dependencies, can be changed for each request.

Return Value

string

at line 233
Session setName(string $name)

Sets the session name to a specified one.

Parameters

string $name

Return Value

Session

at line 249
string getName()

Gets the session name.

Return Value

string

at line 262
SessionSection getSection(string $section, string $class = SessionSection::class)

Returns specified session section.

Parameters

string $section
string $class

Return Value

SessionSection

Exceptions

InvalidArgumentException

at line 271
bool hasSection(string $section)

Checks if a session section exist and is not empty.

Parameters

string $section

Return Value

bool

at line 284
Iterator getIterator()

Iteration over all sections.

Return Value

Iterator

at line 298
void clean()

Cleans and minimizes meta structures. This method is called automatically on shutdown, do not call it directly.

Return Value

void

at line 322
Session setOptions(array $options)

Sets session options.

Parameters

array $options

Return Value

Session

Exceptions

NotSupportedException
InvalidStateException

at line 346
array getOptions()

Returns all session options.

Return Value

array

at line 420
Session setExpiration(string|null $time)

Sets the amount of time (like '20 minutes') allowed between requests before the session will be terminated, null means "until the browser is closed".

Parameters

string|null $time

Return Value

Session

at line 442
Session setCookieParameters(string $path, string $domain = null, bool $secure = null, string $samesite = null)

Sets the session cookie parameters.

Parameters

string $path
string $domain
bool $secure
string $samesite

Return Value

Session

at line 456
array getCookieParameters() deprecated

deprecated

Return Value

array

at line 466
Session setSavePath(string $path)

Sets path of the directory used to save session data.

Parameters

string $path

Return Value

Session

at line 478
Session setHandler(SessionHandlerInterface $handler)

Sets user session handler.

Parameters

SessionHandlerInterface $handler

Return Value

Session