Skip to content

Commit b0f5fbf

Browse files
authored
[Docs] Add Resource Lifecycle (#299)
2 parents 13e40bc + c5258f2 commit b0f5fbf

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

docs/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
* [Resource Bundle documentation](resource/index.md)
3434
* [Installation](resource/installation.md)
35+
* [Resource Lifecycle](resource/lifecycle.md)
3536
* [Create new resource](resource/create_new_resource.md)
3637
* [Configure your resource](resource/configure_your_resource.md)
3738
* [Configure your operations](resource/configure_your_operations.md)

docs/resource/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ So far we support:
1919
* [Installation](installation.md)
2020

2121
# New documentation
22+
* [Resource lifecycle](lifecycle.md)
2223
* [Create a new resource](create_new_resource.md)
2324
* [Configure your resource](configure_your_resource.md)
2425
* [Configure your operations](configure_your_operations.md)

docs/resource/lifecycle.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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

Comments
 (0)