SlideShare a Scribd company logo
Event Dispatcher
Symfony 2.X
- Yogesh Salvi
Introduction
● Coupling
● Tightly Coupled and Loosely Coupled System
● Event
● Event Dispatcher
○ Open Ear Event Dispatcher - Listener
○ Open Mouth Event Dispatcher - Talker
● Event-Driven Architecture
● Understand the terms
○ Listener
○ Subscriber
● Demo
● Questions?
Coupling
Coupling
● A device for connecting parts.
● In Software Terminology
○ Coupling is the degree of interdependence between software entities.
○ It measure of how closely connected two or more software entities.
○ It shows strength of the relationships between software entities.
○ Coupling is usually contrasted with cohesion.
○ Low coupling often correlates with high cohesion, and vice versa.
○ Coupling can be "low" (also "loose" and "weak") or "high" (also "tight" and "strong")
Tightly and Loosely Coupled
System
Tightly Coupled System
● Tight coupling is when a group of entities are highly dependent on one
another.
● This scenario arises when a class assumes too many responsibilities,
● When one concern is spread over many entities rather than having its own
class.
● When entity don’t follow Single Responsibility Principle and separation of
concerns.
F
E
D
C
A
B
Tightly Coupled System - Disadvantages
● A change in one module usually forces a ripple effect of changes in other
modules.
● Assembly of modules might require more effort and/or time due to the
increased inter-module dependency.
● A particular module might be harder to reuse and/or test because dependent
modules must be included.
Loosely Coupled System
● Loose coupling is achieved by means of a design that promotes
single-responsibility and separation of concerns.
● A loosely-coupled entity can be consumed and tested independently of other
entities.
● Loose coupling is often a sign of a well-structured computer system and a
good design.
● when it combined with high cohesion, it supports the general goals of high
readability and maintainability.
Loosely Coupled System
● Components can be replaced with alternative implementations that provide
the same services.
● Components in a loosely coupled system are less constrained to the same
platform, language, operating system, or build environment.
F
E
D
C
A
B
Event
Event
An event can be defined as
"a significant change in state"
Event - Structure
● Event Header
○ The event header might include information such as event name, time stamp for the event,
and type of event.
● Event Body
○ The event body provides the details of the state change detected. An event body should not
be confused with the pattern or the logic that may be applied in reaction to the occurrence of
the event itself.
Event
Dispatcher
Dispatcher
● Dispatchers are communications personnel
responsible for receiving and transmitting pure and
reliable messages.
● A number of organizations, including police and fire
departments, emergency medical services, railroads,
etc, use dispatchers to relay information and
coordinate their operations.
Event Dispatcher
Event Dispatcher
● It provides way which allow application components to communicate with
each other by dispatching events and listening to them.
● It is the only way to use communication where you don't care about the
target object.
● Target object may or may not be exists.
● They will listen to any messages that are being broadcasted.
Open Ear Event Dispatcher
Listener
Open Ear Event Dispatcher - Listener
● This type of event dispatchers are like
message-sponges.
● They will listen to any messages that are
being broadcasted.
Open Mouth Event
Dispatcher - Talker
Open Mouth Event Dispatcher - Talker
● This type of event dispatchers are like
loudmouths.
● They will broadcast any message to anyone
who is listening on demand.
Event-Driven Architecture
Event-Driven Architecture
Event-Driven Architecture aims at promoting
Loosely Coupled System.
● It is a programming paradigm in which the flow of the program is
determined by series of events.
● It is a software architecture pattern promoting the creation, detection,
consumption of, and reaction to events.
Event-Driven Architecture
Event Generator
Event Dispatcher
Event Handler 2Event Handler 1 Event Handler 3
Event Open Ear Event
Dispatcher
Open Mouth
Event Dispatcher
Event-Driven Architecture
● A listener tells a central dispatcher object that it wants to listen to the some
specific event (X).
● At some point, the event generator tells the dispatcher object to dispatch the
event (X), passing with it an Event object.
● Event object itself often contains data about the event being dispatched.
● The dispatcher notifies (i.e. calls a method on) all listeners of the event (X).
Listener vs Subscriber
Listener
● It is signed up specifying the events on which it listens (i.e. Service
Definition).
● It can also listen on several events simply by adding more tags in service
definition.
● Same event listener can be bind to different events without modifying class.
Simply by changing service definition.
● An event listeners are bind at the time of bootstrapping.
● Listeners are more flexible because bundles can enable or disable each of
them conditionally depending on some configuration value.
Subscriber
● The Subscriber has a method telling the dispatcher what events it is listening
to.
● It keeps the knowledge of the events in the class rather than in the service
definition.
● You can change the events a subscriber is registered for, at runtime and
even after registering the subscriber by changing the return value of
getSubscribedEvents method.
● 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;
Listener vs Subscriber
Eventually
both Listeners and Subscribers are
registered as
“Listeners”.
Debugging Event Listeners
You can find out what listeners are registered in the event dispatcher using the
console:
You can get registered listeners for a particular event by specifying its name:
# php bin/console debug:event-dispatcher
# php bin/console debug:event-dispatcher kernel.exception
Demo
Questions???
Thank You!
Yogesh M Salvi
References:
● https://en.wikipedia.org/wiki/Loose_coupl
ing
● https://en.wikipedia.org/wiki/Event-drive
n_architecture
● http://symfony.com/doc/current/compone
nts/event_dispatcher.html

