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.
Solution: Apply the publish/subscriber pattern - PHP Tutorial
From the course: PHP: Design Patterns
Solution: Apply the publish/subscriber pattern
- This one took a little more. Unlike our after code from before, we couldn't just call the methods and be done with it. As our first step we needed a Dispatcher. Which we could just copy from the after code if we wanted to. Once we have a Dispatcher we needed to register all of our listeners in index.php, which we did here. All that should look pretty familiar. Of course, if we stop there, we end up with our count being off. You should see the count be the number two twice. Definitely not what we want. This is because when C is triggered off of A the value from B triggering has not been passed along to C. So this is what we need to modify. This is where things get different in that our input value is supposed to change over time. Therefore, our addOneAndEcho needs to return the result it just generated. So you can return that here. And another difference is the Dispatcher needs to catch that result here and feed it back into the method next time. Notice that the publish method now…
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)
-
-
-
-