Skip to content

Commit d5ed66c

Browse files
Merge branch '3.4' into 4.2
* 3.4: Fix Twig 1.x compatibility [Translator] Improve farsi(persian) translations for Form Improve fa translations Added tests to cover the possibility of having scalars as services. fixed tests on old PHP versions [FrameworkBundle] Inform the user when save_path will be ignored fixed CS [Translator] Load plurals from po files properly [EventDispatcher] Add tag kernel.rest on 'debug.event_dispatcher' service [Console] Update to inherit and add licence [Intl] Remove --dev from intl compile autoloader [Intl] Init compile tmp volume PHP 5 compat Add test case Update Request.php Don't assume port 0 for X-Forwarded-Port Load plurals from mo files properly
2 parents 904226a + 0fcde9e commit d5ed66c

File tree

8 files changed

+50
-2
lines changed

8 files changed

+50
-2
lines changed

DependencyInjection/Configuration.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,12 @@ private function addSessionSection(ArrayNodeDefinition $rootNode)
479479
$rootNode
480480
->children()
481481
->arrayNode('session')
482+
->validate()
483+
->ifTrue(function ($v) {
484+
return empty($v['handler_id']) && !empty($v['save_path']);
485+
})
486+
->thenInvalid('Session save path is ignored without a handler service')
487+
->end()
482488
->info('session configuration')
483489
->canBeEnabled()
484490
->children()
@@ -504,7 +510,7 @@ private function addSessionSection(ArrayNodeDefinition $rootNode)
504510
->scalarNode('gc_divisor')->end()
505511
->scalarNode('gc_probability')->defaultValue(1)->end()
506512
->scalarNode('gc_maxlifetime')->end()
507-
->scalarNode('save_path')->defaultValue('%kernel.cache_dir%/sessions')->end()
513+
->scalarNode('save_path')->end()
508514
->integerNode('metadata_update_threshold')
509515
->defaultValue(0)
510516
->info('seconds to wait between 2 session metadata updates')

DependencyInjection/FrameworkExtension.php

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

810810
// session handler (the internal callback registered with PHP session management)
811811
if (null === $config['handler_id']) {
812+
// If the user set a save_path without using a non-default \SessionHandler, it will silently be ignored
813+
if (isset($config['save_path'])) {
814+
throw new LogicException('Session save path is ignored without a handler service');
815+
}
816+
812817
// Set the handler class to be null
813818
$container->getDefinition('session.storage.native')->replaceArgument(1, null);
814819
$container->getDefinition('session.storage.php_bridge')->replaceArgument(0, null);
815820
} else {
816821
$container->setAlias('session.handler', $config['handler_id'])->setPrivate(true);
817822
}
818823

824+
if (!isset($config['save_path'])) {
825+
$config['save_path'] = ini_get('session.save_path');
826+
}
827+
819828
$container->setParameter('session.save_path', $config['save_path']);
820829

821830
$container->setParameter('session.metadata.update_threshold', $config['metadata_update_threshold']);

Resources/config/debug.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
<service id="debug.event_dispatcher" class="Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher" decorates="event_dispatcher">
1111
<tag name="monolog.logger" channel="event" />
12+
<tag name="kernel.reset" method="reset" />
1213
<argument type="service" id="debug.event_dispatcher.inner" />
1314
<argument type="service" id="debug.stopwatch" />
1415
<argument type="service" id="logger" on-invalid="null" />

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@ protected static function getBundleDefaultConfig()
265265
'cookie_httponly' => true,
266266
'cookie_samesite' => null,
267267
'gc_probability' => 1,
268-
'save_path' => '%kernel.cache_dir%/sessions',
269268
'metadata_update_threshold' => 0,
270269
],
271270
'request' => [
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

Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
2525
use Symfony\Component\Cache\Adapter\ProxyAdapter;
2626
use Symfony\Component\Cache\Adapter\RedisAdapter;
27+
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
2728
use Symfony\Component\DependencyInjection\ChildDefinition;
2829
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
2930
use Symfony\Component\DependencyInjection\Compiler\ResolveInstanceofConditionalsPass;
@@ -510,6 +511,14 @@ public function testNullSessionHandler()
510511
$this->assertEquals($expected, array_keys($container->getDefinition('session_listener')->getArgument(0)->getValues()));
511512
}
512513

514+
/**
515+
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
516+
*/
517+
public function testNullSessionHandlerWithSavePath()
518+
{
519+
$this->createContainerFromFile('session_savepath');
520+
}
521+
513522
public function testRequest()
514523
{
515524
$container = $this->createContainerFromFile('full');

0 commit comments

Comments
 (0)