The life of a reservation

Exercise 3 of 6 in chapter 10 · 280 XP · 5 objectives checked by tests

Topics covered: WorkflowState machinePlaces and transitionsmarking_storeinitial_marking

A reservation has a life: requested by a traveler, confirmed by the tavern, then honored when the evening comes. Unless someone cancels it in the meantime. Today, nothing prevents it from being honored without having been confirmed, or canceled after the meal.

Pippin has added a statut (status) to reservations. Rather than scattering if ($statut === …) everywhere, the tavern will describe this life cycle once, and let Symfony enforce it.

The Workflow component

A workflow describes places (the possible states) and transitions (the allowed moves from one place to another). When an object can only be in one place at a time, it is a state machine (state_machine). The workflow knows:

Your mission

  1. In config/packages/workflow.yaml, describe the reservation state machine:

    Transition from to
    confirm requested confirmed
    honor confirmed honored
    cancel requested or confirmed canceled

    A new reservation starts at requested, and the place is stored in the statut property.

  2. Reservations from the website and those from the guilds (the API) are saved as requested.

In the console, workflow:dump reservation --dump-format=mermaid describes your machine as a diagram.