More Related Content

Similar to Event Dispatcher

Learning Vague Knowledge From Socially Generated Content in an Enterprise Fra...
Learning Vague Knowledge From Socially Generated Content in an Enterprise Fra...Learning Vague Knowledge From Socially Generated Content in an Enterprise Fra...
Learning Vague Knowledge From Socially Generated Content in an Enterprise Fra...
Panos Alexopoulos
 
AULT : Agent based User simulation
AULT : Agent based User simulationAULT : Agent based User simulation
AULT : Agent based User simulation
Om Narayan
 
PATTERNS06 - The .NET Event Model
PATTERNS06 - The .NET Event ModelPATTERNS06 - The .NET Event Model
PATTERNS06 - The .NET Event Model
Michael Heron
 
context aware.pptx
context aware.pptxcontext aware.pptx
context aware.pptx
nassmah
 
pattern v
pattern vpattern v
pattern v
ValerieMiguel3
 
Architectural styles class 1
Architectural  styles class 1Architectural  styles class 1
Architectural styles class 1
Dr Reeja S R
 
An Introduction to Software Architecture - Summary
An Introduction to Software Architecture - SummaryAn Introduction to Software Architecture - Summary
An Introduction to Software Architecture - Summary
John Ortiz
 
A Whirlwind Tour of Spatial Joins
A Whirlwind Tour of Spatial JoinsA Whirlwind Tour of Spatial Joins
A Whirlwind Tour of Spatial Joins
Safe Software
 
Testing Event Driven Architecture Presentation
Testing Event Driven Architecture PresentationTesting Event Driven Architecture Presentation
Testing Event Driven Architecture Presentation
Knoldus Inc.
 
Testing Event Driven Architecture Presentation
Testing Event Driven Architecture PresentationTesting Event Driven Architecture Presentation
Testing Event Driven Architecture Presentation
Knoldus Inc.
 
Reactive - Is it really a Magic Pill?
Reactive - Is it really a Magic Pill?Reactive - Is it really a Magic Pill?
Reactive - Is it really a Magic Pill?
Tech Triveni
 
Tlpi chapter 38 writing secure privileged programs
Tlpi   chapter 38 writing secure privileged programsTlpi   chapter 38 writing secure privileged programs
Tlpi chapter 38 writing secure privileged programs
Shu-Yu Fu
 
Reactive systems
Reactive systemsReactive systems
Reactive systems
Matteo Pierro
 
Understanding concurrency
Understanding concurrencyUnderstanding concurrency
Understanding concurrency
Anshul Sharma
 
Tum seminar specification of usage control requirements
Tum seminar specification of usage control requirementsTum seminar specification of usage control requirements
Tum seminar specification of usage control requirements
Bibek Shrestha
 
Secure Developer Access at Decisiv
Secure Developer Access at DecisivSecure Developer Access at Decisiv
Secure Developer Access at Decisiv
Teleport
 
Event+driven+programming key+features
Event+driven+programming key+featuresEvent+driven+programming key+features
Event+driven+programming key+features
Faisal Aziz
 
ax2012
 ax2012 ax2012
ax2012
hailtaron
 
P106 rajagopalan-read
P106 rajagopalan-readP106 rajagopalan-read
P106 rajagopalan-read
Takefumi MIYOSHI
 
