class Session implements SessionInterface, IteratorAggregate, Countable

Session.

Methods

__construct(SessionStorageInterface $storage = null, AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null)

Constructor.

Boolean
start()

Starts the session storage.

Boolean
has(string $name)

Checks if an attribute is defined.

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

Returns an attribute.

set(string $name, mixed $value)

Sets an attribute.

array
all()

Returns attributes.

replace(array $attributes)

Sets attributes.

mixed
remove(string $name)

Removes an attribute.

clear()

Clears all attributes.

Boolean
isStarted()

Checks if the session was started.

getIterator()

Returns an iterator for attributes.

int
count()

Returns the number of attributes.

Boolean
invalidate(integer $lifetime = null)

Invalidates the current session.

Boolean
migrate(Boolean $destroy = false, integer $lifetime = null)

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

save()

Force the session to be saved and closed.

string
getId()

Returns the session ID.

setId(string $id)

Sets the session ID

mixed
getName()

Returns the session name.

setName(string $name)

Sets the session name.

getMetadataBag()

Gets session meta.

registerBag(SessionBagInterface $bag)

Registers a SessionBagInterface with the session.

getBag(string $name)

Gets a bag instance by name.

getFlashBag()

Gets the flashbag interface.

Details

at line line 55
__construct(SessionStorageInterface $storage = null, AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null)

Constructor.

Parameters

SessionStorageInterface $storage A SessionStorageInterface instance.
AttributeBagInterface $attributes An AttributeBagInterface instance, (defaults null for default AttributeBag)
FlashBagInterface $flashes A FlashBagInterface instance (defaults null for default FlashBag)

at line line 71
Boolean start()

Starts the session storage.

Return Value

Boolean True if session started.

Exceptions

RuntimeException If session fails to start.

at line line 79
Boolean has(string $name)

Checks if an attribute is defined.

Parameters

string $name The attribute name

Return Value

Boolean true if the attribute is defined, false otherwise

at line line 87
mixed get(string $name, mixed $default = null)

Returns an attribute.

Parameters

string $name The attribute name
mixed $default The default value if not found.

Return Value

mixed

at line line 95
set(string $name, mixed $value)

Sets an attribute.

Parameters

string $name
mixed $value

at line line 103
array all()

Returns attributes.

Return Value

array Attributes

at line line 111
replace(array $attributes)

Sets attributes.

Parameters

array $attributes Attributes

at line line 119
mixed remove(string $name)

Removes an attribute.

Parameters

string $name

Return Value

mixed The removed value

at line line 127
clear()

Clears all attributes.

at line line 135
Boolean isStarted()

Checks if the session was started.

Return Value

Boolean

at line line 145
ArrayIterator getIterator()

Returns an iterator for attributes.

Return Value

ArrayIterator An \ArrayIterator instance

at line line 155
int count()

Returns the number of attributes.

Return Value

int The number of attributes

at line line 163
Boolean invalidate(integer $lifetime = null)

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.

Return Value

Boolean True if session invalidated, false if error.

at line line 173
Boolean migrate(Boolean $destroy = false, integer $lifetime = null)

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.

Return Value

Boolean True if session migrated, false if error.

at line line 181
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.

at line line 189
string getId()

Returns the session ID.

Return Value

string The session ID.

at line line 197
setId(string $id)

Sets the session ID

Parameters

string $id

at line line 205
mixed getName()

Returns the session name.

Return Value

mixed The session name.

at line line 213
setName(string $name)

Sets the session name.

Parameters

string $name

at line line 221
MetadataBag getMetadataBag()

Gets session meta.

Return Value

MetadataBag

at line line 229
registerBag(SessionBagInterface $bag)

Registers a SessionBagInterface with the session.

Parameters

SessionBagInterface $bag

at line line 237
SessionBagInterface getBag(string $name)

Gets a bag instance by name.

Parameters

string $name

Return Value

SessionBagInterface

at line line 247
FlashBagInterface getFlashBag()

Gets the flashbag interface.

Return Value

FlashBagInterface