Session
in package
implements
SessionInterface, IteratorAggregate, Countable
Tags
Table of Contents
Interfaces
- SessionInterface
- Interface for the session.
- IteratorAggregate
- Countable
Properties
- $storage : mixed
- $attributeName : string
- $data : array<string|int, mixed>
- $flashName : string
- $usageIndex : int
- $usageReporter : Closure|null
Methods
- __construct() : mixed
- all() : array<string|int, mixed>
- Returns attributes.
- clear() : mixed
- Clears all attributes.
- count() : int
- Returns the number of attributes.
- get() : mixed
- Returns an attribute.
- getBag() : SessionBagInterface
- Gets a bag instance by name.
- getFlashBag() : FlashBagInterface
- Gets the flashbag interface.
- getId() : string
- Returns the session ID.
- getIterator() : ArrayIterator<string, mixed>
- Returns an iterator for attributes.
- getMetadataBag() : MetadataBag
- Gets session meta.
- getName() : string
- Returns the session name.
- getUsageIndex() : int
- has() : bool
- Checks if an attribute is defined.
- invalidate() : bool
- Invalidates the current session.
- isStarted() : bool
- Checks if the session was started.
- migrate() : bool
- Migrates the current session to a new session id while maintaining all session attributes.
- registerBag() : mixed
- Registers a SessionBagInterface with the session.
- remove() : mixed
- Removes an attribute.
- replace() : mixed
- Sets attributes.
- save() : mixed
- Force the session to be saved and closed.
- set() : mixed
- Sets an attribute.
- setId() : mixed
- Sets the session ID.
- setName() : mixed
- Sets the session name.
- start() : bool
- Starts the session storage.
- getAttributeBag() : AttributeBagInterface
- Gets the attributebag interface.
Properties
$storage
protected
mixed
$storage
$attributeName
private
string
$attributeName
$data
private
array<string|int, mixed>
$data
= []
$flashName
private
string
$flashName
$usageIndex
private
int
$usageIndex
= 0
$usageReporter
private
Closure|null
$usageReporter
Methods
__construct()
public
__construct([SessionStorageInterface $storage = null ][, AttributeBagInterface $attributes = null ][, FlashBagInterface $flashes = null ][, callable $usageReporter = null ]) : mixed
Parameters
- $storage : SessionStorageInterface = null
- $attributes : AttributeBagInterface = null
- $flashes : FlashBagInterface = null
- $usageReporter : callable = null
all()
Returns attributes.
public
all() : array<string|int, mixed>
Return values
array<string|int, mixed>clear()
Clears all attributes.
public
clear() : mixed
count()
Returns the number of attributes.
public
count() : int
Return values
intget()
Returns an attribute.
public
get(string $name[, mixed $default = null ]) : mixed
Parameters
- $name : string
- $default : mixed = null
getBag()
Gets a bag instance by name.
public
getBag(string $name) : SessionBagInterface
Parameters
- $name : string
Return values
SessionBagInterfacegetFlashBag()
Gets the flashbag interface.
public
getFlashBag() : FlashBagInterface
Return values
FlashBagInterfacegetId()
Returns the session ID.
public
getId() : string
Return values
stringgetIterator()
Returns an iterator for attributes.
public
getIterator() : ArrayIterator<string, mixed>
Return values
ArrayIterator<string, mixed>getMetadataBag()
Gets session meta.
public
getMetadataBag() : MetadataBag
Return values
MetadataBaggetName()
Returns the session name.
public
getName() : string
Return values
stringgetUsageIndex()
public
& getUsageIndex() : int
Return values
inthas()
Checks if an attribute is defined.
public
has(string $name) : bool
Parameters
- $name : string
Return values
boolinvalidate()
Invalidates the current session.
public
invalidate([int $lifetime = null ]) : bool
Parameters
- $lifetime : int = null
-
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 values
boolisStarted()
Checks if the session was started.
public
isStarted() : bool
Return values
boolmigrate()
Migrates the current session to a new session id while maintaining all session attributes.
public
migrate([bool $destroy = false ][, int $lifetime = null ]) : bool
Parameters
- $destroy : bool = false
-
Whether to delete the old session or leave it to garbage collection
- $lifetime : int = null
-
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 values
boolregisterBag()
Registers a SessionBagInterface with the session.
public
registerBag(SessionBagInterface $bag) : mixed
Parameters
- $bag : SessionBagInterface
remove()
Removes an attribute.
public
remove(string $name) : mixed
Parameters
- $name : string
Return values
mixed —The removed value or null when it does not exist
replace()
Sets attributes.
public
replace(array<string|int, mixed> $attributes) : mixed
Parameters
- $attributes : array<string|int, mixed>
save()
Force the session to be saved and closed.
public
save() : mixed
set()
Sets an attribute.
public
set(string $name, mixed $value) : mixed
Parameters
- $name : string
- $value : mixed
setId()
Sets the session ID.
public
setId(string $id) : mixed
Parameters
- $id : string
setName()
Sets the session name.
public
setName(string $name) : mixed
Parameters
- $name : string
start()
Starts the session storage.
public
start() : bool
Return values
boolgetAttributeBag()
Gets the attributebag interface.
private
getAttributeBag() : AttributeBagInterface
Note that this method was added to help with IDE autocompletion.