Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ff3b566

Browse files
committed
[FrameworkBundle] Inform the user when save_path is ignored due to missing handler_id
1 parent 2bf5da5 commit ff3b566

File tree

7 files changed

+41
-2
lines changed

7 files changed

+41
-2
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ private function addSessionSection(ArrayNodeDefinition $rootNode)
498498
->defaultTrue()
499499
->setDeprecated('The "%path%.%node%" option is enabled by default and deprecated since Symfony 3.4. It will be always enabled in 4.0.')
500500
->end()
501-
->scalarNode('save_path')->defaultValue('%kernel.cache_dir%/sessions')->end()
501+
->scalarNode('save_path')->end()
502502
->integerNode('metadata_update_threshold')
503503
->defaultValue('0')
504504
->info('seconds to wait between 2 session metadata updates')

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,13 +873,22 @@ private function registerSessionConfiguration(array $config, ContainerBuilder $c
873873

874874
// session handler (the internal callback registered with PHP session management)
875875
if (null === $config['handler_id']) {
876+
// If the user set a save_path without using a non-default \SessionHandler, it will silently be ignored
877+
if (isset($config['save_path'])) {
878+
throw new LogicException('Session save path is ignored without a handler service');
879+
}
880+
876881
// Set the handler class to be null
877882
$container->getDefinition('session.storage.native')->replaceArgument(1, null);
878883
$container->getDefinition('session.storage.php_bridge')->replaceArgument(0, null);
879884
} else {
880885
$container->setAlias('session.handler', $config['handler_id'])->setPrivate(true);
881886
}
882887

888+
if (!isset($config['save_path'])) {
889+
$config['save_path'] = ini_get('session.save_path');
890+
}
891+
883892
$container->setParameter('session.save_path', $config['save_path']);
884893

885894
if (\PHP_VERSION_ID < 70000) {

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,6 @@ protected static function getBundleDefaultConfig()
378378
'handler_id' => 'session.handler.native_file',
379379
'cookie_httponly' => true,
380380
'gc_probability' => 1,
381-
'save_path' => '%kernel.cache_dir%/sessions',
382381
'metadata_update_threshold' => '0',
383382
'use_strict_mode' => true,
384383
],
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', [
4+
'session' => [
5+
'handler_id' => null,
6+
'save_path' => '/some/path',
7+
],
8+
]);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:framework="http://symfony.com/schema/dic/symfony"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
7+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
8+
9+
<framework:config>
10+
<framework:session handler-id="null" save-path="/some/path"/>
11+
</framework:config>
12+
</container>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
framework:
2+
session:
3+
handler_id: null
4+
save_path: /some/path

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use Symfony\Component\DependencyInjection\ContainerBuilder;
3030
use Symfony\Component\DependencyInjection\ContainerInterface;
3131
use Symfony\Component\DependencyInjection\Definition;
32+
use Symfony\Component\DependencyInjection\Exception\LogicException;
3233
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
3334
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
3435
use Symfony\Component\DependencyInjection\Reference;
@@ -474,6 +475,12 @@ public function testNullSessionHandler()
474475
$this->assertNull($container->getDefinition('session.storage.php_bridge')->getArgument(0));
475476
}
476477

478+
public function testNullSessionHandlerWithSavePath()
479+
{
480+
$this->expectException(LogicException::class);
481+
$this->createContainerFromFile('session_savepath');
482+
}
483+
477484
public function testRequest()
478485
{
479486
$container = $this->createContainerFromFile('full');

0 commit comments

Comments
 (0)