小编Vel*_*jex的帖子

Symfony2注销事件监听器问题

我正在努力将审计日志记录添加到Symfony2项目中,该项目记录所有页面加载并将请求发布到自定义审计表中.该项目使用Symfony2(访问/注销)的默认注销路由,该路由会销毁会话,然后重定向到/ login路由.

为onKernelRequest设置了一个事件监听器,然后将正确的数据写入表中.在security.yml文件中,我列出了以下注销路由.

security:
    firewalls:
        main:
            logout:
                path: /logout
                target: /login
Run Code Online (Sandbox Code Playgroud)

审核日志记录适用于除注销事件之外的所有页面.注销后,我尝试访问分析器,然后从侧栏中的"Last 10"选项中选择"/ logout"操作.单击"Events"时,会列出kernel.request的默认Symfony事件,例如DebugHandler和ProfileListener,但是我的自定义回调显示在"Not Called Listeners"选项卡下.

有一个success_handler可以添加到security.yml文件中,但我需要一个可以在会话被销毁之前运行我的事件监听器的方法.有没有办法让现有的侦听器在Symfony执行注销之前记录注销事件?

编辑

<?php

// src/AuditBundle/EventListener/AuditListener.php
namespace AuditBundle\EventListener;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpFoundation\RequestStack;
use AuditBundle\Entity\AuditLog;

class AuditListener
{
    protected $requestStack;
    protected $em;
    protected $tokenStorage;
    protected $authorizationChecker;

    public function __construct(RequestStack $requestStack, \Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage $tokenStorage, $authorizationChecker, \Doctrine\ORM\EntityManager $em = NULL)
    {
        $this->requestStack = $requestStack;
        $this->em = $em;
        $this->tokenStorage = $tokenStorage;
        $this->authorizationChecker = $authorizationChecker;
    }

    public function onKernelRequest(GetResponseEvent $response)
    {
        $request = $response->getRequest();
        if ( strpos($request->getRequestUri(), 'fonts') !== …
Run Code Online (Sandbox Code Playgroud)

php session symfony-2.8

4
推荐指数
1
解决办法
4518
查看次数

标签 统计

php ×1

session ×1

symfony-2.8 ×1