Skip to content
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

Exception when using DoctrineOrmMappingsPass::createAttributeMappingDriver together with doctrine/orm > v3 #1844

Open
uerka opened this issue Dec 3, 2024 · 1 comment

Comments

@uerka
Copy link

uerka commented Dec 3, 2024

Bug Report

Not sure if i should put it here or into doctrine/orm as it seems like compatibility problem.

Q A
doctrine\doctrine-bundle 2.13.1
doctrine\orm 3.3.0

Summary

We have a private bundle, that we're reusing on multiple projects. This bundle provides some entities with mapping. Within this bundle we're calling DoctrineOrmMappingsPass to register bundle's entities mapping:

$container->addCompilerPass(DoctrineOrmMappingsPass::createAttributeMappingDriver($namespaces, $directories));

Current behavior

Currently app crashes hard with \InvalidArgumentException

The $reportFieldsWhereDeclared argument is no longer supported, make sure to omit it when calling Doctrine\ORM\Mapping\Driver\AttributeDriver::__construct.

Expected behavior

It probably should not crash)
As soon as its going to be omitted by doctrine\orm we would like to avoid pass reportFieldsWhereDeclared from bundle.

How to reproduce

Its quite simple:

  1. doctrine/orm version > 3
  2. latest doctrine/doctrine-bundle
  3. call DoctrineOrmMappingsPass to add mapping by attributes - for example like following:
namespace My\CustomBundle;

use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

class MyCustomBundle extends Bundle
{
    public function build(ContainerBuilder $container): void
    {
        $namespaces = [
            'My\CustomBundle\Model',
        ];

        $directories = [
            __DIR__ . '/src/Model',
        ];
        
        $container->addCompilerPass(DoctrineOrmMappingsPass::createAttributeMappingDriver($namespaces, $directories));
     }
}
@greg0ire
Copy link
Member

greg0ire commented Dec 3, 2024

I believe the offending piece of code is here:

$driver = new Definition(AnnotationDriver::class, [$reader, $directories, $reportFieldsWhereDeclared]);

It should be possible to detect ORM 3 and omit that argument based when relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants