Session
in package
Class Session
This class is responsible for managing session-related functionality within the application. It provides methods to handle session data and ensure proper session management.
Table of Contents
Properties
Methods
- __construct() : mixed
- Constructor for the Session class.
- __destruct() : mixed
- Destructor method for the Session class.
- ageFlashData() : void
- Ages the flash data stored in the session.
- destroy() : bool
- Destroys the current session.
- flash() : void
- Stores a flash message in the session.
- get() : mixed
- Retrieves a value from the session using the specified key. Calls the session driver's `get` method.
- has() : bool
- Checks if a specific key exists in the session. Calls the session driver's `has` method.
- id() : string
- Retrieve the current session ID. Calls the session driver's `id` method.
- remove() : mixed
- Removes a value from the session storage. Calls the session driver's `remove` method.
- set() : void
- Sets a value in the session storage. Calls the session driver's `set` method.
- start() : void
- Starts the session by invoking the session driver's start method.
Properties
$sessionDriver
protected
SessionStorage
$sessionDriver
Methods
__construct()
Constructor for the Session class.
public
__construct(SessionStorage $storage) : mixed
Parameters
- $storage : SessionStorage
-
The session storage handler instance.
__destruct()
Destructor method for the Session class.
public
__destruct() : mixed
This method is automatically called when the object is destroyed. It can be used to perform cleanup tasks, such as closing session resources or saving session data before the object is removed from memory.
ageFlashData()
Ages the flash data stored in the session.
public
ageFlashData() : void
This method moves the current "new" flash data to the "old" flash data and clears the "new" flash data. Flash data is typically used to store temporary session data that is only available for the next request.
destroy()
Destroys the current session.
public
destroy() : bool
This method calls the session driver's destroy
method to terminate
the session and remove any associated session data.
Return values
bool —Returns true on success or false on failure.
flash()
Stores a flash message in the session.
public
flash(string $key, mixed $value) : void
Flash messages are temporary data that will only be available for the next request. This method sets the given key-value pair in the session and marks it as a "new" flash message.
Parameters
- $key : string
-
The key under which the flash message will be stored.
- $value : mixed
-
The value of the flash message.
get()
Retrieves a value from the session using the specified key. Calls the session driver's `get` method.
public
get(string $key[, mixed|null $default = null ]) : mixed
Parameters
- $key : string
-
The key associated with the value to retrieve.
- $default : mixed|null = null
-
The default value to return if the key does not exist in the session.
Return values
mixed —The value associated with the key, or the default value if the key does not exist.
has()
Checks if a specific key exists in the session. Calls the session driver's `has` method.
public
has(string $key) : bool
Parameters
- $key : string
-
The key to check for existence in the session.
Return values
bool —Returns true if the key exists, false otherwise.
id()
Retrieve the current session ID. Calls the session driver's `id` method.
public
id() : string
This method delegates the retrieval of the session ID to the session driver being used.
Return values
string —The current session ID.
remove()
Removes a value from the session storage. Calls the session driver's `remove` method.
public
remove(string $key) : mixed
Parameters
- $key : string
-
The key of the session variable to remove.
Return values
mixed —The result of the removal operation, as defined by the session driver.
set()
Sets a value in the session storage. Calls the session driver's `set` method.
public
set(string $key, mixed $value) : void
Parameters
- $key : string
-
The key under which the value will be stored.
- $value : mixed
-
The value to store in the session.
start()
Starts the session by invoking the session driver's start method.
public
start() : void
This method initializes the session handling process using the configured session driver.