Test Failed
Pull Request — master (#96)
by
unknown
02:30
created

DoctrineMappingsCompilerPass::process()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 15
rs 9.4285
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
final class DoctrineMappingsCompilerPass implements CompilerPassInterface
17
{
18
    /**
19
     * Process Doctrine mappings based on gesdinet_jwt_refresh_token.refresh_token_entity config parameter.
20
     * If this parameter contains user-defined entity, RefreshToken will be registered as a mapped superclass, not as an
21
     * entity, to prevent Doctrine creating table for it and avoid conflicts with user-defined entity.
22
     *
23
     * @param ContainerBuilder $container
24
     */
25
    public function process(ContainerBuilder $container)
26
    {
27
        $mappings = array(
28
            realpath(__DIR__.'/../../Resources/config/doctrine-orm') => 'Gesdinet\JWTRefreshTokenBundle\Entity',
29
        );
30
        $config = $container->getExtensionConfig('gesdinet_jwt_refresh_token')[0];
31
        if (isset($config['refresh_token_entity'])) {
32
            $mappings[realpath(__DIR__.'/../../Resources/config/doctrine-superclass')] = 'Gesdinet\JWTRefreshTokenBundle\Entity';
33
        } else {
34
            $mappings[realpath(__DIR__.'/../../Resources/config/doctrine-entity')] = 'Gesdinet\JWTRefreshTokenBundle\Entity';
35
        }
36
37
        $pass = DoctrineOrmMappingsPass::createYamlMappingDriver($mappings);
38
        $pass->process($container);
39
    }
40
}
41