Modernising Change - Lime Point - Confluent - Kong
Modernising Change - Lime Point - Confluent - KongModernising Change - Lime Point - Confluent - Kong
Modernising Change - Lime Point - Confluent - Kong
confluent
 

Similar to Event Dispatcher (20)

Learning Vague Knowledge From Socially Generated Content in an Enterprise Fra...
Learning Vague Knowledge From Socially Generated Content in an Enterprise Fra...Learning Vague Knowledge From Socially Generated Content in an Enterprise Fra...
Learning Vague Knowledge From Socially Generated Content in an Enterprise Fra...
 
AULT : Agent based User simulation
AULT : Agent based User simulationAULT : Agent based User simulation
AULT : Agent based User simulation
 
PATTERNS06 - The .NET Event Model
PATTERNS06 - The .NET Event ModelPATTERNS06 - The .NET Event Model
PATTERNS06 - The .NET Event Model
 
context aware.pptx
context aware.pptxcontext aware.pptx
context aware.pptx
 
pattern v
pattern vpattern v
pattern v
 
Architectural styles class 1
Architectural  styles class 1Architectural  styles class 1
Architectural styles class 1
 
An Introduction to Software Architecture - Summary
An Introduction to Software Architecture - SummaryAn Introduction to Software Architecture - Summary
An Introduction to Software Architecture - Summary
 
A Whirlwind Tour of Spatial Joins
A Whirlwind Tour of Spatial JoinsA Whirlwind Tour of Spatial Joins
A Whirlwind Tour of Spatial Joins
 
Testing Event Driven Architecture Presentation
Testing Event Driven Architecture PresentationTesting Event Driven Architecture Presentation
Testing Event Driven Architecture Presentation
 
Testing Event Driven Architecture Presentation
Testing Event Driven Architecture PresentationTesting Event Driven Architecture Presentation
Testing Event Driven Architecture Presentation
 
Reactive - Is it really a Magic Pill?
Reactive - Is it really a Magic Pill?Reactive - Is it really a Magic Pill?
Reactive - Is it really a Magic Pill?
 
Tlpi chapter 38 writing secure privileged programs
Tlpi   chapter 38 writing secure privileged programsTlpi   chapter 38 writing secure privileged programs
Tlpi chapter 38 writing secure privileged programs
 
Reactive systems
Reactive systemsReactive systems
Reactive systems
 
Understanding concurrency
Understanding concurrencyUnderstanding concurrency
Understanding concurrency
 
Tum seminar specification of usage control requirements
Tum seminar specification of usage control requirementsTum seminar specification of usage control requirements
Tum seminar specification of usage control requirements
 
Secure Developer Access at Decisiv
Secure Developer Access at DecisivSecure Developer Access at Decisiv
Secure Developer Access at Decisiv
 
Event+driven+programming key+features
Event+driven+programming key+featuresEvent+driven+programming key+features
Event+driven+programming key+features
 
ax2012
 ax2012 ax2012
ax2012
 
P106 rajagopalan-read
P106 rajagopalan-readP106 rajagopalan-read
P106 rajagopalan-read
 
Modernising Change - Lime Point - Confluent - Kong
Modernising Change - Lime Point - Confluent - KongModernising Change - Lime Point - Confluent - Kong
Modernising Change - Lime Point - Confluent - Kong
 

Recently uploaded

Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
lorraineandreiamcidl
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
aymanquadri279
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Undress Baby
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
Aftab Hussain
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 

Recently uploaded (20)

Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 

