Doctrine Listener versus Subscriber

后端 未结 7 955
离开以前
离开以前 2020-12-12 19:52

I\'m working in the Symfony2 framework and wondering when would one use a Doctrine subscriber versus a listener. Doctrine\'s documentation for listeners is very clear, howe

7条回答
  •  执念已碎
    2020-12-12 19:59

    From the documentation :

    The most common way to listen to an event is to register an event listener with the dispatcher. This listener can listen to one or more events and is notified each time those events are dispatched.

    Another way to listen to events is via an event subscriber. An event subscriber is a PHP class that's able to tell the dispatcher exactly which events it should subscribe to. It implements the EventSubscriberInterface interface, which requires a single static method called getSubscribedEvents().

    See the example here :

    https://symfony.com/doc/3.3/components/event_dispatcher.html

提交回复
热议问题