Got*_*bel 10 events event-listener symfony fosuserbundle
我激活了FOSUserBundle的用户确认.但我不想接受原始听众的回应
$url = $this->router->generate('fos_user_registration_check_email');
$event->setResponse(new RedirectResponse($url));
Run Code Online (Sandbox Code Playgroud)
我想选择另一条路线.我试图扩展EventListener
namespace Acme\MyBundle\EventListener;
use FOS\UserBundle\EventListener\EmailConfirmationListener as BaseListener;
// ...
class EmailConfirmationListener extends BaseListener
{
public function onRegistrationSuccess(FormEvent $event)
{
$url = $this->router->generate('fos_user_registration_check_email');
$event->setResponse(new RedirectResponse($url));
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,EventListener似乎不是可扩展的,就像控制器或表单一样.(万一你想知道:当然我的捆绑是FOSUserBundle的孩子.)
所以我想避免直接在vendor文件夹中编辑这两行(因为这样做非常糟糕!).那么我摆脱这场灾难的方法是什么?
Nic*_*ich 23
只需fos_user.listener.email_confirmation通过在您的config.yml...中创建具有相同名称的服务来覆盖服务
# app/config/config.yml
services:
fos_user.listener.email_confirmation:
class: "Acme\MyBundle\EventListener\EmailConfirmationListener"
arguments: ["@fos_user.mailer", "@fos_user.util.token_generator", "@router", "@session"]
tags:
- { name: kernel.event_subscriber }
Run Code Online (Sandbox Code Playgroud)
......甚至更干净 - 创建一个服务使用的参数:
parameters:
my.funky_parameter.class: "Acme\MyBundle\EventListener\EmailConfirmationListener"
services:
fos_user.listener.email_confirmation:
class: "%my.funky_parameter.class%"
# ...
Run Code Online (Sandbox Code Playgroud)
...或者在bundle的扩展名加载的xml/yml/php配置文件中.AppKernel.php选择此方式后,请确保在FOSUserBundle之后注册您的捆绑包.
......或最好的方法:
在编译器传递中更改原始服务的类名称,如文档章节如何覆盖Bundle的任何部分建议.
也许在选择此选项之前,请参阅" 如何使用编译器通行证 "一章.
| 归档时间: |
|
| 查看次数: |
6080 次 |
| 最近记录: |