Skip to content

[Framework Bundle] Allow to configure PSR6 cache for session #23323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ CHANGELOG
require symfony/stopwatch` in your `dev` environment.
* Deprecated using the `KERNEL_DIR` environment variable with `KernelTestCase::getKernelClass()`.
* Deprecated the `KernelTestCase::getPhpUnitXmlDir()` and `KernelTestCase::getPhpUnitCliConfigArgument()` methods.
* Added support for `PSR6SessionHandler`.

3.3.0
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,11 +437,26 @@ private function addSessionSection(ArrayNodeDefinition $rootNode)
->scalarNode('gc_maxlifetime')->end()
->booleanNode('use_strict_mode')->end()
->scalarNode('save_path')->defaultValue('%kernel.cache_dir%/sessions')->end()
->scalarNode('psr6_ttl')->defaultNull()->end()
->scalarNode('psr6_prefix')->defaultNull()->end()
->scalarNode('psr6_service')->defaultNull()->end()
->integerNode('metadata_update_threshold')
->defaultValue('0')
->info('seconds to wait between 2 session metadata updates, it will also prevent the session handler to write if the session has not changed')
->end()
->end()
->validate()
->ifTrue(function ($v) {
return $v['handler_id'] === 'session.handler.psr6' && !isset($v['psr6_service']);
})
->thenInvalid('When handler_id="session.handler.psr6" you must also define a value for "psr6_service". Example "cache.app".')
->end()
->validate()
->ifTrue(function ($v) {
return $v['handler_id'] !== 'session.handler.psr6' && (isset($v['psr6_ttl']) || isset($v['psr6_prefix']) || isset($v['psr6_service']));
})
->thenInvalid('You must specify handler_id="session.handler.psr6" when you use "psr6_ttl", "psr6_prefix" or "psr6_service".')
->end()
->end()
->end()
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
use Symfony\Component\Finder\Finder;
use Symfony\Component\Form\FormTypeGuesserInterface;
use Symfony\Component\Form\FormTypeInterface;
use Symfony\Component\HttpFoundation\Session\Storage\Handler\Psr6SessionHandler;
use Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface;
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface;
Expand Down Expand Up @@ -765,6 +766,13 @@ private function registerSessionConfiguration(array $config, ContainerBuilder $c
// Set the handler class to be null
$container->getDefinition('session.storage.native')->replaceArgument(1, null);
$container->getDefinition('session.storage.php_bridge')->replaceArgument(0, null);
} elseif ('session.handler.psr6' === $config['handler_id']) {
$container->register('session.handler.psr6', Psr6SessionHandler::class)
->addArgument(new Reference($config['psr6_service']))
->addArgument([
'prefix' => $config['psr6_prefix'],
'ttl' => $config['psr6_ttl'],
]);
} else {
$handlerId = $config['handler_id'];

Expand Down