FOSUserBundle 上的错误,传递的参数必须是 ObjectManager 的实例
Posted
技术标签:
【中文标题】FOSUserBundle 上的错误,传递的参数必须是 ObjectManager 的实例【英文标题】:Error on FOSUserBundle, argument passed must be an instance of ObjectManager 【发布时间】:2021-04-13 00:14:33 【问题描述】:我看过所有关于这个主题的帖子,但没有任何帮助。我认为我的问题略有不同。我在 Symfony 4 项目中使用 FOSUser 包。当我访问我的网站时,我收到此错误:
Argument 3 passed to FOS\UserBundle\Doctrine\UserManager::__construct() must be an instance of Doctrine\Common\Persistence\ObjectManager, instance of ContainerVxxTSSB\EntityManager_9a5be93 given, called in C:\Users\xxx\Documents\Dev\project\var\cache\dev\ContainerVxxTSSB\srcApp_KernelDevDebugContainer.php on line 1885
我不知道错误来自哪里,因为它表明缓存中有一个文件。我尝试删除 var 文件夹,但仍然是同样的错误。我不明白的是,错误说我给出了一个“ContainerVxxTSSB\EntityManager_9a5be93”的实例,但我看不出它怎么可能。 我什至不知道在哪里搜索来解决这个问题。
services.yaml
user_factory:
class: App\Security\UserFactory
arguments: ["@fos_user.user_manager", "@doctrine.orm.entity_manager", "%kernel.logs_dir%"]
UserFactory.php:
use App\Entity\User;
use FOS\UserBundle\Doctrine\UserManager;
use Hslavich\OneloginSamlBundle\Security\Authentication\Token\SamlTokenInterface;
use Hslavich\OneloginSamlBundle\Security\User\SamlUserFactoryInterface;
class UserFactory implements SamlUserFactoryInterface
private $userManager;
private $entityManager;
private $logs_dir;
public function __construct(UserManager $userManager, $entityManager, $logs_dir)
$this->userManager = $userManager;
$this->entityManager = $entityManager;
$this->logs_dir = $logs_dir;
然后在供应商文件夹中的 UserManager.php 中:
/**
* Constructor.
*
* @param PasswordUpdaterInterface $passwordUpdater
* @param CanonicalFieldsUpdater $canonicalFieldsUpdater
* @param ObjectManager $om
* @param string $class
*/
public function __construct(PasswordUpdaterInterface $passwordUpdater, CanonicalFieldsUpdater $canonicalFieldsUpdater, ObjectManager $om, $class)
parent::__construct($passwordUpdater, $canonicalFieldsUpdater);
$this->objectManager = $om;
$this->class = $class;
编辑: composer.json中的学说信息
"doctrine/annotations": "^1.0",
"doctrine/doctrine-bundle": "^2.2",
"doctrine/doctrine-migrations-bundle": "^3.0",
"doctrine/orm": "^2.8",
错误指示的行:
return $this->services['fos_user.user_manager'] = new \FOS\UserBundle\Doctrine\UserManager(($this->privates['fos_user.util.password_updater'] ?? $this->getFosUser_Util_PasswordUpdaterService()), ($this->privates['fos_user.util.canonical_fields_updater'] ?? $this->getFosUser_Util_CanonicalFieldsUpdaterService()), ($this->services['doctrine'] ?? $this->getDoctrineService())->getManager(NULL), 'App\\Entity\\User');
创建我所做的项目:
composer create-project symfony/website-skeleton:"^4.4" project_name
然后添加捆绑包
composer require friendsofsymfony/user-bundle
我不记得有错误
编辑 2: 当我想用这个命令清除缓存时:
php bin/console clear:cache
我收到此错误:
TypeError #742
#message: "Argument 3 passed to FOS\UserBundle\Doctrine\UserManager::__construct() must be an instance of Doctrine\Common\Persistence\ObjectManager, instance of ContainerXNABQPE\EntityManager_9a5be93 given, called in C:\Users\xxx\Documents\Dev\test\var\cache\dev\ContainerXNABQPE\srcApp_KernelDevDebugContainer.php on line 1416"
#code: 0
#file: "C:\Users\xxx\Documents\Dev\test\vendor\friendsofsymfony\user-bundle\Doctrine\UserManager.php"
#line: 41
trace:
C:\Users\xxx\Documents\Dev\test\vendor\friendsofsymfony\user-bundle\Doctrine\UserManager.php:41 …
C:\Users\xxx\Documents\Dev\test\var\cache\dev\ContainerXNABQPE\srcApp_KernelDevDebugContainer.php:1416
ContainerXNABQPE\srcApp_KernelDevDebugContainer->getFosUser_UserManagerService()
›
› return $this->services['fos_user.user_manager'] = new \FOS\UserBundle\Doctrine\UserManager(($this->privates['fos_user.util.password_updater'] ?? $this->getFosUser_Util_PasswordUpdaterService()), ($this->privates['fos_use
r.util.canonical_fields_updater'] ?? $this->getFosUser_Util_CanonicalFieldsUpdaterService()), ($this->services['doctrine'] ?? $this->getDoctrineService())->getManager(NULL), 'App\\Entity\\User');
›
arguments:
$passwordUpdater: FOS\UserBundle\Util\PasswordUpdater #739 …
$canonicalFieldsUpdater: FOS\UserBundle\Util\CanonicalFieldsUpdater #741 …
$om: ContainerXNABQPE\EntityManager_9a5be93 #647 …
$class: "App\Entity\User"
C:\Users\xxx\Documents\Dev\test\var\cache\dev\ContainerXNABQPE\srcApp_KernelDevDebugContainer.php:4625 …
C:\Users\xxx\Documents\Dev\test\var\cache\dev\ContainerXNABQPE\srcApp_KernelDevDebugContainer.php:4388 …
C:\Users\xxx\Documents\Dev\test\vendor\symfony\dependency-injection\Container.php:450 …
C:\Users\xxx\Documents\Dev\test\vendor\symfony\dependency-injection\Argument\ServiceLocator.php:40 …
C:\Users\xxx\Documents\Dev\test\vendor\symfony\console\CommandLoader\ContainerCommandLoader.php:45 …
C:\Users\xxx\Documents\Dev\test\vendor\symfony\console\Application.php:548 …
C:\Users\xxx\Documents\Dev\test\vendor\symfony\console\Application.php:750 …
C:\Users\xxx\Documents\Dev\test\vendor\symfony\framework-bundle\Console\Application.php:143 …
C:\Users\xxx\Documents\Dev\test\vendor\symfony\console\Application.php:561 …
C:\Users\xxx\Documents\Dev\test\vendor\symfony\console\Application.php:587 …
C:\Users\xxx\Documents\Dev\test\vendor\symfony\console\Application.php:657 …
C:\Users\xxx\Documents\Dev\test\vendor\symfony\framework-bundle\Console\Application.php:117 …
C:\Users\xxx\Documents\Dev\test\vendor\symfony\console\Application.php:237 …
C:\Users\xxx\Documents\Dev\test\vendor\symfony\framework-bundle\Console\Application.php:83 …
C:\Users\xxx\Documents\Dev\test\vendor\symfony\console\Application.php:149 …
C:\Users\xxx\Documents\Dev\test\bin\console:42 …
【问题讨论】:
有趣。通常这将是“清除缓存”类型的问题,但您已经尝试过了。您可以尝试查看第 1885 行的 srcApp_KernelDevDebugContainer.php。它基本上是创建 UserFactory 的地方,但我认为它不会有太大帮助。你在4.0之前有这个工作吗?我问是因为 FOSUserBundle 并不总是像它应该的那样得到维护。可以尝试创建一个新的 4.4 项目,安装 FOSUserBundle,然后比较版本以查看是否存在某种不匹配。 错误所在的行 " return $this->services['fos_user.user_manager'] = new \FOS\UserBundle\Doctrine\UserManager(($this->privates['fos_user.util .password_updater'] ?? $this->getFosUser_Util_PasswordUpdaterService()), ($this->privates['fos_user.util.canonical_fields_updater'] ?? $this->getFosUser_Util_CanonicalFieldsUpdaterService()), ($this->services['doctrine '] ?? $this->getDoctrineService())->getManager(NULL), 'App\\Entity\\User'); ".这是 Symfony 4.4 的新项目,这是昨天的新项目,我马上就得到了这个错误。 考虑用上面的代码更新你的问题。评论格式不好。虽然它似乎没有在任何地方提到记录器目录。 是的,抱歉,已经完成了 还有一个小请求。我使用了“composer new --full --version=lts project_name”,然后是“composer require friendsofsymfony/user-bundle”,composer 抱怨 twig 版本。考虑使用用于创建新项目的命令更新您的问题并安装用户包。 【参考方案1】:抱歉,回复晚了,我不确定您是否还需要帮助,但这应该可以帮助您。 FOSUserBundle 显然已经被推到了生命的尽头,因为在 reposity 上没有任何活动。从长远来看,最好远离它。但是,您仍然可以使其工作。
您需要将 doctrine/orm
依赖项版本从 ^2.8
降级为 2.7
。
2.8
以上的任何内容都需要doctrine/common
版本^3.0
,这将导致您面临的问题。
【讨论】:
【参考方案2】:您可以尝试以下方法吗:
use App\Entity\User;
use FOS\UserBundle\Doctrine\UserManager;
use Hslavich\OneloginSamlBundle\Security\Authentication\Token\SamlTokenInterface;
use Hslavich\OneloginSamlBundle\Security\User\SamlUserFactoryInterface;
class UserFactory implements SamlUserFactoryInterface
private $userManager;
private $entityManager;
private $logs_dir;
public function __construct(UserManager $userManager, Doctrine\Common\Persistence\ObjectManager $entityManager, $logs_dir)
$this->userManager = $userManager;
$this->entityManager = $entityManager;
$this->logs_dir = $logs_dir;
?
【讨论】:
我试过了,没有任何改变。但是 Doctrine\Common\Persistence\ObjectManager 有下划线,上面写着“未定义的命名空间持久性”。 ok,只输入ObjectManager
,让IDE自动完成命名空间
他们也尝试将EntityManagerInterface
作为类型提示
接下来我要说的是将供应商更新到可能的最新版本,我在互联网上发现了一些针对您的问题的问题,最终他们说要更新学说
另外,不幸的是,接下来要考虑不使用 FOSUserBundle,它现在已经被弃用了以上是关于FOSUserBundle 上的错误,传递的参数必须是 ObjectManager 的实例的主要内容,如果未能解决你的问题,请参考以下文章