Skip to content

Commit a912c52

Browse files
Merge branch '5.4' into 6.0
* 5.4: (22 commits) fix cs Update validators.lv.xlf Fix API gateway service name Improve recommendation message for "composer req" Fix CS in composer.json [DependencyInjection] fix preloading Update validators.uz.xlf AddMake ExpressionVoter Cacheable Add framework config for DBAL cache adapter [ExpressionLanguage] Fix LexerTest number types [Process] intersect with getenv() to populate default envs Improve CI script a bit Fix deprecation message placeholders [Cache] Fix calculate ttl in couchbase sdk 3.0 Fix Loco Provider [Cache] fix dbindex Redis Fix typos in a test message [Cache] fix releasing not acquired locks [DependencyInjection] fix creating 2nd container instances Never rely on dynamic properties ...
2 parents 635269d + e294c53 commit a912c52

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ CHANGELOG
1212
* Add `DoctrineOpenTransactionLoggerMiddleware` to log when a transaction has been left open
1313
* Deprecate `PdoCacheAdapterDoctrineSchemaSubscriber` and add `DoctrineDbalCacheAdapterSchemaSubscriber` instead
1414
* `UniqueEntity` constraint retrieves a maximum of two entities if the default repository method is used.
15+
* Add support for the newer bundle structure to `AbstractDoctrineExtension::loadMappingInformation()`
16+
* Add argument `$bundleDir` to `AbstractDoctrineExtension::getMappingDriverBundleConfigDefaults()`
17+
* Add argument `$bundleDir` to `AbstractDoctrineExtension::getMappingResourceConfigDirectory()`
1518

1619
5.3
1720
---

