StackOverflow!
I'm looking for a way to make plugin-like (I didn't know how to call it) web application with PHP. With that I meant that I want to make system where user can add/remove plugins (extensions, if you like) via browser (not by adding some code to configuration). Good example is WordPress, in my opinion. End-user can simply install any kind of plugins and by doing almost nothing they work as expected and, very often, have a lot of settings to change and so on.
Also, I would love to make it as usable as possible. With that I meant that a plugin can use parts of other plugins so there are less rewritten code. For example, there are plugin that is for authorization/authentication and all other stuff that is related to users. Then, there are plugin that is for blog. Blog, of course, needs before mentioned, right? So it simply uses that before mentioned plugin to work. I understand that there will be a lot of dependencies and so on... but its just normal. :)
My question is... with what technique I can accomplish it? What are advantages and disadvantages of that kind of system? I assume that it will be a little slower and will not fit very huge sites like Facebook (okay, that's just too huge), but for simple blogs, portfolios, whatever it will be just fine!
I have heard about event-driven programming (or event-based programming) and I have read article about it on Wikipedia, but still... I'm very confused and, even more, not sure that its the thing that I'm looking for.
Thanks for reading this. Give me some answers, if its possible. :D
There are multiple issues to consider. As you noted a plugin system depends on registering extensions with the application, and the extension itselfs need a way to hook into the main application.
For all its faults, Wordpress has a quite workable approach to this. It uses "hooks" for interfacing to plugins. That's basically a callback-system which more or less can amount to "event-driven" too. Fundamentally the main application does something like:
foreach ($callback["need_to_render_sidebar"] as $fn) {
$fn();
}
But you can make it more flexible with passing extra parameters, returning data, and more importantly: using objects rather than procedural callbacks for more complex features. (I'd avise to mix and match. There's not one approach that suits all applications or extensions.)
Likewise a plugin system often enables the extensions itself to call back the main application, feed data into it, or modify settings.
The second part you need to consider for a plugin system is how you make it manageable. There basically each WebCMS/DMS has its own approach. Many use zip files to be manually extracted, or module directories. For starters a WP-like approach of meta-data augmented script files is the most suitable. I made a similar system which can be used independently of WP, though it's pretty rough: http://milki.include-once.org/genericplugins/ (the nice part is actually the manageability of settings.)
Just a simple concept.
You can use extensions as PHP classes and store them in separate files in one (or several) directory(-ies). You have to initialize extensions in the main application by going through the extension files and creating objects of these classes.
Adding new extension will consist of adding new class file to a directory. You can also add enable/disable functionality within extension or managed in the main application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With