|
| 1 | +# Resource Lifecycle |
| 2 | + |
| 3 | +Each operation on a resource follows a well-defined lifecycle. |
| 4 | +This flow ensures clear separation of concerns between reading data, applying business logic, and producing the final response. |
| 5 | + |
| 6 | +```mermaid |
| 7 | +flowchart TD |
| 8 | + A[Request] --> B[Routing & Metadata] |
| 9 | + B --> C[Provider] |
| 10 | + C --> D[Processor] |
| 11 | + D --> E[Responder] |
| 12 | + E --> F[Response] |
| 13 | +
|
| 14 | + subgraph ProviderPhase [Provider Phase] |
| 15 | + direction LR |
| 16 | + C1[Load existing resource] |
| 17 | + C2[Create new instance] |
| 18 | + C3[Hydrate resource from request] |
| 19 | + C4[Validate resource] |
| 20 | + end |
| 21 | +
|
| 22 | + subgraph ProcessorPhase [Processor Phase] |
| 23 | + direction LR |
| 24 | + D1[Apply business logic] |
| 25 | + D2[Persist resource] |
| 26 | + D3[Dispatch domain events] |
| 27 | + end |
| 28 | +
|
| 29 | + subgraph ResponderPhase [Responder Phase] |
| 30 | + direction LR |
| 31 | + E1[Render template or redirect] |
| 32 | + E2[Return HTTP response] |
| 33 | + end |
| 34 | +
|
| 35 | + C --> ProviderPhase |
| 36 | + D --> ProcessorPhase |
| 37 | + E --> ResponderPhase |
| 38 | +
|
| 39 | + style ProviderPhase fill:#f4f8ff,stroke:#93c5fd,stroke-width:1px |
| 40 | + style ProcessorPhase fill:#fef9c3,stroke:#facc15,stroke-width:1px |
| 41 | + style ResponderPhase fill:#fef2f2,stroke:#f87171,stroke-width:1px |
| 42 | +``` |
| 43 | + |
| 44 | +## Step-by-step explanation |
| 45 | + |
| 46 | +### Routing & Metadata |
| 47 | +The request is matched to a `Resource` and an `Operation` using metadata collected from attributes (eg `#[AsResource]`). |
| 48 | +This step defines which provider, processor, and responder should handle the request. |
| 49 | + |
| 50 | +### Provider Phase |
| 51 | +The provider is responsible for loading or creating the resource object, hydrating it from the request, and validating it before any business logic is applied. |
| 52 | + |
| 53 | +**Example:** load from Doctrine, create a new instance, populate from request data, validate, or fetch from an external API. |
| 54 | + |
| 55 | +### Processor Phase |
| 56 | +The processor applies the business logic of the operation. |
| 57 | + |
| 58 | +**Example:** persist the entity, execute domain services, or dispatch events. |
| 59 | + |
| 60 | +You can use the default Doctrine processor, or implement your own for DDD use cases. |
| 61 | + |
| 62 | +### Responder Phase |
| 63 | +The responder produces the final output — it can render a Twig template or redirect to another route. |
0 commit comments