8000 Allow AbstractDoctrineExtension implementations to support the newer bundle structure by mbabker · Pull Request #43181 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Allow AbstractDoctrineExtension implementations to support the newer bundle structure #43181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions UPGRADE-5.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ Console

* Deprecate `HelperSet::setCommand()` and `getCommand()` without replacement

DoctrineBridge
--------------

* Add argument `$bundleDir` to `AbstractDoctrineExtension::getMappingDriverBundleConfigDefaults()`
* Add argument `$bundleDir` to `AbstractDoctrineExtension::getMappingResourceConfigDirectory()`

Finder
------

Expand Down
2 changes: 2 additions & 0 deletions UPGRADE-6.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ DoctrineBridge
--------------

* Remove `UserLoaderInterface::loadUserByUsername()` in favor of `UserLoaderInterface::loadUserByIdentifier()`
* Add argument `$bundleDir` to `AbstractDoctrineExtension::getMappingDriverBundleConfigDefaults()`
* Add argument `$bundleDir` to `AbstractDoctrineExtension::getMappingResourceConfigDirectory()`

Cache
-----
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Bridge/Doctrine/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ CHANGELOG
* Add `DoctrineOpenTransactionLoggerMiddleware` to log when a transaction has been left open
* Deprecate `PdoCacheAdapterDoctrineSchemaSubscriber` and add `DoctrineDbalCacheAdapterSchemaSubscriber` instead
* `UniqueEntity` constraint retrieves a maximum of two entities if the default repository method is used.
* Add support for the newer bundle structure to `AbstractDoctrineExtension::loadMappingInformation()`
* Add argument `$bundleDir` to `AbstractDoctrineExtension::getMappingDriverBundleConfigDefaults()`
* Add argument `$bundleDir` to `AbstractDoctrineExtension::getMappingResourceConfigDirectory()`

5.3
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ protected function loadMappingInformation(array $objectManager, ContainerBuilder

if ($mappingConfig['is_bundle']) {
$bundle = null;
$bundleMetadata = null;
foreach ($container->getParameter('kernel.bundles') as $name => $class) {
if ($mappingName === $name) {
$bundle = new \ReflectionClass($class);
$bundleMetadata = $container->getParameter('kernel.bundles_metadata')[$name];

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

$mappingConfig = $this->getMappingDriverBundleConfigDefaults($mappingConfig, $bundle, $container);
$mappingConfig = $this->getMappingDriverBundleConfigDefaults($mappingConfig, $bundle, $container, $bundleMetadata['path']);
if (!$mappingConfig) {
continue;
}
Expand Down Expand Up @@ -133,11 +135,20 @@ protected function setMappingDriverConfig(array $mappingConfig, string $mappingN
*
* Returns false when autodetection failed, an array of the completed information otherwise.
*
* @param string|null $bundleDir The bundle directory path
*
* @return array|false
*/
protected function getMappingDriverBundleConfigDefaults(array $bundleConfig, \ReflectionClass $bundle, ContainerBuilder $container)
protected function getMappingDriverBundleConfigDefaults(array $bundleConfig, \ReflectionClass $bundle, ContainerBuilder $container/*, string $bundleDir = null*/)
{
$bundleDir = \dirname($bundle->getFileName());
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) {
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__);
$bundleDir = null;
} else {
$bundleDir = func_get_arg(3);
}

$bundleDir ?? $bundleDir = \dirname($bundle->getFileName());

if (!$bundleConfig['type']) {
$bundleConfig['type'] = $this->detectMetadataDriver($bundleDir, $container);
Expand All @@ -152,7 +163,7 @@ protected function getMappingDriverBundleConfigDefaults(array $bundleConfig, \Re
if (\in_array($bundleConfig['type'], ['annotation', 'staticphp', 'attribute'])) {
$bundleConfig['dir'] = $bundleDir.'/'.$this->getMappingObjectDefaultName();
} else {
$bundleConfig['dir'] = $bundleDir.'/'.$this->getMappingResourceConfigDirectory();
$bundleConfig['dir'] = $bundleDir.'/'.$this->getMappingResourceConfigDirectory($bundleDir);
}
} else {
$bundleConfig['dir'] = $bundleDir.'/'.$bundleConfig['dir'];
Expand Down Expand Up @@ -246,7 +257,7 @@ protected function assertValidMappingConfiguration(array $mappingConfig, string
*/
protected function detectMetadataDriver(string $dir, ContainerBuilder $container)
{
$configPath = $this->getMappingResourceConfigDirectory();
$configPath = $this->getMappingResourceConfigDirectory($dir);
$extension = $this->getMappingResourceExtension();

if (glob($dir.'/'.$configPath.'/*.'.$extension.'.xml', \GLOB_NOSORT)) {
Expand Down Expand Up @@ -440,9 +451,11 @@ abstract protected function getMappingObjectDefaultName();
/**
* Relative path from the bundle root to the directory where mapping files reside.
*
* @param string|null $bundleDir The bundle directory path
*
* @return string
*/
abstract protected function getMappingResourceConfigDirectory();
abstract protected function getMappingResourceConfigDirectory(/*string $bundleDir = null*/);

/**
* Extension used by the mapping files.
Expand Down
0