Post
#1
|
|
|
Grupa: Zarejestrowani Postów: 144 Pomógł: 0 Dołączył: 22.03.2015 Ostrzeżenie: (0%)
|
Witam,
Szukam jakiegoś dobego tutorialu z których móglbym się nauczyć eventów.. Np. mam taki kod :
Potem tworzymy listnera
Czy listner to serwis obsługujacy eventy ? Czy zawsze w evencie dodaje metode getData? Dlaczego ? Po co eventowi te dane? Czy event działa na zasadzie : informuje event o jakimś zdarzeniu, even pobiera sobie dane i sam przekazuje do listnera? Pomóżcie mi to ogarnąć (IMG:style_emoticons/default/smile.gif) |
|
|
|
![]() |
Post
#2
|
|
|
Grupa: Zarejestrowani Postów: 82 Pomógł: 22 Dołączył: 20.07.2010 Ostrzeżenie: (0%)
|
Dla listenera w konfiguracji podaje sie jakich eventow slucha (w przypadku wystapienia wybranych eventow jakie metody wywolywac).
Subscriber ma metode getSubscribedEvents(), w ktorej sam informuje jakich eventow slucha (czyli sam decyduje na co bedzie reagowal). Roznica jest dosc subtelna. Caly komponent event dispatcher opisany jest tu: http://symfony.com/doc/current/components/...troduction.html Odpowiedz stofa na takie pytanie jak Twoje: https://github.com/symfony/symfony-docs/issues/3987 A tu w dokumentacji tworzy sie wpis o tym jaka jest roznica (nieduza, jesli nie tworzysz zewnetrznego bundla/biblioteki): https://github.com/symfony/symfony-docs/pull/5377/files +Events or Subscribers +--------------------- + +Listeners and subscribers can be used in the same application indistinctly. The +decision to use either of them is usually a matter of personal taste. However, +there are some minor advantages for each of them: + +* **Subscribers are easier to reuse** because the knowledge of the events is kept + in the class rather than in the service definition. This is the reason why + Symfony uses subscribers internally; +* **Listeners are more flexible** because bundles can enable or disable each of + them conditionally depending on some configuration value. |
|
|
|
Matrix12 [SF2][SF]Symfony2 Events 21.07.2015, 13:04:30
Crozin CytatCzy listner to serwis obsługujacy eventy ?Jes... 21.07.2015, 14:21:57
Matrix12 A możesz mi to przykładowo przedstawić? Bo nie mam... 21.07.2015, 18:55:22
Crozin Ale co, całe przykłady wykorzystania EventDispatch... 21.07.2015, 19:07:29
Matrix12 A czym się różni eventlistner od subscriber? Bo w... 22.07.2015, 18:04:55 ![]() ![]() |
|
Aktualny czas: 29.12.2025 - 00:06 |