I would like to create a plugin system where a plugin is simply a file located in specific directory. Contradicting the autoloading principle, I want all files in that directory to be include-d with corresponding class (still 1 file 1 class, implementing an interface I created) instance created and registered to events the class wants to listen to by using EventsManager
.
In my previous project, I use glob()
to iterate all files found, then use file_get_contents()
to extract the contents and finally preg_match()
to get the class name along with checking to see if the class implements the interface (regex: class\s+(\w+)\s+implements\s+TheInterfaceClass). This is not only ugly and cumbersome, but also doesn't cover all possible legal coding styles.
So, I would like to ask if there's either any better way to get what I want, or another plugin system approach where (un)installation of a plugin is a matter of moving the plugin file out of a specific directory. Thank you.