Closed fpolli closed 1 year ago
Have you verified that DoctrineServiceProvider::register()
is actually called? If you have cached your config then changing the array wont have any effect :)
you could disable auto discover for laravel-doctrine/orm
in composer.json
then add DoctrineServiceProvider::class
into app.php
providers
before AppServiceProvider
you could disable auto discover for
laravel-doctrine/orm
incomposer.json
then addDoctrineServiceProvider::class
intoapp.php
providers
beforeAppServiceProvider
Do I need to disable auto discover? I added DSP into app.php before ASP manually, but have not modified composer.json.
Have you verified that
DoctrineServiceProvider::register()
is actually called? If you have cached your config then changing the array wont have any effect :)
I had cached the config. I ran php artisan config:cache to reload cache with my changes, same error, then ran php artisan cache:clear and tried again, same error. Class not found/cannot instantiate.
I did try adding "use LaravelDoctrine\ORM\Facades\Registry;" to the top of my service class then use Registry::getManager instead of trying to instantiate the ManagerRegistry, and that worked. I can fly the plane with the wing duct taped, but I'd like to know what I did wrong anyway so I can actually fix it.
Thanks for your help.
Setting a breakpoint in DoctrineServiceProvider::registerManagerRegistry() might give you some clue.
Thanks
Actually, can I reopen this to ask a couple more questions in aid of increasing my understanding? I do appreciate your time.
Why would using the Facade work when instantiating the underlying class did not work because the class was "not found"?
And if in my service I am instantiating the registry class when I run the service method rather than in the service class constructor, does the order the service providers are called matter? At the time I attempt to actually run the code instantiating the registry class, all the providers have run.
The "Not found" class might be related to the deprecation of the Common
namespace. That namespace should no longer be used and the actual fqdn is Doctrine\Persistence\ManagerRegistry
(as you found out).
Personally, this sort of issues is easier to investigate with xdebug as you can see at specific breakpoint what the container contains. I would recommend to set a breakpoint in the constructor of the exception thrown then look at the stacktrace and figure out in what order things are called.
Please prefix your issue with one of the following: [BUG] [PROPOSAL] [QUESTION].
Package version, Laravel version
LD 1.8, Laravel 9.52
In a service that I register in AppServiceProvider, I attempt to instantiate ManagerRegistry to load an alternate connection (I need multiple connections).
I get one of two errors... First I had "use Doctrine\Common\Persistence\ManagerRegistry" at the top of my class, and I get the error "Class "Doctrine\Common\Persistence\ManagerRegistry" not found"
A little investigating in the vendor/doctrine folder structure led me to try "use Doctrine\Persistence..." and I get the error "Cannot instantiate interface Doctrine\Persistence\ManagerRegistry"
In searching the issues here I saw a comment to make sure you don't try to use ManagerRegistry in a service provider before DoctrineServiceProvider. I looked in my config/app.php file and did not see that provider in the list (I followed the advice of the installation docs and relied on Laravel automatic package detection which has worked for me with other package installs), so I tried manually adding it per the installation documentation here, above the AppServiceProvider. That made no change.
I don't really know what other information you will need, so please ask and I will provide ASAP.
Thank you