How to make a plugin-like web application with PHP?

Stackoverflow

I am looking for a way to make a plugin (as I do not know it) a web application with PHP. With this, I meant that I want to create a system in which the user can add / remove plugins (extensions, if you want) through the browser (not by adding some code to the configuration). A good example is WordPress, in my opinion. The end user can simply install any plugins and work almost nothing as expected, and very often has many settings for changes, etc.

In addition, I would like to make it as convenient as possible. With this, I meant that the plugin can use parts of other plugins, so there is less rewritten code. For example, there is a plugin that is designed for authorization / authentication and all other things related to users. Then there is a blog plugin. A blog, of course, needs to be mentioned before, right? Therefore, he simply uses this before the mentioned plugin will work. I understand that there will be many dependencies, etc .... but this is normal. :)

My question is ... with what technique can I do this? What are the advantages and disadvantages of such a system? I assume that it will be a little slower and will not put very large sites such as Facebook (well, that's too much), but for simple blogs, portfolios, whatever that is!

I heard about event-based programming (or event-based programming), and I read the Wikipedia article about it, but still ... I am very confused and, moreover, not sure if this is what I am looking for.

Thanks for reading this. Give me some answers if possible .: D

+4
source share
2 answers

There are several issues. Since you noticed that the plug-in system depends on the registration of extensions with the application, and the extension itself needs a way to connect to the main application.

With all its errors, Wordpress has a perfectly acceptable approach to this. It uses interceptors to interact with plugins. It is basically a callback system that can more or less constitute an "event driven" one. Basically the main application does something like:

foreach ($callback["need_to_render_sidebar"] as $fn) { $fn(); } 

But you can make it more flexible with passing additional parameters, returning data, and, more importantly: using objects, rather than procedural callbacks for more complex functions. (I would like to mix and match. There is not one approach that is suitable for all applications or extensions.)

Similarly, the plug-in system often allows internal users to redirect the main application, insert data into it, or change settings.

The second part that you need to consider for the plugin system is how you make it manageable. There basically every WebCMS / DMS has its own approach. Many use zip files that need to be manually extracted or module directories. For starters, the most appropriate is a WP-like approach to metadata, supplemented by script files. I made a similar system that can be used independently of WP, although it is rather crude: http://milki.include-once.org/genericplugins/ (the nice part is actually manageability settings.)

+6
source

A simple concept.

You can use extensions as PHP classes and store them in separate files in one (or several) directories (-ies). You must initialize extensions in the main application by looking at extension files and creating objects of these classes.

Adding a new extension will consist of adding a new class file to the directory. You can also add on / off functions to the extension or control in the main application.

+2
source

All Articles