The tavern's settings

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

Topics covered: Environment variables#[Autowire(env:)]int: and csv: processors.env.env.test

Gorm is off traveling for a month: Bruna takes over the tavern. She would rather close on Wednesdays, and her ravens fly to other lands. But everything is hard-coded: '1' for Monday, 'Gorm' for the innkeeper, three lands in the aviary controller. To change a setting, you would have to change the code and deploy again.

Environment variables

What changes from one server to another (or from one month to the next) does not belong in the code, but in environment variables. Symfony reads them from the server's real environment, and failing that from the .env files:

A service receives a variable with #[Autowire(env: '…')].

Your mission

Make the tavern configurable, without changing its default behavior:

  1. JOUR_DE_FERMETURE (closing day): the day the dining room is closed (1 = Monday… 7 = Sunday, 0 = never). 1 by default, and 0 in test: the tests of the following chapters don't have to fear Mondays;
  2. TAVERNIER (innkeeper): who is notified of new dishes (Gorm by default);
  3. CONTREES_DE_LA_VOLIERE (the aviary's lands): the lands whose winds the aviary shows, separated by commas;
  4. a closing day that is not a number (“monday”) must be rejected, not read as 0.

What about secrets?

A password or an API key is a setting too, but it must never be committed in .env. Symfony offers a vault (secrets:set), encrypted and safe to commit, whose decryption key stays on the server. The chapter's lesson comes back to it.