问题描述
我实际上遇到过几次这个问题,当使用 PHP bin/console make:entity 时,它为存储库中的 ManagerRegistry 使用了错误的命名空间。
这是它放在那里的内容:
use Doctrine\Persistence\ManagerRegistry;
然后出现以下错误:
Cannot autowire service "App\Repository\PrivateCallBookingAvailabilityRepository": argument "$registry" of method "__construct()" has type "Doctrine\Persistence\Manage
rRegistry" but this class was not found.
查看其他存储库并不总是这样做,实际使用的那些:
use Doctrine\Common\Persistence\ManagerRegistry;
知道为什么要这样做吗?
解决方法
您需要降级 symfony/maker-bundle
的版本,因为 Doctrine\Common\Persistence\ManagerRegistry
在 Doctrine 中被重命名为 Doctrine\Persistence\ManagerRegistry
,并且看起来您的 Doctrine 版本具有此类的旧名称。
您也可以选择将 Doctrine 更新到最新版本。
您可以在此处找到更多详细信息https://github.com/symfony/maker-bundle/pull/518。