Design pattern for implementing plugins in PHP applications Design pattern for implementing plugins in PHP applications php php

Design pattern for implementing plugins in PHP applications


There is no consensus as in the Silver Bullet sense. For established patterns, you have multiple options like

to name a few.

Which you use is up to you, but you should make sure your system architecture supports the modularity. Have a look at these slides for some ideas


I think an Events Dispatcher is a nice and clean way to implement plugins, or any extension for that matter. An Events Dispatcher is an implementation of the Observer pattern, and is being used in symfony, Symfony2 and Zend Framework 2 (beta).

Looking through any of that source on github will make for some interesting reading. Though, an interesting bit of information can be found here:

http://components.symfony-project.org/event-dispatcher/trunk/book/02-Recipes

I wrote an Events and Hooks class a few years back for a project, I'll post that here if I can find it.


Take a look at the Yii framework. Yii heavily relies on events which are much cleaner than hooks, actions, etc. Using events, you can allow different parts of the system to talk to each other in an object oriented manner.