The autoloader you wrote in the previous chapter follows a simple rule: the Gazette\ prefix matches the src/ folder. This rule is so common that it has a name, PSR-4, and Composer knows how to apply it. All you have to do is declare it.
Your mission
- In
composer.json, add anautoloadsection, at the same level asrequire(not inside it), that maps, with PSR-4, theGazette\prefix to thesrc/folder. - In the console, run
composer dump-autoload: Composer rereadscomposer.jsonand regeneratesvendor/autoload.php. - Run the tests. They load
Gazette\Articlewithout your autoloader, using only Composer's.
public/index.php keeps its autoloader for now: you'll replace it in the next exercise.
Reminder
PSR-4 is a recommendation shared by PHP projects: a namespace prefix matches a folder, and the rest of the class name matches the path of the file. Gazette\Meteo\Bulletin lives in src/Meteo/Bulletin.php. Composer doesn't reread composer.json on every request: after changing the autoload section, run composer dump-autoload again.