1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Cache\Adapter\PdoAdapter; |
6
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
7
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
8
|
|
|
use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler; |
9
|
|
|
use Symfony\Component\Lock\Store\PdoStore; |
10
|
|
|
use Symfony\Component\Messenger\Bridge\Doctrine\Transport\Connection; |
11
|
|
|
use Symfony\Component\Messenger\Transport\Doctrine\Connection as LegacyConnection; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Blacklist tables used by well-known Symfony classes. |
15
|
|
|
*/ |
16
|
|
|
class WellKnownSchemaFilterPass implements CompilerPassInterface |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* {@inheritDoc} |
20
|
|
|
*/ |
21
|
|
|
public function process(ContainerBuilder $container) |
22
|
|
|
{ |
23
|
|
|
$blacklist = []; |
24
|
|
|
|
25
|
|
|
foreach ($container->getDefinitions() as $definition) { |
26
|
|
|
if ($definition->isAbstract() || $definition->isSynthetic()) { |
27
|
|
|
continue; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
switch ($definition->getClass()) { |
31
|
|
|
case PdoAdapter::class: |
32
|
|
|
$blacklist[] = $definition->getArguments()[3]['db_table'] ?? 'cache_items'; |
33
|
|
|
break; |
34
|
|
|
|
35
|
|
|
case PdoSessionHandler::class: |
36
|
|
|
$blacklist[] = $definition->getArguments()[1]['db_table'] ?? 'sessions'; |
37
|
|
|
break; |
38
|
|
|
|
39
|
|
|
case PdoStore::class: |
40
|
|
|
$blacklist[] = $definition->getArguments()[1]['db_table'] ?? 'lock_keys'; |
41
|
|
|
break; |
42
|
|
|
|
43
|
|
|
case LegacyConnection::class: |
44
|
|
|
case Connection::class: |
45
|
|
|
// add the blacklist *unless* the new schema subscriber service exists |
46
|
|
|
if (!$container->getDefinition('doctrine.orm.messenger.doctrine_schema_subscriber')) { |
47
|
|
|
$blacklist[] = $definition->getArguments()[0]['table_name'] ?? 'messenger_messages'; |
48
|
|
|
} |
49
|
|
|
break; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
if (! $blacklist) { |
|
|
|
|
54
|
|
|
return; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$definition = $container->getDefinition('doctrine.dbal.well_known_schema_asset_filter'); |
58
|
|
|
$definition->replaceArgument(0, $blacklist); |
59
|
|
|
|
60
|
|
|
foreach (array_keys($container->getParameter('doctrine.connections')) as $name) { |
61
|
|
|
$definition->addTag('doctrine.dbal.schema_filter', ['connection' => $name]); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.