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
|
|
|
|