The head cook

Exercise 7 of 8 in chapter 1 · 150 XP · 5 objectives checked by tests

Topics covered: ServiceAutowiringDependency injection

Gorm finally hires a cook: Bruna, a dwarf who flatly refuses to let the list of dishes lie around the dining room (read: in the controller). The kitchen is her domain.

In Symfony, business logic lives in services: plain PHP classes that the container creates for you and injects wherever they are asked for.

Your mission

  1. Complete the App\Service\Cuisine (kitchen) service:
    • tousLesPlats() (all the dishes): the list of dishes, by slug (move the controller's PLATS constant here);
    • plat(string $slug): one dish, or null if it doesn't exist;
    • platDuJour() (dish of the day): the house specialty.
  2. Make MenuController use the Cuisine (menu and dish pages): the controller must no longer contain the list of dishes.
  3. On the home page, announce the dish of the day in <p class="plat-du-jour">.

Reminder

No configuration to write: thanks to autowiring, typing an argument (Cuisine $cuisine) in an action or a constructor is enough for Symfony to provide the service.