From the course: PHP: Design Patterns
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
The publish/subscriber pattern in action - PHP Tutorial
From the course: PHP: Design Patterns
The publish/subscriber pattern in action
- Many of the major frameworks implement some form of the Pub-Sub pattern, but the implementation that I'm most familiar with is that of the Zend framework. You can see that example here. Once again, the required library is already installed in your vendor directory via composer. You don't have to do anything to use this example. In this case, we use Zend frameworks EventManager to attach certain listeners to various method calls. So here we attach this closure to this method call. Now, when we trigger the load and the test amends below, we can see the event is fired one, and only one time for the load event. Here. The test event doesn't fire the event because we're not listening for that one. In the browser, this looks like this. So we see that the event load was captured, and we pass the parameters along. Also, you should note that this implementation is much more advanced than my original, and that we can pass along specific fields or parameters attached to the event. It's quite…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
-
(Locked)
Introducing the publish/subscriber pattern2m 4s
-
(Locked)
Exploring a use case for the publish/subscriber pattern1m 57s
-
(Locked)
The publish/subscriber pattern in action1m 6s
-
(Locked)
Challenge: Apply the publish/subscriber pattern51s
-
(Locked)
Solution: Apply the publish/subscriber pattern1m 4s
-
(Locked)
-
-
-
-