Subfolders

Exercise 4 of 4 in chapter 4 · 150 XP · 5 objectives checked by tests

Topics covered: NamespacesusePSR-4Composercomposer dump-autoload -o

The src/ folder is filling up, so Madame Lou did some tidying: everything that gets published went into src/Contenu/ (content), and Gaston's weather report into src/Meteo/ (weather). The files have moved, but their namespaces stayed at the old address, and the front page no longer shows.

Your mission

  1. In each moved file, make the namespace match the folder: namespace Gazette\Contenu; in src/Contenu/, namespace Gazette\Meteo; in src/Meteo/.
  2. Bulletin implements Publication, which is no longer in its namespace: import it with use.
  3. In public/index.php, import the classes under their new names.
  4. In the console, composer dump-autoload -o reports the misplaced classes: run it again until there are none left.

The old files in src/ now contain nothing but a comment: they don't get in the way, you can leave them.

Reminder

With PSR-4, the namespace is the address of the file: Gazette\Contenu\Article lives in src/Contenu/Article.php, and nowhere else. use works in every file, including those in src/, as soon as a class uses one from another namespace.