Light-weight, framework-agnostic interfaces for session managers and session segments. These interfaces let packages depend on the contract of a session without pulling in a full session implementation.
They are used by:
- Aura.Session, which provides the full-featured implementation; and
- Aura.Auth, which only needs a very light session to work independently, but can also accept an Aura.Session instance directly because both speak these interfaces.
composer require aura/session-interfaceThis package has no dependencies other than PHP ^8.1.
The segment contract is split into three interfaces by capability, following the interface-segregation principle, so a consumer depends only on what it actually uses.
The minimal contract for a session manager:
| Method | Purpose |
|---|---|
start(): bool |
Start a new session. |
resume(): bool |
Resume a previously-started session. |
regenerateId(): bool |
Regenerate the session ID. |
The minimal contract for reading and writing values in a session segment:
| Method | Purpose |
|---|---|
get(string $key, $alt): mixed |
Read a value (or an alternative). |
set(string $key, $val): void |
Write a value. |
The contract for managing a segment as a whole:
| Method | Purpose |
|---|---|
getSegment(): mixed |
Read the entire segment. |
clear(): void |
Empty the segment. |
remove(?string $key): void |
Remove one key, or the whole segment if null. |
The contract for "flash" values (available for the next request, and/or the
current one): setFlash(), getFlash(), clearFlash(), getFlashNext(),
setFlashNow(), clearFlashNow(), and keepFlash().
Each of these is a separate interface so that consumers that only read and
write plain values do not have to depend on whole-segment management or flash
behaviour. A full implementation simply composes the ones it needs — for
example Aura.Session's own SegmentInterface extends all three:
namespace Aura\Session;
use Aura\Session_Interface\SegmentInterface as BaseSegmentInterface;
use Aura\Session_Interface\ManageableSegmentInterface;
use Aura\Session_Interface\FlashSegmentInterface;
interface SegmentInterface extends
BaseSegmentInterface,
ManageableSegmentInterface,
FlashSegmentInterface
{
}By extracting these interfaces into their own zero-dependency package, a
consumer such as Aura.Auth can type-hint against SessionInterface and
SegmentInterface and:
- ship a tiny built-in implementation for standalone use, and
- transparently accept a full
Aura\Session\Session/ segment when one is available,
without either package depending on the other.