使用事件侦听器中的数据和事件调度程序的功能

时间:2017-02-28 16:01:20

标签: symfony event-listener

背景: 我想使用来自调用事件调度程序的函数的事件侦听器中的数据。从我所看到的事件调度程序只返回GenericEvent对象。

主捆绑包是调用调度程序的地方。

MainBundleController.php

public function mainBundle() {
 $this->getContainer()->get('event_dispatcher')->addListener('my_test_event', new GenericEvent($object))
// Is it possible to use the data from $anotherBundleListener

}

AnotherBundle / services.yml

another_bundle.listener:
  class:   ..../AnotherBundleEventService
  tags:
    - {name: kernel.event_listener, event: my_test_event, method: anotherBundleListener}

AnotherBundleEventService.php

public function anotherBundleListener(GenericEvent $event) {
 //Do amazing things
 return $somethingAmazing
}

事件监听器和调度程序工作唯一的问题是我想在调用调度程序的函数中使用监听器中的数据。

如果还有其他方式,请告诉我。

1 个答案:

答案 0 :(得分:0)