Skip to content

Commit 255d13c

Browse files
committed
Adding a new compiler pass to notify that the session is required
1 parent eaffd1d commit 255d13c

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the FOSUserBundle package.
5+
*
6+
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
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 FOS\UserBundle\DependencyInjection\Compiler;
13+
14+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
use Symfony\Flex\Recipe;
17+
18+
/**
19+
* Checks to see if the session service exists.
20+
*
21+
* @author Ryan Weaver <ryan@knpuniversity.com>
22+
*/
23+
class CheckForSessionPass implements CompilerPassInterface
24+
{
25+
/**
26+
* {@inheritdoc}
27+
*/
28+
public function process(ContainerBuilder $container)
29+
{
30+
if (!$container->has('session')) {
31+
$message = 'FOSUserBundle requires the "session" service to be available.';
32+
33+
if (class_exists(Recipe::class)) {
34+
$message .= ' Uncomment the "session" section in "config/packages/framework.yaml" to activate it.';
35+
}
36+
37+
throw new \LogicException($message);
38+
}
39+
}
40+
}

FOSUserBundle.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Doctrine\Bundle\CouchDBBundle\DependencyInjection\Compiler\DoctrineCouchDBMappingsPass;
1515
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass;
1616
use Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\DoctrineMongoDBMappingsPass;
17+
use FOS\UserBundle\DependencyInjection\Compiler\CheckForSessionPass;
1718
use FOS\UserBundle\DependencyInjection\Compiler\InjectRememberMeServicesPass;
1819
use FOS\UserBundle\DependencyInjection\Compiler\InjectUserCheckerPass;
1920
use FOS\UserBundle\DependencyInjection\Compiler\ValidationPass;
@@ -35,6 +36,7 @@ public function build(ContainerBuilder $container)
3536
$container->addCompilerPass(new ValidationPass());
3637
$container->addCompilerPass(new InjectUserCheckerPass());
3738
$container->addCompilerPass(new InjectRememberMeServicesPass());
39+
$container->addCompilerPass(new CheckForSessionPass());
3840

3941
$this->addRegisterMappingsPass($container);
4042
}

0 commit comments

Comments
 (0)