linkorb/flex-session

Allow to switch session storage backend by a single environment variable

v0.1.0 2019-04-25 07:53 UTC

This package is auto-updated.

Last update: 2024-10-25 19:34:01 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/

Links

The HttpFoundation Component(Symfony Docs)