Code

< 40 %
40-60 %
> 60 %
1
<?php
2
3
/*
4
 *
5
 * (c) Yaroslav Honcharuk <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Yarhon\RouteGuardBundle;
12
13
use Symfony\Component\HttpKernel\Bundle\Bundle;
14
use Symfony\Component\DependencyInjection\ContainerBuilder;
15
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
16
use Yarhon\RouteGuardBundle\DependencyInjection\Compiler\SymfonySecurityBundlePass;
17
use Yarhon\RouteGuardBundle\DependencyInjection\Compiler\SensioFrameworkExtraBundlePass;
18
use Yarhon\RouteGuardBundle\DependencyInjection\Compiler\SensioSecurityExpressionVoterPass;
19
use Yarhon\RouteGuardBundle\DependencyInjection\Compiler\TwigBundlePass;
20
use Yarhon\RouteGuardBundle\DependencyInjection\Compiler\ContainerClassMapPass;
21
use Yarhon\RouteGuardBundle\DependencyInjection\Compiler\InjectTaggedServicesPass;
22
use Yarhon\RouteGuardBundle\DependencyInjection\Container\ForeignExtensionAccessor;
23
use Yarhon\RouteGuardBundle\DependencyInjection\Container\ClassMapBuilder;
24
25
/**
26
 * @author Yaroslav Honcharuk <[email protected]>
27
 */
28
class YarhonRouteGuardBundle extends Bundle
29
{
30
    /**
31
     * {@inheritdoc}
32
     */
33 18
    public function build(ContainerBuilder $container)
34
    {
35 18
        parent::build($container);
36
37 18
        $foreignExtensionAccessor = new ForeignExtensionAccessor();
38 18
        $classMapBuilder = new ClassMapBuilder();
39
40
        // We need to be able to remove SensioSecurityExpressionVoter before it is registered in "security.access.decision_manager" service
41 18
        $container->addCompilerPass(new SensioSecurityExpressionVoterPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 1);
42
43
        // We use same type and priority as are used for \Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\ExtensionPass
44 18
        $container->addCompilerPass(new TwigBundlePass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 0);
45
46 18
        $container->addCompilerPass(new SymfonySecurityBundlePass($foreignExtensionAccessor), PassConfig::TYPE_BEFORE_REMOVING, 100);
47 18
        $container->addCompilerPass(new SensioFrameworkExtraBundlePass(), PassConfig::TYPE_BEFORE_REMOVING, 101);
48
49 18
        $container->addCompilerPass(new InjectTaggedServicesPass(), PassConfig::TYPE_BEFORE_REMOVING, 0);
50
51
        // We need only public services for the class map, so we include this pass at the very end, after removing all private services.
52 18
        $container->addCompilerPass(new ContainerClassMapPass($classMapBuilder), PassConfig::TYPE_AFTER_REMOVING, 0);
53 18
    }
54
}
55