Skip to content

Commit

Permalink
Avoid complaining about the missing session when no features are need…
Browse files Browse the repository at this point in the history
…ing it
  • Loading branch information
stof committed Feb 19, 2018
1 parent 2e04e33 commit 7bfda23
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DependencyInjection/Compiler/CheckForSessionPass.php
Expand Up @@ -27,7 +27,7 @@ class CheckForSessionPass implements CompilerPassInterface
*/
public function process(ContainerBuilder $container)
{
if (!$container->has('session')) {
if ($container->has('fos_user.session') && !$container->has('session')) {
$message = 'FOSUserBundle requires the "session" service to be available.';

if (class_exists(Recipe::class)) {
Expand Down
8 changes: 8 additions & 0 deletions DependencyInjection/FOSUserExtension.php
Expand Up @@ -41,6 +41,7 @@ class FOSUserExtension extends Extension
);

private $mailerNeeded = false;
private $sessionNeeded = false;

/**
* {@inheritdoc}
Expand Down Expand Up @@ -78,6 +79,7 @@ public function load(array $configs, ContainerBuilder $container)
}

if ($config['use_flash_notifications']) {
$this->sessionNeeded = true;
$loader->load('flash_notifications.xml');
}

Expand Down Expand Up @@ -130,6 +132,11 @@ public function load(array $configs, ContainerBuilder $container)
if ($this->mailerNeeded) {
$container->setAlias('fos_user.mailer', $config['service']['mailer']);
}

if ($this->sessionNeeded) {
// Use a private alias rather than a parameter, to avoid leaking it at runtime (the private alias will be removed)
$container->setAlias('fos_user.session', new Alias('session', false));
}
}

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

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

0 comments on commit 7bfda23

Please sign in to comment.