Skip to content

Commit 8f0a96b

Browse files
committed
[DoctrineBridge] Allow AbstractDoctrineExtension implementations to support the newer bundle structure
1 parent 4c0d8d1 commit 8f0a96b

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

CHANGELOG.md

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

1114
5.3
1215
---

DependencyInjection/AbstractDoctrineExtension.php

Lines changed: 19 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
}
@@ -133,11 +135,20 @@ protected function setMappingDriverConfig(array $mappingConfig, string $mappingN
133135
*
134136
* Returns false when autodetection failed, an array of the completed information otherwise.
135137
*
138+
* @param string|null $bundleDir The bundle directory path
139+
*
136140
* @return array|false
137141
*/
138-
protected function getMappingDriverBundleConfigDefaults(array $bundleConfig, \ReflectionClass $bundle, ContainerBuilder $container)
142+
protected function getMappingDriverBundleConfigDefaults(array $bundleConfig, \ReflectionClass $bundle, ContainerBuilder $container/*, string $bundleDir = null*/)
139143
{
140-
$bundleDir = \dirname($bundle->getFileName());
144+
if (\func_num_args() < 4 && __CLASS__ !== static::class && __CLASS__ !== (new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface && !$this instanceof \Mockery\MockInterface) {
145+
trigger_deprecation('symfony/doctrine-bridge', '5.4', 'The "%s()" method will have a new "string $bundleDir = null" argument in version 6.0, not defining it is deprecated.', __METHOD__);
146+
$bundleDir = null;
147+
} else {
148+
$bundleDir = func_get_arg(3);
149+
}
150+
151+
$bundleDir ?? $bundleDir = \dirname($bundle->getFileName());
141152

142153
if (!$bundleConfig['type']) {
143154
$bundleConfig['type'] = $this->detectMetadataDriver($bundleDir, $container);
@@ -152,7 +163,7 @@ protected function getMappingDriverBundleConfigDefaults(array $bundleConfig, \Re
152163
if (\in_array($bundleConfig['type'], ['annotation', 'staticphp', 'attribute'])) {
153164
$bundleConfig['dir'] = $bundleDir.'/'.$this->getMappingObjectDefaultName();
154165
} else {
155-
$bundleConfig['dir'] = $bundleDir.'/'.$this->getMappingResourceConfigDirectory();
166+
$bundleConfig['dir'] = $bundleDir.'/'.$this->getMappingResourceConfigDirectory($bundleDir);
156167
}
157168
} else {
158169
$bundleConfig['dir'] = $bundleDir.'/'.$bundleConfig['dir'];
@@ -246,7 +257,7 @@ protected function assertValidMappingConfiguration(array $mappingConfig, string
246257
*/
247258
protected function detectMetadataDriver(string $dir, ContainerBuilder $container)
248259
{
249-
$configPath = $this->getMappingResourceConfigDirectory();
260+
$configPath = $this->getMappingResourceConfigDirectory($dir);
250261
$extension = $this->getMappingResourceExtension();
251262

252263
if (glob($dir.'/'.$configPath.'/*.'.$extension.'.xml', \GLOB_NOSORT)) {
@@ -440,9 +451,11 @@ abstract protected function getMappingObjectDefaultName();
440451
/**
441452
* Relative path from the bundle root to the directory where mapping files reside.
442453
*
454+
* @param string|null $bundleDir The bundle directory path
455+
*
443456
* @return string
444457
*/
445-
abstract protected function getMappingResourceConfigDirectory();
458+
abstract protected function getMappingResourceConfigDirectory(/*string $bundleDir = null*/);
446459

447460
/**
448461
* Extension used by the mapping files.

0 commit comments

Comments
 (0)