Skip to content

Commit d334e5f

Browse files
committed
[HttpFoundation][Cache] Added MarshallingSessionHandler
1 parent 98eb084 commit d334e5f

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
13+
14+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
17+
/**
18+
* @author Ahmed TAILOULOUTE <[email protected]>
19+
*/
20+
class RemoveUnusedSessionMarshallingHandlerPass implements CompilerPassInterface
21+
{
22+
public function process(ContainerBuilder $container)
23+
{
24+
if (!$container->hasDefinition('session.marshalling_handler')) {
25+
return;
26+
}
27+
28+
$isMarshallerDecorated = false;
29+
30+
foreach ($container->getDefinitions() as $definition) {
31+
$decorated = $definition->getDecoratedService();
32+
if (null !== $decorated && 'session.marshaller' === $decorated[0]) {
33+
$isMarshallerDecorated = true;
34+
35+
break;
36+
}
37+
}
38+
39+
if (!$isMarshallerDecorated) {
40+
$container->removeDefinition('session.marshalling_handler');
41+
}
42+
}
43+
}

FrameworkBundle.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\DataCollectorTranslatorPass;
1919
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\LoggingTranslatorPass;
2020
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ProfilerPass;
21+
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RemoveUnusedSessionMarshallingHandlerPass;
2122
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TestServiceContainerRealRefPass;
2223
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TestServiceContainerWeakRefPass;
2324
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass;
@@ -130,6 +131,7 @@ public function build(ContainerBuilder $container)
130131
$this->addCompilerPassIfExists($container, AddAutoMappingConfigurationPass::class);
131132
$container->addCompilerPass(new RegisterReverseContainerPass(true));
132133
$container->addCompilerPass(new RegisterReverseContainerPass(false), PassConfig::TYPE_AFTER_REMOVING);
134+
$container->addCompilerPass(new RemoveUnusedSessionMarshallingHandlerPass());
133135

134136
if ($container->getParameter('kernel.debug')) {
135137
$container->addCompilerPass(new AddDebugLogProcessorPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 2);

Resources/config/session.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,12 @@
7171

7272
<!-- for BC -->
7373
<service id="session.storage.filesystem" alias="session.storage.mock_file" />
74+
75+
<service id="session.marshaller" class="Symfony\Component\HttpFoundation\Session\Storage\Handler\IdentityMarshaller" />
76+
77+
<service id="session.marshalling_handler" decorates="session.handler" class="Symfony\Component\HttpFoundation\Session\Storage\Handler\MarshallingSessionHandler">
78+
<argument type="service" id="session.marshalling_handler.inner" />
79+
<argument type="service" id="session.marshaller" />
80+
</service>
7481
</services>
7582
</container>

0 commit comments

Comments
 (0)