Skip to content

Commit af79c9b

Browse files
Merge branch '4.2' into 4.3
* 4.2: 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 [Serializer]: AbstractObjectNormalizer ignores the property types of discriminated classes [EventDispatcher] Add tag kernel.rest on 'debug.event_dispatcher' service [Console] Update to inherit and add licence [Intl] Remove --dev from intl compile autoloader Remove call to deprecated method [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 c25ce5a + d5ed66c commit af79c9b

File tree

8 files changed

+49
-2
lines changed

8 files changed

+49
-2
lines changed

DependencyInjection/Configuration.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,12 @@ private function addSessionSection(ArrayNodeDefinition $rootNode)
522522
$rootNode
523523
->children()
524524
->arrayNode('session')
525+
->validate()
526+
->ifTrue(function ($v) {
527+
return empty($v['handler_id']) && !empty($v['save_path']);
528+
})
529+
->thenInvalid('Session save path is ignored without a handler service')
530+
->end()
525531
->info('session configuration')
526532
->canBeEnabled()
527533
->children()
@@ -547,7 +553,7 @@ private function addSessionSection(ArrayNodeDefinition $rootNode)
547553
->scalarNode('gc_divisor')->end()
548554
->scalarNode('gc_probability')->defaultValue(1)->end()
549555
->scalarNode('gc_maxlifetime')->end()
550-
->scalarNode('save_path')->defaultValue('%kernel.cache_dir%/sessions')->end()
556+
->scalarNode('save_path')->end()
551557
->integerNode('metadata_update_threshold')
552558
->defaultValue(0)
553559
->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
@@ -892,13 +892,22 @@ private function registerSessionConfiguration(array $config, ContainerBuilder $c
892892

893893
// session handler (the internal callback registered with PHP session management)
894894
if (null === $config['handler_id']) {
895+
// If the user set a save_path without using a non-default \SessionHandler, it will silently be ignored
896+
if (isset($config['save_path'])) {
897+
throw new LogicException('Session save path is ignored without a handler service');
898+
}
899+
895900
// Set the handler class to be null
896901
$container->getDefinition('session.storage.native')->replaceArgument(1, null);
897902
$container->getDefinition('session.storage.php_bridge')->replaceArgument(0, null);
898903
} else {
899904
$container->setAlias('session.handler', $config['handler_id'])->setPrivate(true);
900905
}
901906

907+
if (!isset($config['save_path'])) {
908+
$config['save_path'] = ini_get('session.save_path');
909+
}
910+
902911
$container->setParameter('session.save_path', $config['save_path']);
903912

904913
$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
@@ -301,7 +301,6 @@ protected static function getBundleDefaultConfig()
301301
'cookie_httponly' => true,
302302
'cookie_samesite' => null,
303303
'gc_probability' => 1,
304-
'save_path' => '%kernel.cache_dir%/sessions',
305304
'metadata_update_threshold' => 0,
306305
],
307306
'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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,14 @@ public function testNullSessionHandler()
561561
$this->assertEquals($expected, array_keys($container->getDefinition('session_listener')->getArgument(0)->getValues()));
562562
}
563563

564+
/**
565+
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
566+
*/
567+
public function testNullSessionHandlerWithSavePath()
568+
{
569+
$this->createContainerFromFile('session_savepath');
570+
}
571+
564572
public function testRequest()
565573
{
566574
$container = $this->createContainerFromFile('full');

0 commit comments

Comments
 (0)