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