/
WellKnownSchemaFilterPass.php
61 lines (50 loc) · 2.11 KB
/
WellKnownSchemaFilterPass.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
namespace Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler;
use Symfony\Component\Cache\Adapter\PdoAdapter;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler;
use Symfony\Component\Lock\Store\PdoStore;
use Symfony\Component\Messenger\Bridge\Doctrine\Transport\Connection;
use Symfony\Component\Messenger\Transport\Doctrine\Connection as LegacyConnection;
/**
* Blacklist tables used by well-known Symfony classes.
*/
class WellKnownSchemaFilterPass implements CompilerPassInterface
{
/**
* {@inheritDoc}
*/
public function process(ContainerBuilder $container)
{
$blacklist = [];
foreach ($container->getDefinitions() as $definition) {
if ($definition->isAbstract() || $definition->isSynthetic()) {
continue;
}
switch ($definition->getClass()) {
case PdoAdapter::class:
$blacklist[] = $definition->getArguments()[3]['db_table'] ?? 'cache_items';
break;
case PdoSessionHandler::class:
$blacklist[] = $definition->getArguments()[1]['db_table'] ?? 'sessions';
break;
case PdoStore::class:
$blacklist[] = $definition->getArguments()[1]['db_table'] ?? 'lock_keys';
break;
case LegacyConnection::class:
case Connection::class:
$blacklist[] = $definition->getArguments()[0]['table_name'] ?? 'messenger_messages';
break;
}
}
if (! $blacklist) {
return;
}
$definition = $container->getDefinition('doctrine.dbal.well_known_schema_asset_filter');
$definition->replaceArgument(0, $blacklist);
foreach (array_keys($container->getParameter('doctrine.connections')) as $name) {
$definition->addTag('doctrine.dbal.schema_filter', ['connection' => $name]);
}
}
}