Code

< 40 %
40-60 %
> 60 %
1
<?php
2
3
/*
4
 * This file is part of the EloyekunlePermissionsBundle package.
5
 *
6
 * (c) Elijah Oyekunle <https://elijahoyekunle.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 Eloyekunle\PermissionsBundle;
13
14
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass;
15
use Eloyekunle\PermissionsBundle\DependencyInjection\Compiler\ValidationPass;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
use Symfony\Component\HttpKernel\Bundle\Bundle;
18
19
class EloyekunlePermissionsBundle extends Bundle
20
{
21
    /**
22
     * @param ContainerBuilder $container
23
     */
24 2
    public function build(ContainerBuilder $container)
25
    {
26 2
        parent::build($container);
27 2
        $container->addCompilerPass(new ValidationPass());
28 2
        $this->addRegisterMappingsPass($container);
29 2
    }
30
31
    /**
32
     * @param ContainerBuilder $container
33
     */
34
    private function addRegisterMappingsPass(ContainerBuilder $container)
35
    {
36
        $mappings = [
37
            realpath(
38
                __DIR__.'/Resources/config/doctrine-mapping'
39
            ) => 'Eloyekunle\PermissionsBundle\Model',
40
        ];
41
        if (class_exists(
42
            'Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass'
43
        )) {
44
            $container->addCompilerPass(
45
                DoctrineOrmMappingsPass::createXmlMappingDriver(
46
                    $mappings,
47
                    ['eloyekunle_permissions.model_manager_name'],
48
                    'eloyekunle_permissions.backend_type_orm'
49
                )
50
            );
51
        }
52
    }
53
}
54