PHPackages                             componenta/session - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. componenta/session

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

componenta/session
==================

Framework-agnostic session management library for PHP 8.4+

v1.0.0(1mo ago)00MITPHPPHP &gt;=8.4

Since Jun 16Pushed 1mo agoCompare

[ Source](https://github.com/componenta/session)[ Packagist](https://packagist.org/packages/componenta/session)[ RSS](/packages/componenta-session/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

Componenta Session
==================

[](#componenta-session)

Framework-agnostic session management for PHP 8.4+: session ids, session data, metadata, storage, serialization, cookies, manager lifecycle, and PSR-15 middleware.

Use this package when the application needs explicit session control instead of relying directly on PHP's global `$_SESSION` state.

Installation
------------

[](#installation)

```
composer require componenta/session
```

Requirements
------------

[](#requirements)

- PHP 8.4+
- PSR-7 / PSR-15 for middleware integration

Related Packages
----------------

[](#related-packages)

PackageWhy it matters here`componenta/auth`Uses session ids for session authentication.`psr/http-message` / `psr/http-server-middleware`Session middleware reads cookies from PSR-7 requests and writes cookies to PSR-7 responses.`componenta/pipeline`Runs `SessionMiddleware` in the HTTP middleware chain.Session Data
------------

[](#session-data)

`SessionData` stores attributes and flash messages.

```
use Componenta\Session\SessionData;

$data = new SessionData(['user_id' => 42]);

$data->getInt('user_id');     // 42
$data->set('theme', 'dark');
$data->pull('theme');         // "dark" and removes it
$data->only('user_id');
$data->except('csrf_token');
```

Typed getters throw `AttributeNotFoundException` when a required key is missing and `AttributeTypeMismatchException` when a value has the wrong type.

Flash messages are meant for the next request:

```
$data->flash('success', 'Saved');
$data->peekFlashes('success'); // keeps messages
$data->getFlashes('success');  // reads and removes messages
```

Session Identity
----------------

[](#session-identity)

```
use Componenta\Session\SessionId;

$id = new SessionId('abc123');
(string) $id; // abc123
```

Empty ids are rejected. `SessionIdGenerator` creates new ids for fresh and regenerated sessions.

Lifecycle Manager
-----------------

[](#lifecycle-manager)

`SessionManager` coordinates storage and serialization.

```
use Componenta\Session\SessionManager;

$manager = new SessionManager($storage);

$session = $manager->start($id);
$session->data->set('user_id', 42);

$manager->save($session);
$manager->regenerate($session, deleteOld: true);
$manager->destroy($session);
```

`start(null)` creates a new session. `start($id)` reads existing storage and hydrates metadata/data. Broken serialized payloads surface as `SessionException`.

Storage And Serialization
-------------------------

[](#storage-and-serialization)

Storage is abstracted by `SessionStorageInterface`:

- `ArraySessionStorage`: in-memory storage for simple runtime/test use.
- `FileSessionStorage`: file-backed storage.
- `NativeSessionHandler`: bridge to native PHP session handling.

Serialization is abstracted by `SessionSerializerInterface`:

- `PhpSerializer`
- `JsonSerializer`

Use JSON only for data that can be represented safely as JSON arrays/scalars.

Cookies And Middleware
----------------------

[](#cookies-and-middleware)

`SessionCookieManager` reads and writes session cookies using `SessionCookieOptions` and `SameSite`.

`SessionMiddleware` integrates the manager with a PSR-15 pipeline: it reads the request cookie, starts the session, attaches session state, delegates to the next handler, then persists the session and emits the cookie.

Configuration
-------------

[](#configuration)

`SessionConfig` controls TTL and garbage-collection settings. Storage implementations may use these values differently, but the manager always passes TTL on save and `gcMaxLifetime` on cleanup.

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance91

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

43d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/20490712?v=4)[Andrey Shelamkoff](/maintainers/Shelamkoff)[@Shelamkoff](https://github.com/Shelamkoff)

---

Top Contributors

[![Shelamkoff](https://avatars.githubusercontent.com/u/20490712?v=4)](https://github.com/Shelamkoff "Shelamkoff (1 commits)")

---

Tags

phpmiddlewarepsr-15session

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/componenta-session/health.svg)

```
[![Health](https://phpackages.com/badges/componenta-session/health.svg)](https://phpackages.com/packages/componenta-session)
```

###  Alternatives

[mezzio/mezzio

PSR-15 Middleware Microframework

3923.8M126](/packages/mezzio-mezzio)[cakephp/authentication

Authentication plugin for CakePHP

1214.1M107](/packages/cakephp-authentication)[jaxon-php/jaxon-core

Jaxon is an open source PHP library for easily creating Ajax web applications

73149.4k30](/packages/jaxon-php-jaxon-core)[flarum/core

Delightfully simple forum software.

211.4M2.4k](/packages/flarum-core)[sunrise/http-router

A powerful solution as the foundation of your project.

17451.8k11](/packages/sunrise-http-router)[xima/xima-typo3-frontend-edit

Frontend Edit - This extension provides an edit button for editors within frontend content elements.

1414.3k](/packages/xima-xima-typo3-frontend-edit)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
