I'm building an app in Symfony2 that has a social-driven aspect (many actions a user performs on the site will show up in a "news feed"-style list for others to view). I've determined that the sf2 event dispatcher/listener system is the best way to handle this, but I've run into something of a snag in trying to configure my listener to handle many different events.

我正在Symfony2中构建一个具有社交驱动方面的应用程序(用户在网站上执行的许多操作将显示在“新闻提要”样式列表中供其他人查看)。我已经确定sf2事件调度程序/侦听器系统是处理这个问题的最佳方法,但是我试图配置我的侦听器来处理许多不同的事件时遇到了一些麻烦。

The (now outdated) documentation I've found in my searches seems to indicate that at one point, event listeners could register on multiple events, but the code has been refactored, and now the configuration looks something like this:

我在搜索中找到的(现在过时的)文档似乎表明,在某一时刻,事件监听器可以注册多个事件,但代码已经重构,现在配置看起来像这样:

config.yml:

config.yml:

services:
  social.listener:
    class: F\Q\C\N\SocialEventListener
    tags:
      - { name: kernel.listener, event: onSocialShare }

Is there any way to either:

有没有办法:

  1. Easily pass multiple events (something like event: [onSocialShare, onSocialFriend, onSocialCreate] works, but that feels like it will quickly get ugly and unmaintainable, clogging up my config file with potentially dozens of social events
  2. 轻松传递多个事件(类似事件:[onSocialShare,onSocialFriend,onSocialCreate],但感觉它会很快变得丑陋且无法维护,可能会破坏我的配置文件中的潜在数十个社交事件
  3. Define the event to which I want to subscribe from code (as was done previously)
  4. 定义我想从代码订阅的事件(如前所述)
  5. Or possibly another, better option that I haven't thought of yet
  6. 或者可能是我还没想过的另一个更好的选择

Thanks in advance.

提前致谢。

2 个解决方案

#1


30

Word back from the symfony-users google group (thread here) is that the appropriate way to do this is by adding several tags:

从symfony-users google group(此处的主题)回来的话是,通过添加几个标签来实现此目的的恰当方法是:

services:
  social.listener:
    class: F\Q\C\N\SocialEventListener
    tags:
      - { name: kernel.listener, event: onSocialShare }
      - { name: kernel.listener, event: onSocialFriend }
      - { name: kernel.listener, event: ... etc }

So, it looks like currently, there is no good way of adding event subscriptions from listener code. Oh well.

所以,它看起来像目前,没有从侦听器代码添加事件订阅的好方法。好吧。

更多相关文章

  1. 如何通过mysql查询获得具有不同时区的事件的日,小时,分钟,秒
  2. 【文档】五、Mysql Binlog事件结构
  3. 向数据库添加1的PHP Onclick事件(SQL)
  4. 如何最好地处理重复日历事件的异常
  5. 前端笔记之JavaScript(十)深入JavaScript节点&DOM&事件
  6. 使用Javascript / jQuery的/ CSS。如何在目标div之外维护拖动事
  7. Github推送事件签名不匹配
  8. 在鼠标悬停事件中使用Javascript隐藏内容
  9. 谷歌Chrome复制了JavaScript的“焦点”事件

随机推荐

  1. JQuery查找并更改字符串的样式
  2. 使用BeautifulSoup解析HTML时遇到问题
  3. java中json数据格式的应用
  4. jQuery animate()函数没有动画
  5. 【转】Mozilla研究—深入理解mozilla所需
  6. 总结一些更多的针对webkit的HTML, CSS和J
  7. 韩顺平_轻松搞定网页设计(html+css+javas
  8. Python-html课程基础复习
  9. html中页面传递参数不用cookie不用缓存,j
  10. sp_send_dbmail在body中嵌入mhtml文件