1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Configuration; |
6
|
|
|
use Symfony\Component\Cache\Adapter\PdoAdapter; |
7
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
8
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
9
|
|
|
use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler; |
10
|
|
|
use Symfony\Component\Lock\Store\PdoStore; |
11
|
|
|
use Symfony\Component\Messenger\Transport\Doctrine\Connection; |
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
|
|
|
if (! method_exists(Configuration::class, 'setSchemaAssetsFilter')) { |
24
|
|
|
// only supported when using doctrine/dbal 2.9 or higher |
25
|
|
|
return; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
$blacklist = []; |
29
|
|
|
|
30
|
|
|
foreach ($container->getDefinitions() as $definition) { |
31
|
|
|
if ($definition->isAbstract() || $definition->isSynthetic()) { |
32
|
|
|
continue; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
switch ($definition->getClass()) { |
36
|
|
|
case PdoAdapter::class: |
37
|
|
|
$blacklist[] = $definition->getArguments()[3]['db_table'] ?? 'cache_items'; |
38
|
|
|
break; |
39
|
|
|
|
40
|
|
|
case PdoSessionHandler::class: |
41
|
|
|
$blacklist[] = $definition->getArguments()[1]['db_table'] ?? 'lock_keys'; |
42
|
|
|
break; |
43
|
|
|
|
44
|
|
|
case PdoStore::class: |
45
|
|
|
$blacklist[] = $definition->getArguments()[1]['db_table'] ?? 'sessions'; |
46
|
|
|
break; |
47
|
|
|
|
48
|
|
|
case Connection::class: |
49
|
|
|
$blacklist[] = $definition->getArguments()[0]['table_name'] ?? 'messenger_messages'; |
50
|
|
|
break; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
if (! $blacklist) { |
|
|
|
|
55
|
|
|
return; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$definition = $container->getDefinition('doctrine.dbal.well_known_schema_asset_filter'); |
59
|
|
|
$definition->replaceArgument(0, $blacklist); |
60
|
|
|
|
61
|
|
|
foreach (array_keys($container->getParameter('doctrine.connections')) as $name) { |
62
|
|
|
$definition->addTag('doctrine.dbal.schema_filter', ['connection' => $name]); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
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.