![]() |
![]() |
![]()
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. |
|
|
![]() ![]() |
![]() |
Aktualny czas: 14.10.2025 - 19:01 |