dougu3290 2016-03-21 05:40
浏览 56

如何在没有请求的情况下调度symfony事件

In my symfony project I have created a command for cron task(runs one time for day). It change a table and that table has updatedBy property (by doctrine blameable listener). So i have to log a user programmatically. here is my code for that.

if ($this->container->get("security.context")->getToken() === null) {
      $token = new UsernamePasswordToken($systemUser, null, "admin_area", $systemUser->getRoles());
      $this->container->get("security.context")->setToken($token);
}

My problem is how to dispatch this event. Because there is no request I cant use following code.

$request = $this->container->get("request");
        $event = new InteractiveLoginEvent($request, $token);
        $this->container->get("event_dispatcher")->dispatch("security.interactive_login", $event);

Also get("request") service cannot use inside command. Please help me to dispatch this event.

  • 写回答

1条回答 默认 最新

  • dongsong73032 2016-03-21 07:10
    关注

    -You can create a request object via the create method as example:

    $request = Request::create("?foo=bar");
    

    Then use it in the event:

        $event = new InteractiveLoginEvent($request, $token);
    

    I don't know if need some params from the request but you can add (See the doc).

    Hope this help

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题