This presentation introduces the event manager in Zend Framework 2.
Get 50% discount on my online Zend Framework 2 course by following the below link!
https://www.udemy.com/zend-framework-2-from-beginner-to-professional/?couponCode=SS10&utm_source=slideshare&utm_campaign=sspresentation&utm_medium=referral
2. Introduction to the event system
ZF2 is based on the Event-driven Architecture (EDA)
Simply put, the idea is that activities occur in response to events
Thus, activities are attached to events, and when a given event occurs, its
attached activities are executed
This principle is well known in programming; Java and the .NET platform, for
instance, both make heavy use of event handling
3. Configuring ZF2 with events
Events are used internally in Zend Framework 2, e.g. by the module manager
Subscribing to these events allows one to “plug into” the framework
A series of pre-defined events are available
Please see the documentation for more information and a full list of available events
4. Example use case
Imagine placing an order on Amazon.com
When the order is placed, a series of activities or processes should occur
A confirmation should be sent to the customer
The items should be picked from the warehouse
The customer’s credit card should be debited
...
These processes are registered on the OnOrderPlaced event, and when this
event is triggered, the attached processes or activities are executed
5. Advantages
Provides a great deal of flexibility in a system
Easy to add or remove activities that should happen when a given event occurs
The application becomes very flexible, as it is easy to “hook into” the system
Business processes can easily be adapted to changing business needs
6. Disadvantages
It can be hard to understand what actually happens during a business process
Activities can be attached to events almost anywhere in the application, and
perhaps even added dynamically
This makes it difficult to both understand and debug a process; one must know which activities are
attached to an event at runtime to understand exactly what happens
The flow of the business process is therefore less transparent than if it were implemented in a
completely procedural fashion
The sequence in which activities must be executed adds complexity
10. More information
A priority can also be specified when attaching an event listener to an event
The priority is simply an integer; the listener with the highest number is executed first
A callback can be assigned to multiple events at once
A wildcard can also be used to attach a callback to all events
More information and examples: http://tinyurl.com/zf2-event-manager
11. that’s allThis presentation is part of my Zend Framework 2 online course.
Get 50% discount by navigating to the below URL!
https://www.udemy.com/zend-framework-2-from-beginner-to-
professional/?couponCode=SS50
Notes de l'éditeur
The event manager can be thought of as an implementation of the observer pattern where the event is the subject and the observers are the attached event listeners.
$this is the target (often be the class from which the event is triggered)