Subscriber多事件监听

  1. <?php
  2. namespace Group\Events\Tests;
  3. use Group\Events\EventSubscriberInterface;
  4. class TestSubscriber implements EventSubscriberInterface
  5. {
  6. public function getSubscribedEvents()
  7. {
  8. return [
  9. //eventName => listener
  10. 'test.start' => 'onTestStart',
  11. //eventName => listener, priority
  12. 'test.stop' => ['onTestStop', 100],
  13. //eventName => array listener, priority
  14. 'test.doing' => [
  15. ['onDoA'],
  16. ['onDoB', 225],
  17. ],
  18. ];
  19. }
  20. public function onTestStart(\Event $event)
  21. {
  22. echo 'onTestStart';
  23. }
  24. public function onTestStop(\Event $event)
  25. {
  26. echo 'onTestStop';
  27. }
  28. public function onDoA(\Event $event)
  29. {
  30. echo 'onDoA';
  31. }
  32. public function onDoB(\Event $event)
  33. {
  34. echo 'onDoB';
  35. }
  36. }

如何绑定多事件监听Subscriber见EventDispatcher事件调度