Event Dispatcher

  • 2. Introduction ● Coupling ● Tightly Coupled and Loosely Coupled System ● Event ● Event Dispatcher ○ Open Ear Event Dispatcher - Listener ○ Open Mouth Event Dispatcher - Talker ● Event-Driven Architecture ● Understand the terms ○ Listener ○ Subscriber ● Demo ● Questions?
  • 4. Coupling ● A device for connecting parts. ● In Software Terminology ○ Coupling is the degree of interdependence between software entities. ○ It measure of how closely connected two or more software entities. ○ It shows strength of the relationships between software entities. ○ Coupling is usually contrasted with cohesion. ○ Low coupling often correlates with high cohesion, and vice versa. ○ Coupling can be "low" (also "loose" and "weak") or "high" (also "tight" and "strong")
  • 5. Tightly and Loosely Coupled System
  • 6. Tightly Coupled System ● Tight coupling is when a group of entities are highly dependent on one another. ● This scenario arises when a class assumes too many responsibilities, ● When one concern is spread over many entities rather than having its own class. ● When entity don’t follow Single Responsibility Principle and separation of concerns. F E D C A B
  • 7. Tightly Coupled System - Disadvantages ● A change in one module usually forces a ripple effect of changes in other modules. ● Assembly of modules might require more effort and/or time due to the increased inter-module dependency. ● A particular module might be harder to reuse and/or test because dependent modules must be included.
  • 8. Loosely Coupled System ● Loose coupling is achieved by means of a design that promotes single-responsibility and separation of concerns. ● A loosely-coupled entity can be consumed and tested independently of other entities. ● Loose coupling is often a sign of a well-structured computer system and a good design. ● when it combined with high cohesion, it supports the general goals of high readability and maintainability.
  • 9. Loosely Coupled System ● Components can be replaced with alternative implementations that provide the same services. ● Components in a loosely coupled system are less constrained to the same platform, language, operating system, or build environment. F E D C A B
  • 10. Event
  • 11. Event An event can be defined as "a significant change in state"
  • 12. Event - Structure ● Event Header ○ The event header might include information such as event name, time stamp for the event, and type of event. ● Event Body ○ The event body provides the details of the state change detected. An event body should not be confused with the pattern or the logic that may be applied in reaction to the occurrence of the event itself.
  • 13. Event
  • 15. Dispatcher ● Dispatchers are communications personnel responsible for receiving and transmitting pure and reliable messages. ● A number of organizations, including police and fire departments, emergency medical services, railroads, etc, use dispatchers to relay information and coordinate their operations.
  • 17. Event Dispatcher ● It provides way which allow application components to communicate with each other by dispatching events and listening to them. ● It is the only way to use communication where you don't care about the target object. ● Target object may or may not be exists. ● They will listen to any messages that are being broadcasted.
  • 18. Open Ear Event Dispatcher Listener
  • 19. Open Ear Event Dispatcher - Listener ● This type of event dispatchers are like message-sponges. ● They will listen to any messages that are being broadcasted.
  • 21. Open Mouth Event Dispatcher - Talker ● This type of event dispatchers are like loudmouths. ● They will broadcast any message to anyone who is listening on demand.
  • 23. Event-Driven Architecture Event-Driven Architecture aims at promoting Loosely Coupled System. ● It is a programming paradigm in which the flow of the program is determined by series of events. ● It is a software architecture pattern promoting the creation, detection, consumption of, and reaction to events.
  • 24. Event-Driven Architecture Event Generator Event Dispatcher Event Handler 2Event Handler 1 Event Handler 3 Event Open Ear Event Dispatcher Open Mouth Event Dispatcher
  • 25. Event-Driven Architecture ● A listener tells a central dispatcher object that it wants to listen to the some specific event (X). ● At some point, the event generator tells the dispatcher object to dispatch the event (X), passing with it an Event object. ● Event object itself often contains data about the event being dispatched. ● The dispatcher notifies (i.e. calls a method on) all listeners of the event (X).
  • 27. Listener ● It is signed up specifying the events on which it listens (i.e. Service Definition). ● It can also listen on several events simply by adding more tags in service definition. ● Same event listener can be bind to different events without modifying class. Simply by changing service definition. ● An event listeners are bind at the time of bootstrapping. ● Listeners are more flexible because bundles can enable or disable each of them conditionally depending on some configuration value.
  • 28. Subscriber ● The Subscriber has a method telling the dispatcher what events it is listening to. ● It keeps the knowledge of the events in the class rather than in the service definition. ● You can change the events a subscriber is registered for, at runtime and even after registering the subscriber by changing the return value of getSubscribedEvents method. ● 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;
  • 29. Listener vs Subscriber Eventually both Listeners and Subscribers are registered as “Listeners”.
  • 30. Debugging Event Listeners You can find out what listeners are registered in the event dispatcher using the console: You can get registered listeners for a particular event by specifying its name: # php bin/console debug:event-dispatcher # php bin/console debug:event-dispatcher kernel.exception
  • 31. Demo
  • 33. Thank You! Yogesh M Salvi References: ● https://en.wikipedia.org/wiki/Loose_coupl ing ● https://en.wikipedia.org/wiki/Event-drive n_architecture ● http://symfony.com/doc/current/compone nts/event_dispatcher.html