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

Issue with StaticPHPDriver namespace since doctrine/orm 2.3 (breaks since 3.0) #1793

Closed
clementvtrd opened this issue Apr 16, 2024 · 1 comment

Comments

@clementvtrd
Copy link

Context

I'm trying to setup a static php mapping with the following configuration (truncate with unrelated configuration):

doctrine:
    dbal:
    orm:
        mappings:
            Model:
                type: staticphp
                is_bundle: false
                dir: '%kernel.project_dir%/src/Infrastructure/Doctrine/Entity'
                prefix: 'Infrastructure\Doctrine\Entity'

My entity has a loadMetadata method and all should be fine.

Error

However, if I try to run any command that use the default entity manager service, I got the following error:

Symfony\Component\ErrorHandler\Error\ClassNotFoundError^ {#4743
  #message: """
    Attempted to load class "StaticPHPDriver" from namespace "Doctrine\ORM\Mapping\Driver".\n
    Did you forget a "use" statement for "Doctrine\Persistence\Mapping\Driver\StaticPHPDriver"?
    """
  #code: 0
  #file: "./var/cache/dev/ContainerJ7M0HEC/getDoctrine_Orm_DefaultEntityManagerService.php"
  #line: 52

Issue

Digging dipper and it appear that the generated class has this line:

$b->addDriver(new \Doctrine\ORM\Mapping\Driver\StaticPHPDriver([(\dirname(__DIR__, 4).'/src/Infrastructure/Doctrine/Entity')]), 'Infrastructure\\Doctrine\\Entity');

The class \Doctrine\ORM\Mapping\Driver\StaticPHPDriver has been removed from doctrine/orm since v3.0 and deprecated since v2.3.

But the corrected line would be (I guess):

$b->addDriver(new \Doctrine\Persistence\Mapping\Driver\StaticPHPDriver([(\dirname(__DIR__, 4).'/src/Infrastructure/Doctrine/Entity')]), 'Infrastructure\\Doctrine\\Entity');

I tried to patch the generated class and run, for example, doctrine:schema:update --dump-sql and it works.

Proposal

My suggestion would be to patch the file config/orm.xml and replace the value of parameter with key doctrine.orm.metadata.staticphp.class with \Doctrine\Persistence\Mapping\Driver\StaticPHPDriver.

@ostrolucky
Copy link
Member

This is not an issue with doctrine-bundle but doctrine-bridge, explained here #1755 (comment)

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

No branches or pull requests

2 participants