D
D
Dmitry Andreenko2020-02-11 21:45:07
PHP
Dmitry Andreenko, 2020-02-11 21:45:07

Plugins for web application. How does it work and how to implement?

Greetings!

Here's a noob question...
How to add plugin support to the engine I'm writing?
Just create a controller, assign routings to it, that's understandable, but...

1. How to enable/disable plugins? If you change the state in the database, then when you start the application, you will need to get a list of active plugins with which you will then need to work (load their configs, classes ...)
If everything is clear with configs and controllers, then with entities the question is: if data about included plugins are stored in the database, how to initialize Doctrine (it is used in the project) before getting all active plugins?
Those. during initialization, it is given an array with folders of entities to work with, but how to load plug-in entities if their list is received after initialization? Re-initialize?

2. How to extend existing application classes?
Just extends doesn't seem like a good idea to me, because if multiple plugins extend the same class, it won't work...
I.e. again, you need to get a list of plugins that extend this class, and then run each of them so that each one works.
It’s clear in words, but how to extend one class to another in code?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey delphinpro, 2020-02-11
@delphinpro

The plugin system can be based on events.
For example, somewhere in your application you call a subroutine X that does something useful, and you want to allow plugins to change or add to the result of those actions. Then you, before or after calling subroutine X, notify the system with a certain event that some code can now be executed. If a plugin is subscribed to this event, it is called, the initial data is passed to it, to which it does something and returns the result of the work to the system. Along with the data, the plugin can be passed all the interfaces necessary for operation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question