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

The publish/subscriber pattern in action - PHP Tutorial

From the course: PHP: Design Patterns

Start my 1-month free trial

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…

Contents