linkorb / flex-session
Allow to switch session storage backend by a single environment variable
v0.1.0
2019-04-25 07:53 UTC
Requires
- php: ^7.1
- symfony/http-foundation: ^4.0
Requires (Dev)
- phpunit/phpunit: ^8
This package is auto-updated.
Last update: 2024-11-25 19:36:39 UTC
README
FlexSession: .env configurable session backends
Allows switching the SessionHandler at Runtime using environment variables.
Using
$typeProvider = TypeProviderFactory::fromEnv('FLEX_SESSION'); $handlerFactory = new FlexSessionHandlerFactory($typeProvider); $handlerFactory->addType('file', new FileSessionHandlerFactory()); $handlerFactory->addType('memcached', new MemcachedSessionHandlerFactory()); $handlerFactory->addType('pdo', new PdoSessionHandlerFactory()); $handler = new FlexSessionHandler($handlerFactory); $session = new Session(new NativeSessionStorage([], $handler));
Example define environment variable
# File based
FLEX_SESSION=file?path=/tmp/my-app-sessions
# Memached
FLEX_SESSION=memcached?server=127.0.0.1
# PDO
FLEX_SESSION=pdo?dsn=mysql:host=localhost;dbname=testdb&username=x&password=y&table=session_table
Run tests
./vendor/bin/phpunit --bootstrap vendor/autoload.php tests/