Junior — Middle
How can automatic class loading be configured using Composer?
sobes.tech AI
Answer from AI
Automatic class loading in Composer is configured through the autoload section in the composer.json file. Main methods:
- PSR-4 autoloading — maps namespaces to directories.
- PSR-0 autoloading — an older standard similar to PSR-4.
- classmap — specifies specific files or directories to scan.
- files — loads specified files directly.
Example PSR-4 configuration:
{
"autoload": {
"psr-4": {
"App\\": "src/"
}
}
}
After changing composer.json, run composer dump-autoload to update the autoloader.