DependencyInjection/AbstractDoctrineExtension.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,11 @@ protected function loadMappingInformation(array $objectManager, ContainerBuilder
7373

7474
if ($mappingConfig['is_bundle']) {
7575
$bundle = null;
76+
$bundleMetadata = null;
7677
foreach ($container->getParameter('kernel.bundles') as $name => $class) {
7778
if ($mappingName === $name) {
7879
$bundle = new \ReflectionClass($class);
80+
$bundleMetadata = $container->getParameter('kernel.bundles_metadata')[$name];
7981

8082
break;
8183
}
@@ -85,7 +87,7 @@ protected function loadMappingInformation(array $objectManager, ContainerBuilder
8587
throw new \InvalidArgumentException(sprintf('Bundle "%s" does not exist or it is not enabled.', $mappingName));
8688
}
8789

88-
$mappingConfig = $this->getMappingDriverBundleConfigDefaults($mappingConfig, $bundle, $container);
90+
$mappingConfig = $this->getMappingDriverBundleConfigDefaults($mappingConfig, $bundle, $container, $bundleMetadata['path']);
8991
if (!$mappingConfig) {
9092
continue;
9193
}
@@ -135,9 +137,9 @@ protected function setMappingDriverConfig(array $mappingConfig, string $mappingN
135137
*
136138
* @return array|false
137139
*/
138-
protected function getMappingDriverBundleConfigDefaults(array $bundleConfig, \ReflectionClass $bundle, ContainerBuilder $container): array|false
140+
protected function getMappingDriverBundleConfigDefaults(array $bundleConfig, \ReflectionClass $bundle, ContainerBuilder $container, string $bundleDir = null): array|false
139141
{
140-
$bundleDir = \dirname($bundle->getFileName());
142+
$bundleDir ??= \dirname($bundle->getFileName());
141143

142144
if (!$bundleConfig['type']) {
143145
$bundleConfig['type'] = $this->detectMetadataDriver($bundleDir, $container);
@@ -152,7 +154,7 @@ protected function getMappingDriverBundleConfigDefaults(array $bundleConfig, \Re
152154
if (\in_array($bundleConfig['type'], ['annotation', 'staticphp', 'attribute'])) {
153155
$bundleConfig['dir'] = $bundleDir.'/'.$this->getMappingObjectDefaultName();
154156
} else {
155-
$bundleConfig['dir'] = $bundleDir.'/'.$this->getMappingResourceConfigDirectory();
157+
$bundleConfig['dir'] = $bundleDir.'/'.$this->getMappingResourceConfigDirectory($bundleDir);
156158
}
157159
} else {
158160
$bundleConfig['dir'] = $bundleDir.'/'.$bundleConfig['dir'];
@@ -244,7 +246,7 @@ protected function assertValidMappingConfiguration(array $mappingConfig, string
244246
*/
245247
protected function detectMetadataDriver(string $dir, ContainerBuilder $container): ?string
246248
{
247-
$configPath = $this->getMappingResourceConfigDirectory();
249+
$configPath = $this->getMappingResourceConfigDirectory($dir);
248250
$extension = $this->getMappingResourceExtension();
249251

250252
if (glob($dir.'/'.$configPath.'/*.'.$extension.'.xml', \GLOB_NOSORT)) {
@@ -426,7 +428,7 @@ abstract protected function getMappingObjectDefaultName(): string;
426428
/**
427429
* Relative path from the bundle root to the directory where mapping files reside.
428430
*/
429-
abstract protected function getMappingResourceConfigDirectory(): string;
431+
abstract protected function getMappingResourceConfigDirectory(string $bundleDir = null): string;
430432

431433
/**
432434
* Extension used by the mapping files.

SchemaListener/DoctrineDbalCacheAdapterSchemaSubscriber.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Doctrine\Common\EventSubscriber;
1515
use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs;
1616
use Doctrine\ORM\Tools\ToolEvents;
17-
use Symfony\Component\Cache\Adapter\DoctrineSchemaConfiguratorInterface;
17+
use Symfony\Component\Cache\Adapter\DoctrineDbalAdapter;
1818

1919
/**
2020
* Automatically adds the cache table needed for the DoctrineDbalAdapter of
@@ -27,7 +27,7 @@ final class DoctrineDbalCacheAdapterSchemaSubscriber implements EventSubscriber
2727
private $dbalAdapters;
2828

2929
/**
30-
* @param iterable<mixed, DoctrineSchemaConfiguratorInterface> $dbalAdapters
30+
* @param iterable<mixed, DoctrineDbalAdapter> $dbalAdapters
3131
*/
3232
public function __construct(iterable $dbalAdapters)
3333
{

Tests/SchemaListener/DoctrineDbalCacheAdapterSchemaSubscriberTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs;
1818
use PHPUnit\Framework\TestCase;
1919
use Symfony\Bridge\Doctrine\SchemaListener\DoctrineDbalCacheAdapterSchemaSubscriber;
20-
use Symfony\Component\Cache\Adapter\DoctrineSchemaConfiguratorInterface;
20+
use Symfony\Component\Cache\Adapter\DoctrineDbalAdapter;
2121

2222
class DoctrineDbalCacheAdapterSchemaSubscriberTest extends TestCase
2323
{
@@ -29,14 +29,15 @@ public function testPostGenerateSchema()
2929
$entityManager->expects($this->once())
3030
->method('getConnection')
3131
->willReturn($dbalConnection);
32+
3233
$event = new GenerateSchemaEventArgs($entityManager, $schema);
3334

34-
$pdoAdapter = $this->createMock(DoctrineSchemaConfiguratorInterface::class);
35-
$pdoAdapter->expects($this->once())
35+
$dbalAdapter = $this->createMock(DoctrineDbalAdapter::class);
36+
$dbalAdapter->expects($this->once())
3637
->method('configureSchema')
3738
->with($schema, $dbalConnection);
3839

39-
$subscriber = new DoctrineDbalCacheAdapterSchemaSubscriber([$pdoAdapter]);
40+
$subscriber = new DoctrineDbalCacheAdapterSchemaSubscriber([$dbalAdapter]);
4041
$subscriber->postGenerateSchema($event);
4142
}
4243
}

0 commit comments

Comments
 (0)