登录EventListener未在生产端触发 [英] Login EventListener not firing on production side

查看:101
本文介绍了登录EventListener未在生产端触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个事件侦听器,当用户登录我的Symfony设置时应触发该事件侦听器.

I have an event listener that should fire when a user logs in in my Symfony setup.

我的服务中有以下内容.yml

I have the following in my services.yml

...
d_user.login_listener:
    class: D\UserBundle\EventListener\LoginListener
    arguments: []
    tags:
        - { name: 'kernel.event_subscriber', event: 'security.interactive_login' }

在我的登录监听器中,我只是拥有这个:

and in my login listener I simply have this:

<?php

namespace D\UserBundle\EventListener;

use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class LoginListener implements EventSubscriberInterface
{
    public function onSecurityInteractiveLogin(InteractiveLoginEvent $event)
    {
        echo 'user logged in';
    }

    public static function getSubscribedEvents()
    {
        return array(
            // must be registered before the default Locale listener
            'security.interactive_login' => array(array('onSecurityInteractiveLogin', 18))
        );
    }
}

在我的开发服务器上,我在重定向之前正确看到了用户已登录"文本,但是在我的生产服务器上,它只是登录而没有事件触发.我稍后将对此进行修改,以在用户登录时设置会话变量.我只需要获取调用的方法即可.

On my dev server I correctly see the text "user logged in" before redirection, but on my production server it just logs in without the event firing. I'm modifying this later to set a session var on user login. I just need to get the method called.

有什么建议吗?我曾尝试在生产环境中清除prod和dev的缓存,但这无济于事.

Any advice? I've tried clearing the cache for prod and dev on my production environment, but that didn't help.

推荐答案

不建议使用echo进行调试.如果要输出,请使用记录器!

Debugging with echo is discouraged. If you want an output, use the logger!

namespace D\UserBundle\EventListener;
use Psr\Log\LoggerInterface;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class LoginListener implements EventSubscriberInterface
{
    private $logger;
    private $router;

    public function __construct(LoggerInterface $logger)
    {
        $this->logger = $logger;
    }

    public function onSecurityInteractiveLogin(InteractiveLoginEvent $event)
    {
        $this->logger->info('user logged in');
    }

    public static function getSubscribedEvents()
    {
        return array(
            // must be registered before the default Locale listener
            'security.interactive_login' => array(array('onSecurityInteractiveLogin', 18))
        );
    }
}

并将记录器注入您的服务定义中,最好使用一个不错的频道名称:

and inject the logger in your service defintion, preferrable with a nice channel name:

d_user.login_listener:
    class: D\UserBundle\EventListener\LoginListener
    arguments: [@logger]
    tags:
        - { name: 'kernel.event_subscriber', event: 'security.interactive_login' }
        - { name: monolog.logger, channel: d_user }

这篇关于登录EventListener未在生产端触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