php - Autoloader for OOP project -


i'm busy big wordpress plugin consist of couple of classes , interfaces (which use proper namespacing). research , answers got previous questions, best option use interface injection (dependency injection) maintain soc. @ stage work intended.

i'm left bringing 1 main class used contoller. @ moment, test everything, use require_once in order load classes , interfaces (files in 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 autoloaders, not understand how use them in controller class. 1 issue need avoid class loaded before interface, because if load sequence wrong, fatal error stating interface not exist.

my question:

how make use of autoloader in controller class load classes , intefaces makes sure interfaces loaded before respective classes

use composer autoloading classes. supports namespaces autoloading and, once setup, automatic in own namespaces.

all have setup composer.json

"autoload": {         "psr-4": {"acme\\": "src/"}     } 

just require aotoload.php , manage else.

require __dir__ . '/vendor/autoload.php'; 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -