8000 [FrameworkBundle] Inform the user when save_path will be ignored by gnat42 · Pull Request #31620 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[FrameworkBundle] Inform the user when save_path will be ignored #31620

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

Merged
merged 1 commit into from
Jul 8, 2019
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,12 @@ private function addSessionSection(ArrayNodeDefinition $rootNode)
$rootNode
->children()
->arrayNode('session')
->validate()
->ifTrue(function ($v) {
return empty($v['handler_id']) && !empty($v['save_path']);
})
->thenInvalid('Session save path is ignored without a handler service')
->end()
->info('session configuration')
->canBeEnabled()
->children()
Expand Down Expand Up @@ -498,7 +504,7 @@ private function addSessionSection(ArrayNodeDefinition $rootNode)
->defaultTrue()
->setDeprecated('The "%path%.%node%" option is enabled by default and deprecated since Symfony 3.4. It will be always enabled in 4.0.')
->end()
->scalarNode('save_path')->defaultValue('%kernel.cache_dir%/sessions')->end()
->scalarNode('save_path')->end()
->integerNode('metadata_update_threshold')
->defaultValue('0')
->info('seconds to wait between 2 session metadata updates')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -873,13 +873,22 @@ private function registerSessionConfiguration(array $config, ContainerBuilder $c

// session handler (the internal callback registered with PHP session management)
if (null === $config['handler_id']) {
// If the user set a save_path without using a non-default \SessionHandler, it will silently be ignored
if (isset($config['save_path'])) {
throw new LogicException('Session save path is ignored without a handler service');
}

// Set the handler class to be null
$container->getDefinition('session.storage.native')->replaceArgument(1, null);
$container->getDefinition('session.storage.php_bridge')->replaceArgument(0, null);
} else {
$container->setAlias('session.handler', $config['handler_id'])->setPrivate(true);
}

if (!isset($config['save_path'])) {
$config['save_path'] = ini_get('session.save_path');
}

$container->setParameter('session.save_path', $config['save_path']);

if (\PHP_VERSION_ID < 70000) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@ protected static function getBundleDefaultConfig()
'handler_id' => 'session.handler.native_file',
'cookie_httponly' => true,
'gc_probability' => 1,
'save_path' => '%kernel.cache_dir%/sessions',
'metadata_update_threshold' => '0',
'use_strict_mode' => true,
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

$container->loadFromExtension('framework', [
'session' => [
'handler_id' => null,
'save_path' => '/some/path',
],
]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<framework:session handler-id="null" save-path="/some/path"/>
</framework:config>
</container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
framework:
session:
handler_id: null
save_path: /some/path
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\Adapter\ProxyAdapter;
use Symfony\Component\Cache\Adapter\RedisAdapter;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down Expand Up @@ -474,6 +475,12 @@ public function testNullSessionHandler()
$this->assertNull($container->getDefinition('session.storage.php_bridge')->getArgument(0));
}

public function testNullSessionHandlerWithSavePath()
{
$this->expectException(InvalidConfigurationException::class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must be converted to an annotation for tests to pass on old PHP versions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$this->createContainerFromFile('session_savepath');
}

public function testRequest()
{
$container = $this->createContainerFromFile('full');
Expand Down
0