Closed on Mondays

Exercise 1 of 6 in chapter 9 · 270 XP · 5 objectives checked by tests

Topics covered: Kernel eventskernel.request#[AsEventListener]RequestEventClockInterface

On Mondays, Bruna goes to the market and Gorm counts the barrels: the tavern is closed. Until now, Pippin hung a sign on the door, but the website keeps taking reservations. We need a rule that applies to every dining room page, without touching each controller.

Kernel events

For every request, Symfony announces the steps of its work as events: kernel.request (the request arrives), kernel.controller, kernel.response, kernel.exception… Any service can listen to them. That's how the router, the firewall and the profiler work.

And when a kernel.request listener provides a response itself, Symfony does not call the controller.

Your mission

Complete the FermeLeLundi (closed on Mondays) listener:

  1. on Mondays, the dining room pages (the routes in SALLE, the dining room) respond 503 with the fermeture.html.twig (closing) page;
  2. on the other days, nothing changes;
  3. the kitchen, the guild API and the login page stay open;
  4. an unknown page stays a 404.

Read the time from the clock ($horloge) received in the constructor, not with new \DateTimeImmutable(): that's what lets the tests pick the day. In development, Pippin even stopped the clock on a Monday at noon (config/packages/horloge.yaml): the preview must show the closing page.