Session Management

The documentation is constantly evolving and updated alongside the project's progress. Since it is developed in parallel with the code, some sections may temporarily refer to earlier versions of the system-these are gradually adapted to the current state of the application. If you notice any outdated information, please report it or open an Issue / Pull Request.

Documentation

# Session Management

# Overview

The SessionManager provides a simple interface for handling PHP sessions.


# Basic Usage

use Dbm\Infrastructure\Session\SessionManager;

$session = new SessionManager();
$session->start();

# Set Session

$session->setSession('user_id', 1);

# Get Session

$userId = $session->getSession('user_id');

# Remove Session

$session->unsetSession('user_id');

# Destroy Session

$session->destroySession();

# Pop (Get & Remove)

$message = $session->pop('flash_message');

# Reference Access

$data = &$session->getSessionByReference('cart');

$data[] = 'product_id';

# Notes

  • setSession(), getSession(), hasSession(), unsetSession(), pop(), and destroySession() operate on $_SESSION; they do not start the session. Start it explicitly or use the platform StartSessionMiddleware. getSessionByReference() and regenerateId() start a session when needed.
  • getSession() and pop() return null when the key is absent.
  • Useful for flash messages and carts

# Best Practices

  • Use sessions only for small data
  • Avoid storing large objects
  • Always secure session cookies