|
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
|
|
|
$filters = $container->findTaggedServiceIds('doctrine.dbal.schema_filter'); |
|
21
|
|
|
|
|
22
|
|
|
if (count($filters) > 0 && !method_exists(\Doctrine\DBAL\Configuration::class, 'setSchemaAssetsFilter')) { |
|
23
|
|
|
throw new \LogicException('The doctrine.dbal.schema_filter tag is only supported when using doctrine/dbal 2.9 or higher.'); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
$connectionFilters = []; |
|
27
|
|
|
foreach ($filters as $id => $tagAttributes) { |
|
28
|
|
|
foreach ($tagAttributes as $attributes) { |
|
29
|
|
|
$name = isset($attributes['connection']) ? $attributes['connection'] : $container->getParameter('doctrine.default_connection'); |
|
30
|
|
|
|
|
31
|
|
|
if (!isset($connectionFilters[$name])) { |
|
32
|
|
|
$connectionFilters[$name] = []; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
$connectionFilters[$name][] = new Reference($id); |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
foreach ($connectionFilters as $name => $references) { |
|
40
|
|
|
$configurationId = sprintf('doctrine.dbal.%s_connection.configuration', $name); |
|
41
|
|
|
|
|
42
|
|
|
if (!$container->hasDefinition($configurationId)) { |
|
43
|
|
|
continue; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$definition = new ChildDefinition('doctrine.dbal.schema_asset_filter_manager'); |
|
47
|
|
|
$definition->setArgument(0, $references); |
|
48
|
|
|
|
|
49
|
|
|
$id = sprintf('doctrine.dbal.%s_schema_asset_filter_manager', $name); |
|
50
|
|
|
$container->setDefinition($id, $definition); |
|
51
|
|
|
$container->findDefinition($configurationId) |
|
52
|
|
|
->addMethodCall('setSchemaAssetsFilter', [new Reference($id)]); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|