Skip to content

Commit 7bfda23

Browse files
committed
Avoid complaining about the missing session when no features are needing it
1 parent 2e04e33 commit 7bfda23

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

DependencyInjection/Compiler/CheckForSessionPass.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class CheckForSessionPass implements CompilerPassInterface
2727
*/
2828
public function process(ContainerBuilder $container)
2929
{
30-
if (!$container->has('session')) {
30+
if ($container->has('fos_user.session') && !$container->has('session')) {
3131
$message = 'FOSUserBundle requires the "session" service to be available.';
3232

3333
if (class_exists(Recipe::class)) {

DependencyInjection/FOSUserExtension.php

+8
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class FOSUserExtension extends Extension
4141
);
4242

4343
private $mailerNeeded = false;
44+
private $sessionNeeded = false;
4445

4546
/**
4647
* {@inheritdoc}
@@ -78,6 +79,7 @@ public function load(array $configs, ContainerBuilder $container)
7879
}
7980

8081
if ($config['use_flash_notifications']) {
82+
$this->sessionNeeded = true;
8183
$loader->load('flash_notifications.xml');
8284
}
8385

@@ -130,6 +132,11 @@ public function load(array $configs, ContainerBuilder $container)
130132
if ($this->mailerNeeded) {
131133
$container->setAlias('fos_user.mailer', $config['service']['mailer']);
132134
}
135+
136+
if ($this->sessionNeeded) {
137+
// Use a private alias rather than a parameter, to avoid leaking it at runtime (the private alias will be removed)
138+
$container->setAlias('fos_user.session', new Alias('session', false));
139+
}
133140
}
134141

135142
/**
@@ -203,6 +210,7 @@ private function loadProfile(array $config, ContainerBuilder $container, XmlFile
203210
private function loadRegistration(array $config, ContainerBuilder $container, XmlFileLoader $loader, array $fromEmail)
204211
{
205212
$loader->load('registration.xml');
213+
$this->sessionNeeded = true;
206214

207215
if ($config['confirmation']['enabled']) {
208216
$this->mailerNeeded = true;

0 commit comments

Comments
 (0)