\Symfony\Component\HttpFoundation\SessionSessionInterface

Interface for the session.

Summary

Methods
Constants
start()
getId()
setId()
getName()
setName()
invalidate()
migrate()
save()
has()
get()
set()
all()
replace()
remove()
clear()
isStarted()
registerBag()
getBag()
getMetadataBag()
No constants found
No protected methods found
N/A
No private methods found
N/A

Methods

start()

start() : boolean

Starts the session storage.

Throws

\RuntimeException

if session fails to start

Returns

boolean —

True if session started

getId()

getId() : string

Returns the session ID.

Returns

string —

The session ID

setId()

setId(string  $id) 

Sets the session ID.

Parameters

string $id

getName()

getName() : mixed

Returns the session name.

Returns

mixed —

The session name

setName()

setName(string  $name) 

Sets the session name.

Parameters

string $name

invalidate()

invalidate(integer  $lifetime = null) : boolean

Invalidates the current session.

Clears all session attributes and flashes and regenerates the session and deletes the old session from persistence.

Parameters

integer $lifetime

Sets the cookie lifetime for the session cookie. A null value will leave the system settings unchanged, 0 sets the cookie to expire with browser session. Time is in seconds, and is not a Unix timestamp.

Returns

boolean —

True if session invalidated, false if error

migrate()

migrate(boolean  $destroy = false, integer  $lifetime = null) : boolean

Migrates the current session to a new session id while maintaining all session attributes.

Parameters

boolean $destroy

Whether to delete the old session or leave it to garbage collection

integer $lifetime

Sets the cookie lifetime for the session cookie. A null value will leave the system settings unchanged, 0 sets the cookie to expire with browser session. Time is in seconds, and is not a Unix timestamp.

Returns

boolean —

True if session migrated, false if error

save()

save() 

Force the session to be saved and closed.

This method is generally not required for real sessions as the session will be automatically saved at the end of code execution.

has()

has(string  $name) : boolean

Checks if an attribute is defined.

Parameters

string $name

The attribute name

Returns

boolean —

true if the attribute is defined, false otherwise

get()

get(string  $name, mixed  $default = null) : mixed

Returns an attribute.

Parameters

string $name

The attribute name

mixed $default

The default value if not found

Returns

mixed

set()

set(string  $name, mixed  $value) 

Sets an attribute.

Parameters

string $name
mixed $value

all()

all() : array

Returns attributes.

Returns

array —

Attributes

replace()

replace(array  $attributes) 

Sets attributes.

Parameters

array $attributes

Attributes

remove()

remove(string  $name) : mixed

Removes an attribute.

Parameters

string $name

Returns

mixed —

The removed value or null when it does not exist

clear()

clear() 

Clears all attributes.

isStarted()

isStarted() : boolean

Checks if the session was started.

Returns

boolean