mini\Session\SessionProxy class

Documentation

Global proxy for $_SESSION that auto-starts sessions on access

This proxy replaces PHP's native $_SESSION superglobal, providing:

  • Automatic session start on first array access
  • Per-request session instances in fiber/async environments
  • Transparent integration with existing $_SESSION code

Traditional PHP behavior:

session_start();                 // Must call manually
$_SESSION['user'] = 'john';      // Only works after session_start()

With SessionProxy:

$_SESSION['user'] = 'john';      // Auto-starts session, just works
$user = $_SESSION['user'];       // Returns 'john'

The proxy delegates all operations to a per-request SessionInterface instance obtained from Mini's service container. This enables:

  • Fiber-safe sessions (each request has its own Session instance)
  • Testability (swap SessionInterface for a mock)
  • Runtime agnostic (works in FPM, Swoole, phasync, etc.)

Inheritance

Implements: ArrayAccess Countable IteratorAggregate Traversable

Methods (8)

Get the Session instance for the current request

Check if a session key exists

Get a session value

Set a session value

Remove a session key

Count session items

Get iterator for session data

Debug info for var_dump()

Source

src/Session/SessionProxy.php:36-144