symfony - Can anyone tell me the difference between subscriber and listener in sf2?
怪我咯
怪我咯 2017-05-16 16:46:15
0
1
487

Like the title, the listener is probably clear, but the subscriber is confused.

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all (1)
为情所困

When registering a listener (a method of a certain class), you need to specify the event.

The subscriber specifies event processing through the getSubscribedEvents() static method, which can be understood as batch registration. The return value of getSubscribedEvents() is an array, and the key is the event name. The corresponding nested array lists the methods that need to be triggered for this event and its priority (the one with the larger value is triggered first, -1024~1024)

class ExampleSubscriber implements EventSubscriberInterface { static public function getSubscribedEvents() { return array( 'kernel.response' => array( // <-- 事件 array('onKernelResponseFirst', 5), // <-- 第一个回调,优先级5 array('onKernelResponseSecond', 0) // <-- 第二个回调,优先级0 ) ); } public function onKernelResponseFirst(FilterResponseEvent $event) { // ... } public function onKernelResponseSecond(FilterResponseEvent $event) { // ... } }
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!