class Session implements SessionInterface, IteratorAggregate, Countable
protected | $storage |
__construct(SessionStorageInterface $storage = null, AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null) | ||
bool | start() Starts the session storage. | |
bool | 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. | ||
bool | isStarted() Checks if the session was started. | |
ArrayIterator | getIterator() Returns an iterator for attributes. | |
int | count() Returns the number of attributes. | |
int | getUsageIndex() | |
bool | isEmpty() | |
bool | invalidate(int $lifetime = null) Invalidates the current session. | |
bool | migrate(bool $destroy = false, int $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. | ||
MetadataBag | getMetadataBag() Gets session meta. | |
registerBag(SessionBagInterface $bag) Registers a SessionBagInterface with the session. | ||
SessionBagInterface | getBag(string $name) Gets a bag instance by name. | |
FlashBagInterface | getFlashBag() Gets the flashbag interface. |
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) |
Starts the session storage.
bool | True if session started |
RuntimeException | if session fails to start |
Checks if an attribute is defined.
string | $name | The attribute name |
bool | true if the attribute is defined, false otherwise |
Returns an attribute.
string | $name | The attribute name |
mixed | $default | The default value if not found |
mixed |
Sets an attribute.
string | $name | |
mixed | $value |
Returns attributes.
array | Attributes |
Sets attributes.
array | $attributes | Attributes |
Removes an attribute.
string | $name |
mixed | The removed value or null when it does not exist |
Clears all attributes.
Checks if the session was started.
bool |
Returns an iterator for attributes.
ArrayIterator | An \ArrayIterator instance |
Returns the number of attributes.
int | The number of attributes |
int |
bool |
Invalidates the current session.
Clears all session attributes and flashes and regenerates the session and deletes the old session from persistence.
int | $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. |
bool | True if session invalidated, false if error |
Migrates the current session to a new session id while maintaining all session attributes.
bool | $destroy | Whether to delete the old session or leave it to garbage collection |
int | $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. |
bool | True if session migrated, false if error |
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.
Returns the session ID.
string | The session ID |
Sets the session ID.
string | $id |
Returns the session name.
mixed | The session name |
Sets the session name.
string | $name |
Gets session meta.
MetadataBag |
Registers a SessionBagInterface with the session.
SessionBagInterface | $bag |
Gets a bag instance by name.
string | $name |
SessionBagInterface |
Gets the flashbag interface.
FlashBagInterface |
© 2004–2017 Fabien Potencier
Licensed under the MIT License.
https://api.symfony.com/4.1/Symfony/Component/HttpFoundation/Session/Session.html