I'm currently busy with a big WordPress plugin which consist of a couple of classes and interfaces (which use proper namespacing). From research and what answers I got from previous questions, the best option was to use interface injection (dependency injection) to maintain SOC. Everything at this stage work as intended.
I'm left now with bringing everything together into one main class which will be used as a contoller. At this moment, to test everything, I use require_once
in order to load my classes and interfaces (files are in a folder called functions
)
EXAMPLE:
require_once( '/functions/INTERFACEA.php' );
require_once( '/functions/CLASSA.php' );
require_once( '/functions/INTERFACEB.php' );
require_once( '/functions/CLASSB.php' );
//etc
I have heard about autoloaders, but does not completely understand how to use them in a controller class. One issue that I really need to avoid is that a class is loaded before its interface, because if the load sequence is wrong, I get a fatal error stating that my interface does not exist.
MY QUESTION:
How do I properly make use of an autoloader in a controller class to load my classes and intefaces which also makes sure that my interfaces are loaded before their respective classes