codemonster-ru / session
Lightweight session management library for PHP with pluggable handlers
Installs: 16
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/codemonster-ru/session
Requires
- php: >=8.2
Requires (Dev)
- phpunit/phpunit: ^9.6 || ^10.5 || ^11.0 || ^12.0
This package is auto-updated.
Last update: 2025-10-24 15:01:14 UTC
README
Lightweight session management library for PHP โ object-oriented.
๐ฆ Installation
composer require codemonster-ru/session
๐ Usage
Basic example
use Codemonster\Session\Session; // Start session (default: file storage) Session::start(); // Store values Session::put('user', 'Vasya'); Session::put('role', 'admin'); // Retrieve values echo Session::get('user'); // Vasya // Remove values Session::forget('role'); // Get all session data print_r(Session::all()); // Destroy current session Session::destroy();
Using Array handler (for tests or CLI)
Session::start('array'); Session::put('debug', true); echo Session::get('debug'); // true
Using custom handler
use Codemonster\Session\Session; use App\Session\RedisSessionHandler; $redis = new Redis(); $redis->connect('127.0.0.1', 6379); $handler = new RedisSessionHandler($redis); Session::start(customHandler: $handler); Session::put('user_id', 42);
๐งช Testing
You can run tests with the command:
composer test