root@localdomain Posted May 11, 2011 Share Posted May 11, 2011 Hi all, I am working on php project and willing to use the "everything as a plugin" idea so alot of people can easily contribute. I am wondering how I can make a php page that includes my plugins, without having to hardcode them(as in require_once, ...). And afterwards it should be possible to execute a function on each of the enabled plugins. Especially the "hardcode" part I am not sure on how to fix it. As for executing a function for each plugin (so that will be a Class object), I wonder how I can make an object of each class from an interface and then execute a function without hardcoding the creation of all objects. Any one ideas or experience with something like this? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
requinix Posted May 11, 2011 Share Posted May 11, 2011 If you put all the plugins in one directory, you can // includes a file without giving it direct access to any variables // note that it could still use stuff like global $var; function include_once_clean() { include_once func_get_arg(0); } foreach (glob("/path/to/plugins/*.php") as $file) include_once_clean($file); From there it's up to your imagination. Quote Link to comment Share on other sites More sharing options...
root@localdomain Posted May 20, 2011 Author Share Posted May 20, 2011 Thanks for your suggestion. In the end I implemented the includes using the database of the application. So if you have a new plugin installed you need to run a scan script. It reads each subdirectory of plugins/ and gets a plugin info file. The include statement, the class name and the plugin name are read and put in the database. The admin gets a list of installed plugin and can enable them (uses a database column). When the user calls a page that uses plugins, the installed and enabled plugins are used/shown. So the plugin php page gets included (as is in the plugin info file) and an object is created using the name that is also retrieved from the plugin info file (and put in the database when scanning of course). Hope this helps anyone else that is trying to do the same. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.