I am looking to create a plugin manager like program which starts a loop that searches for .php files in the ‘plugins’ folder. I need this to somehow run a function called main() in each file which will then run other functions. How could i accomplish this without the other main() functions clashing and would there be any better alternative?
I am looking to create a plugin manager like program which starts a loop
Share
If you want to use functions then you can namespace them. But for something like this id use classes. for example each plugin might have a
PluginConfigurationclass which could either be namespaced likePluginName\PluginConfigurationor faked likePluginName_PluginConfiguration.Then you could jsut instatiate these classes and invoke whatever for example:
UPDATE:
Well an interface defines all methods (functions) a class must implement. You can use it to enforce a minimum API on any class the
implementsthat interface. From your description this would be the methodmainalthough during development you may find that you need/want to add more.You can also use type hinting to enforce a specific method signature. For example lets say you always want to inject the
Applicationinstance thats loading the plugin into the plugin itself so it can register things or set up additional stuff. In that case you might do: