我试图覆盖LastLoginListener以向其添加功能。Fosuserbundle覆盖事件监听器
我;想要做它描述here 看来
在的appbundle \ DependencyInjection \ OverrideServiceCompilerPass.php
<?php
namespace AppBundle\DependencyInjection\Compiler;
use AppBundle\EventListener\LastLoginListener;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class OverrideServiceCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
$definition = $container->getDefinition('"fos_user.security.interactive_login_listener');
$definition->setClass(LastLoginListener::class);
}
services.yml
services:
app.login_listener:
class: AppBundle\EventListener\LastLoginListener
arguments: []
tags:
- { name: kernel.event_subscriber }
监听器本身从包中复制。
自动加载预期类 “的appbundle \ DependencyInjection \ OverrideServiceCompilerPass” 到文件 “/vendor/composer/../../src/AppBundle/DependencyInjection/OverrideServiceCompilerPass.php” 来定义。该文件已找到,但该类不在其中,类名或命名空间可能有拼写错误。 在DebugClassLoader.php(线路261)
我的目标是增加与听众的最后登录的IP地址,但我需要创建另一个添加一个角色和注册日期 我想做它“正确的方式”,而不是做一些事情hackish
我与工作事件侦听器现在这样做,似乎是一个编译器通过覆盖不需要的服务,我可以用它来扩展默认功能的默认侦听器。 –
对不起,我不能编辑我的评论,张贴作为解决方案,我会接受。 –