I want to learn on how to do plugin based development ? For example i create a basic cms and then instead of bloating it with features which everyone may not require, how do i create those features in style of addons / plugins so the user just uploads the file and activates in admin area and its on.
Just like popular wordpress etc. how are they doing it and how can i do it ? Please provide me a head start.
In fact, I wouldn’t really recommend looking into how mos of open source software does it in code - most of the code in a lot of open source software is a complete mess.
And besides, if you copy how other people have done it, you won’t have anything unique
Try coming up with a plan of your own. Not only will you understand it better (and therefore accomplish it faster) but you will also have one hell of a learning experience!
I think most work using hooks for certain events - wordpress certainly does - eg, a plugin can hook into the ‘before post’ event or something and modify the content if it wants before the post is committed to the database, things like that.
In fact, I wouldn’t really recommend looking into how mos of open source software does it in code - most of the code in a lot of open source software is a complete mess.
The code might be a mess, but it’s the plugin architecture and concepts OP is after. You could study a system built in assembler and still get the gist of how things ‘tick’.
There is no head start in this game, OP, sorry. Anything cool takes years of study and dedication. Start building something you consider flexible, and you will learn a ton. Start using WordPress, Joomla, Drupal, etc and think about how they might have solved their problems.
Solve those same probems in your way, eventually you will encountrer concrete questions which can be answered with some degree of accuracy. Thats how you learn, asking to start building plugin based software is like asking how life formed on earth, such a vast question its impossible to answer in a single reply.
Start with a list of requirements and problems that you would like your plugin system to solve. Then start brainstorming and knock off the ideas that don’t work.
There are many, many ways to implement a plugin system, so you’ll find that they are implemented very differently between different software.
I too was giving this some thought recently (with equally little success so far). After reading this thread, as well as the linked ones, it appears to me that most of the replies focus on how to implement some sort of event system / observer pattern. However a just as interesting question in my opinion is, one that I’m struggling with, how one would integrate a plugin system that allows a plugin to add (or override) both business logic as well as UI elements into a MVC structure for instance…
I’m currently working on a site where a request to “x” controller and “y” action gets handled by method y() of a controller class located under “controllers/x_controller.php” and renders the template located under “views/x/y.php”… This separation and naming scheme allows for a fairly simple and clean dispatch logic.
On the other hand I was also thinking about including a plugin system that would allow the creation of various “display modules” (or widgets if you prefer) that could be included into the page at will. An ideal system would allow the plugin to supply both the template/view of the component (including various resources such as css files) as well as the necessary controller logic and perhaps even some admin module complete with its own admin controller and views…
The problem is that for a plugin to be easily installable etc. all its files need to live together, so that the entire plugin can be deployed as a single folder. (Though sub-folders are ok…) This however completely messes up you carefully laid out system/structure And what’s worse it makes locating the correct file to load/render a much more complicated issue… Finally, while I suppose that it is not strictly necessary for the actual files to be cleanly separated for the proper working of a MVC system, not doing so makes things a bit messier and more difficult to manage…
So, so far I’m still on the lookout for a system that elegantly merges object oriented design with both a MVC as well as a plugin based structure/layout…
Part of the problem with implementing a plugin system is that there needs to be a lot of hooks in your code. That greatly compounds complexity and opens the doors for potential mischief–malicious or otherwise.
The most common approach seems to be the 3-prong approach: BeforeAction(), duringAction(), AfterAction(). The most complicated portion is probably the hook for duringAction().
Those are hooks based on intercepting filters, I’d imagine: each request to a certain piece of code goes through a chain of filters, before actually processing the request. When the processing is done, it returns through the exact same chain, which allows you to have control over what is done before and after the actual processing.
The plugin systems of Drupal and Wordpress from what I gather, seem to be a little more primitive: they’ve decided to think for the plugin developers, calling implementations of hooks from inside of the processing code, passing all of the known values by reference and let the implementations of the hooks decide what is to happen next. A collection of those hooks working together is then called a “module”.
Phergie, an IRC bot written in PHP, essentially takes the hooks approach too: they have plugins classes that are children of an abstract plugin, which contains methods for almost(?) every action possible for the bot. Say for example, you want your plugin to respond to the text “hey”, you’d override the onPrivmsg( ) method, you’d inspect if the message contains the string “hey” and you respond accordingly.
The question which one is best is hard to answer, as I’ve never had the need to write such a hook system myself. Both methods seem to have their own up- and downsides. The “hook” implementation benefits greatly from clarity: it’s easy to explain, and easy to grasp. The filter approach seems to be a bit harder to get your head around, especially if the processing actions are not known up front.
I imagine the choice depends on the number of hooks, and if that number is finite. Phergie has a plugin system I like, but they can do that because the number of possible operations occuring on IRC are finite and limited. Drupal on the other hand, has more hooks everytime they have a new major version: as the application grows, the number of hooks would too. I’m guessing Wordpress does the same.
It allows you to add a hook to any method on any object… it is messy though. I was kinda hoping someone would be able to provide a better way of automagically wrapping classes as they’re defined.