symfony / orm-pack

A Symfony Pack for Doctrine ORM
MIT License
1.82k stars 18 forks source link

DoctrineBundle is not registered in your application #21

Closed rask closed 3 years ago

rask commented 4 years ago

I ran into this issue today when I upgraded one of our Symfony 4.2 applications to run on PHP 7.4 and updated dependencies accordingly.

In the composer.json we have symfony/orm-pack installed, which installs doctrine/doctrine-bundle properly at version 1.12.* or so.

We also have DoctrineBundle defined in config/bundles.php properly.

Otherwise the application worked OK in PHP 7.4 and new dependencies, but I noticed that one of our controllers was throwing errors that displayed:

DoctrineBundle is not registered in your application

After digging, I noticed that the bundle was in fact registered when running console debug:container. ManagerRegistry instances were properly injected when passed in as constructor parameters, so it seemed to work.

What was different with the failing controller, was that it used $this->getDoctrine() instead of injecting a ManagerRegistry. The controller extends Symfony's AbstractController.

The problem went away when I swapped the getDoctrine() call to be a ManagerRegistry injection instead.

I do think that this has something to do with a relatively stale Symfony 4.2 being in use, but wanted to post this issue to

  1. Have a reference available in case someone else runs into a similar issue,
  2. Let you know in case this might be an actual fixable bug in later Symfony versions as well.
martinlillemets commented 4 years ago

I encountered the same problem with symfony = 4.4.8 and orm-pack =1.0.8 versions. orm-pack has internal doctrine/doctrine-bundle dependency which resolved at version 1.11.2

I managed to solve the problem by adding the following doctrine-bundle dependency to composer.json "doctrine/doctrine-bundle": "^1.12"

nicolas-grekas commented 3 years ago

This should be fixed now.