Goodbye, homemade autoloader

Exercise 3 of 4 in chapter 4 · 100 XP · 3 objectives checked by tests

Topics covered: vendor/autoload.phpComposerAutoload

Composer now knows how to load the gazette's classes. Your autoloader served you well: it can retire.

Your mission

  1. In public/index.php, replace the call to spl_autoload_register() with a single line that loads Composer's autoloader: require __DIR__ . '/../vendor/autoload.php';.
  2. Check that the front page still shows, weather report included.

Reminder

vendor/autoload.php is the only file a Composer project loads by hand. It registers the autoloader for your classes (the PSR-4 rule) and the one for every dependency installed in vendor/. That's how, in the next chapter, a downloaded router will become usable in a single line.