如何覆盖FOSUserBundle/Doctrine/UserManager.php [英] How to override FOSUserBundle/Doctrine/UserManager.php
问题描述
我正在将文件上传系统与fosuserbundle集成
I am integrating fileupload system with fosuserbundle
我需要重写updateUser函数 在
I need to override updateUser function in
/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Doctrine/UserManager.php
我将此文件复制到
/ACME/UserBundle/Doctrine/UserManager.php
但这是行不通的.
这是我的临时/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Doctrine/UserManager.php
This is my temporary /vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Doctrine/UserManager.php
public function updateUser(UserInterface $user, $andFlush = true)
{
$this->updateCanonicalFields($user);
$this->updatePassword($user);
//it works but it should not be used here.
$user->upload();
//
$this->objectManager->persist($user);
if ($andFlush) {
$this->objectManager->flush();
}
}
推荐答案
您不能像尝试使用简单的捆绑继承那样覆盖UserManager,因为它在FOSUserBundle中被用作服务.
You can not override the UserManager by simple bundle inheritance as you tried because it is used as a service throughout the FOSUserBundle.
在捆绑包(即services.xml)中创建服务配置,并添加自己的acme.user_manager服务:
Create a service configuration in your bundle ( i.e. services.xml ) and add your own acme.user_manager service:
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"
>
<parameters>
<parameter key="acme.user_manager.class">ACME/UserBundle/Doctrine/UserManager</parameter>
</parameters>
<services>
<service id="acme.user_manager" class="%acme.user_manager.class%" public="false">
<argument type="service" id="security.encoder_factory" />
<argument type="service" id="fos_user.util.username_canonicalizer" />
<argument type="service" id="fos_user.util.email_canonicalizer" />
<argument type="service" id="fos_user.entity_manager" />
<argument>%fos_user.model.user.class%</argument>
</service>
</services>
</container>
然后在您的config.yml中配置FOSUserBundle以将该服务用作UserManager
Then configure FOSUserBundle to use this service as the UserManager in your config.yml
fos_user:
# ...
service:
user_manager: acme.user_manager
这篇关于如何覆盖FOSUserBundle/Doctrine/UserManager.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!