Autoloading is done automatically using Composer assuming you've downloaded the dependencies from modules stated in the require
key of your composer.json
file. Just include this at the top of your PHP script to access the Classes:
require_once __DIR__.'/to/vendor/autoload.php';
If these are manually downloaded packages you'll need to point the autoloader to them and run composer update
:
"autoload": {
"psr-0": {
"Util\\": "assets/"
},
"files": ["assets/Util/init.php"]
}
The above automatically:
- appends the script at
assets/Util/init.php
to every file where the autoloader is run; - and autoloads classes from, in this example, the Util namespace (has to be in a folder called Util to meet psr-0 convention so is actually at
assets/Util/
) into any file that runs the autoloader
You may also need to manage namespace issues using the use Namespace\Class as Class;
syntax.