|
21 | 21 | use TheCodingMachine\TDBM\Utils\DefaultNamingStrategy;
|
22 | 22 | use TheCodingMachine\TDBM\Utils\NamingStrategyInterface;
|
23 | 23 | use TheCodingMachine\TDBM\SchemaLockFileDumper;
|
| 24 | +use TheCodingMachine\TDBM\Utils\RootProjectLocator; |
| 25 | +use function strlen; |
| 26 | +use function substr; |
24 | 27 |
|
25 | 28 | class TdbmExtension extends Extension
|
26 | 29 | {
|
@@ -66,7 +69,7 @@ private function nD(string $class = null, array $arguments = []): Definition
|
66 | 69 | $definition->setAutowired(true);
|
67 | 70 | $definition->setAutoconfigured(true);
|
68 | 71 | $definition->setPublic(false);
|
69 |
| - |
| 72 | + |
70 | 73 | return $definition;
|
71 | 74 | }
|
72 | 75 |
|
@@ -104,6 +107,22 @@ private function getConfigurationDefinition(ConnectionConfiguration $config, str
|
104 | 107 | $configuration->setArgument('$namingStrategy', new Reference($namingStrategyServiceId));
|
105 | 108 | $configuration->setArgument('$codeGeneratorListeners', [new Reference(SymfonyCodeGeneratorListener::class)]);
|
106 | 109 | $configuration->setArgument('$cache', new Reference('tdbm.cache'));
|
| 110 | + |
| 111 | + // Let's name the tdbm lock file after the name of the DBAL connection. |
| 112 | + |
| 113 | + // A DBAL connection is in the form: "doctrine.dbal.default_connection" |
| 114 | + $connectionName = $config->getConnection(); |
| 115 | + if (strpos($connectionName, 'doctrine.dbal.') === 0) { |
| 116 | + $connectionName = substr($connectionName, 14); |
| 117 | + if (strpos($connectionName, '_connection') === strlen($connectionName) - 11) { |
| 118 | + $connectionName = substr($connectionName, 0, strlen($connectionName) - 11); |
| 119 | + } |
| 120 | + } |
| 121 | + |
| 122 | + if ($connectionName !== 'default') { |
| 123 | + $configuration->setArgument('$lockFilePath', RootProjectLocator::getRootLocationPath().'tdbm.'.$connectionName.'.lock.yml'); |
| 124 | + } |
| 125 | + |
107 | 126 | return $configuration;
|
108 | 127 | }
|
109 | 128 |
|
|
0 commit comments