Test Failed
Pull Request — master (#96)
by
unknown
08:52
created

DoctrineMappingsCompilerPass::process()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 2
nop 1
1
<?php
2
3
namespace Gesdinet\JWTRefreshTokenBundle\DependencyInjection\Compiler;
4
5
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass;
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
9
/**
10
 * Class DoctrineMappingsCompilerPass
11
 *
12
 * We can't add DoctrineOrmMappingsPass directly, because in GesdinetJWTRefreshTokenBundle->build we don't have current
13
 * bundle configuration yet.
14
 * This CompilerPass is effectively just a wrapper for DoctrineOrmMappingsPass, which passes mappings conditionally.
15
 *
16
 * @package Gesdinet\JWTRefreshTokenBundle\DependencyInjection\Compiler
17
 */
18
final class DoctrineMappingsCompilerPass implements CompilerPassInterface
19
{
20
    /**
21
     * Process Doctrine mappings based on gesdinet_jwt_refresh_token.refresh_token_entity config parameter.
22
     * If this parameter contains user-defined entity, RefreshToken will be registered as a mapped superclass, not as an
23
     * entity, to prevent Doctrine creating table for it and avoid conflicts with user-defined entity.
24
     *
25
     * @param ContainerBuilder $container
26
     */
27
    public function process(ContainerBuilder $container)
28
    {
29
        $mappings = array(
30
            realpath(__DIR__.'/../../Resources/config/doctrine-orm') => 'Gesdinet\JWTRefreshTokenBundle\Entity',
31
        );
32
        $config = $container->getExtensionConfig('gesdinet_jwt_refresh_token')[0];
33
        if (isset($config['refresh_token_entity'])) {
34
            $mappings[realpath(__DIR__.'/../../Resources/config/doctrine-superclass')] = 'Gesdinet\JWTRefreshTokenBundle\Entity';
35
        } else {
36
            $mappings[realpath(__DIR__.'/../../Resources/config/doctrine-entity')] = 'Gesdinet\JWTRefreshTokenBundle\Entity';
37
        }
38
39
        $pass = DoctrineOrmMappingsPass::createYamlMappingDriver($mappings);
40
        $pass->process($container);
41
    }
42
43
}
44