1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\DependencyInjection\ChildDefinition; |
6
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
7
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
8
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Processes the doctrine.dbal.schema_filter |
12
|
|
|
*/ |
13
|
|
|
class DbalSchemaFilterPass implements CompilerPassInterface |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* {@inheritDoc} |
17
|
|
|
*/ |
18
|
|
|
public function process(ContainerBuilder $container) |
19
|
|
|
{ |
20
|
|
|
// feature require doctrine/dbal 2.9 or higher |
21
|
|
|
if (!method_exists(\Doctrine\DBAL\Configuration::class, 'setSchemaAssetsFilter')) { |
22
|
|
|
return; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
$filters = $container->findTaggedServiceIds('doctrine.dbal.schema_filter'); |
26
|
|
|
|
27
|
|
|
$connectionFilters = []; |
28
|
|
|
foreach ($filters as $id => $tagAttributes) { |
29
|
|
|
foreach ($tagAttributes as $attributes) { |
30
|
|
|
$name = isset($attributes['connection']) ? $attributes['connection'] : $container->getParameter('doctrine.default_connection'); |
31
|
|
|
|
32
|
|
|
if (!isset($connectionFilters[$name])) { |
33
|
|
|
$connectionFilters[$name] = []; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
$connectionFilters[$name][] = new Reference($id); |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
foreach ($connectionFilters as $name => $references) { |
41
|
|
|
$configurationId = sprintf('doctrine.dbal.%s_connection.configuration', $name); |
42
|
|
|
|
43
|
|
|
if (!$container->hasDefinition($configurationId)) { |
44
|
|
|
continue; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$definition = new ChildDefinition('doctrine.dbal.schema_asset_filter_manager'); |
48
|
|
|
$definition->setArgument(0, $references); |
49
|
|
|
|
50
|
|
|
$id = sprintf('doctrine.dbal.%s_schema_asset_filter_manager', $name); |
51
|
|
|
$container->setDefinition($id, $definition); |
52
|
|
|
$container->findDefinition($configurationId) |
53
|
|
|
->addMethodCall('setSchemaAssetsFilter', [new Reference($id)]); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|