[英]Argument 1 passed to DoctrineDataCollector::__construct() must be an instance of Doctrine\Common\Persistence\ManagerRegistry
I am developing a Symfony project which somebody else started on and I was happy that I had it up and running.我正在开发一个其他人开始的 Symfony 项目,我很高兴我能够启动并运行它。 Unfortunatelly after running
composer update
today, the Symfony page that I have throws an error.不幸的是,今天运行
composer update
后,我的 Symfony 页面抛出错误。
After running composer update the following error was displayed:运行 composer update 后显示以下错误:
Composer update error
作曲家更新错误
Executing script cache:clear [KO]
[KO]
Script cache:clear returned with error code 255
!! Symfony\Component\ErrorHandler\Error\ClassNotFoundError {#132
!! #message: """
!! Attempted to load class "MappingDriverChain" from namespace "Doctrine\Common\Persistence\Mapping\Driver".\n
!! Did you forget a "use" statement for "Doctrine\Persistence\Mapping\Driver\MappingDriverChain"?
!! """
!! #code: 0
!! #file: "./var/cache/dev/ContainerFcUQG2T/App_KernelDevDebugContainer.php"
!! #line: 869
!! trace: {
!! ./var/cache/dev/ContainerFcUQG2T/App_KernelDevDebugContainer.php:869 {
!! ContainerFcUQG2T\App_KernelDevDebugContainer->getDoctrine_Orm_DefaultEntityManagerService($lazyLoad = true)
!! ›
!! › $b = new \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain();
!! › $b->addDriver(new \Doctrine\ORM\Mapping\Driver\AnnotationDriver(($this->privates['annotations.cached_reader'] ?? $this->getAnnotations_CachedReaderService()), [0 => (\dirname(__DIR__, 4).'/src/Entity')]), 'App\\Entity');
!! }
!! ./var/cache/dev/ContainerFcUQG2T/App_KernelDevDebugContainer.php:5160 { …}
!! ./var/cache/dev/ContainerFcUQG2T/App_KernelDevDebugContainer.php:5204 { …}
!! ./var/cache/dev/ContainerFcUQG2T/App_KernelDevDebugContainer.php:569 { …}
!! ./vendor/symfony/http-kernel/CacheWarmer/CacheWarmerAggregate.php:87 { …}
!! ./vendor/symfony/http-kernel/Kernel.php:553 { …}
!! ./vendor/symfony/http-kernel/Kernel.php:126 { …}
!! ./vendor/symfony/framework-bundle/Console/Application.php:168 { …}
!! ./vendor/symfony/framework-bundle/Console/Application.php:74 { …}
!! ./vendor/symfony/console/Application.php:140 { …}
!! ./bin/console:42 { …}
!! }
!! }
!! 2020-07-31T08:18:05+00:00 [critical] Uncaught Error: Class 'Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain' not found
!!
After accessing the Symfony page, this TypeError was printed:访问 Symfony 页面后,打印了此 TypeError:
TypeError类型错误
Argument 1 passed to Doctrine\Bundle\DoctrineBundle\DataCollector\DoctrineDataCollector::__construct() must be an instance of Doctrine\Common\Persistence\ManagerRegistry, instance of Doctrine\Bundle\DoctrineBundle\Registry given, called in /var/www/html/mgo/var/cache/dev/ContainerFcUQG2T/App_KernelDevDebugContainer.php on line 1176
传递给 Doctrine\Bundle\DoctrineBundle\DataCollector\DoctrineDataCollector::__construct() 的参数 1 必须是 Doctrine\Common\Persistence\ManagerRegistry 的实例,给定的 Doctrine\Bundle\DoctrineBundle\Registry 实例,在 /var/www/html 中调用/mgo/var/cache/dev/ContainerFcUQG2T/App_KernelDevDebugContainer.php 1176行
To be honest I have no idea what caused this issue, but I think it has nothing to do with the changes I made in the twig
and Symfony php
files of the project.老实说,我不知道是什么导致了这个问题,但我认为这与我在项目的
twig
和 Symfony php
文件中所做的更改无关。
I'll add some files, if there is anything else that I should be looking into, let me know.我会添加一些文件,如果还有其他需要查看的内容,请告诉我。
/config/packages/doctrine.yaml
/config/packages/doctrine.yaml
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'
# IMPORTANT: You MUST configure your server version,
# either here or in the DATABASE_URL env var (see .env file)
#server_version: '5.7'
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
composer.json
作曲家.json
{
"name": "project",
"description": "project description",
"type": "path",
"license": "MIT",
"minimum-stability": "dev",
"require": {
"php": "^7.4",
"ext-ctype": "*",
"ext-iconv": "*",
"mgo/mgo-client-php": "2.0.0",
"sensio/framework-extra-bundle": "^5.1",
"symfony/asset": "5.0.*",
"symfony/console": "5.0.*",
"symfony/dotenv": "5.0.*",
"symfony/expression-language": "5.0.*",
"symfony/flex": "^1.3.1",
"symfony/form": "5.0.*",
"symfony/framework-bundle": "5.0.*",
"symfony/http-client": "5.0.*",
"symfony/intl": "5.0.*",
"symfony/mailer": "5.0.*",
"symfony/monolog-bundle": "^3.1",
"symfony/notifier": "5.0.*",
"symfony/orm-pack": "*",
"symfony/process": "5.0.*",
"symfony/security-bundle": "5.0.*",
"symfony/serializer-pack": "*",
"symfony/string": "5.0.*",
"symfony/translation": "5.0.*",
"symfony/twig-pack": "*",
"symfony/validator": "5.0.*",
"symfony/web-link": "5.0.*",
"symfony/yaml": "5.0.*",
"ext-json": "*"
},
"repositories": [
{
"type": "path",
"url": "/home/*user*/mgo-client-php",
"symlink": false
}
],
"require-dev": {
"symfony/debug-pack": "*",
"symfony/maker-bundle": "^1.0",
"symfony/profiler-pack": "*",
"symfony/test-pack": "*",
"mgo-client-php": "2.0.0",
"monolog/monolog": "^1.23"
},
"config": {
"preferred-install": {
"*": "dist"
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"replace": {
"paragonie/random_compat": "2.*",
"symfony/polyfill-ctype": "*",
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php72": "*",
"symfony/polyfill-php71": "*",
"symfony/polyfill-php70": "*",
"symfony/polyfill-php56": "*"
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"@auto-scripts"
],
"post-update-cmd": [
"@auto-scripts"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"allow-contrib": false,
"require": "5.0.*"
}
}
}
EDIT:编辑:
As @Alexandre Tranchant suggested I removed my /var/cache
file to get the original error.正如@Alexandre Tranchant 建议的那样,我删除了我的
/var/cache
文件以获取原始错误。 The error that pops up is the following:弹出的错误如下:
Attempted to load class "MappingDriverChain" from namespace "Doctrine\Common\Persistence\Mapping\Driver".
尝试从命名空间“Doctrine\Common\Persistence\Mapping\Driver”加载 class“MappingDriverChain”。 Did you forget a "use" statement for "Doctrine\Persistence\Mapping\Driver\MappingDriverChain"?
您是否忘记了“Doctrine\Persistence\Mapping\Driver\MappingDriverChain”的“使用”语句?
It's correct there is no link with your update on twig files.正确的是,您在 twig 文件上的更新没有链接。
As your composer.json file doesn't fix the doctrine version, it upgraded your doctrine package version.由于您的 composer.json 文件没有修复 doctrine 版本,它升级了您的 doctrine ZEFE90A8E604A7C840EZ88D 版本。 In the newest version of Doctrine, the pattern of repository files have change.
在最新版本的 Doctrine 中,存储库文件的模式发生了变化。 There is 2 solutions:
有2个解决方案:
Solution1 (Not tested and not recommended): you fix the doctrine package by adding it in the composer.json.解决方案1(未测试且不推荐):通过将 doctrine package 添加到 composer.json 来修复它。 You can have a look on the old composer.lock of your application.
您可以查看应用程序的旧 composer.lock。 This isn't the best solution.
这不是最好的解决方案。 (But it's only my opinion)
(但这只是我的意见)
Solution2: Upgrade your files to be compliant with the new version of doctrine.解决方案2:升级您的文件以与新版本的 doctrine 兼容。
I see three major steps:我看到三个主要步骤:
So, I guess that you have to upgrade your repositories declaration.所以,我想你必须升级你的存储库声明。
Here is the new pattern of a repository这是存储库的新模式
#src/Repository/Foo.php
use App\Entity\Foo;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\Persistence\ManagerRegistry;
/**
* Some repository coded in the new way.
*
* @method Article|null find($id, $lockMode = null, $lockVersion = null)
* @method Article|null findOneBy(array $criteria, array $orderBy = null)
* @method Article[] findAll()
* @method Article[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class ArticleRepository extends ServiceEntityRepository
{
/**
* FooRepository constructor.
*
* @param ManagerRegistry $registry injected by dependency injection
*/
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Foo::class);
}
If you don't use repositories, you have to find where in your code you was using Doctrine\Bundle\DoctrineBundle\Registry
and find a way to replace it by the new ManagerRegistry
.如果您不使用存储库,则必须找到您在代码中使用
Doctrine\Bundle\DoctrineBundle\Registry
的位置,并找到一种方法将其替换为新的ManagerRegistry
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.