Skip to content

Commit 6676af0

Browse files
committed
Deprecat service "session"
1 parent 2882ce9 commit 6676af0

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Compiler/RegisterServiceSubscribersPass.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
namespace Symfony\Component\DependencyInjection\Compiler;
1313

1414
use Psr\Container\ContainerInterface as PsrContainerInterface;
15+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1516
use Symfony\Component\DependencyInjection\Argument\BoundArgument;
1617
use Symfony\Component\DependencyInjection\ContainerInterface;
1718
use Symfony\Component\DependencyInjection\Definition;
1819
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1920
use Symfony\Component\DependencyInjection\Reference;
2021
use Symfony\Component\DependencyInjection\TypedReference;
22+
use Symfony\Component\HttpFoundation\Session\SessionInterface;
2123
use Symfony\Contracts\Service\ServiceProviderInterface;
2224
use Symfony\Contracts\Service\ServiceSubscriberInterface;
2325

@@ -66,7 +68,7 @@ protected function processValue($value, bool $isRoot = false)
6668
throw new InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $this->currentId, ServiceSubscriberInterface::class));
6769
}
6870
$class = $r->name;
69-
71+
$replaceDeprecatedSession = $this->container->has('.session.deprecated') && $r->isSubclassOf(AbstractController::class);
7072
$subscriberMap = [];
7173

7274
foreach ($class::getSubscribedServices() as $key => $type) {
@@ -85,6 +87,11 @@ protected function processValue($value, bool $isRoot = false)
8587
if (!$autowire) {
8688
throw new InvalidArgumentException(sprintf('Service "%s" misses a "container.service_subscriber" tag with "key"/"id" attributes corresponding to entry "%s" as returned by "%s::getSubscribedServices()".', $this->currentId, $key, $class));
8789
}
90+
if ($replaceDeprecatedSession && SessionInterface::class === $type) {
91+
// This prevents triggering the deprecation when building the container
92+
// Should be removed in Symfony 6.0
93+
$type = '.session.deprecated';
94+
}
8895
$serviceMap[$key] = new Reference($type);
8996
}
9097

0 commit comments

Comments
 (0)