docs(articles): English translation of From Magento to Symfony
en/articles/magento-to-symfony/basics/lifecycle.md
new file +32
−0
1
+
# The life of a request
2
+
3
+
In Magento a request goes through the FrontController, the router list and the action's `execute()`. In Symfony `HttpKernel` follows the same path, but every step is an event anyone can subscribe to: routing, security, argument conversion, exception handling. Understand this diagram, and most of Symfony's "magic" becomes ordinary event listeners.
4
+
5
+
```text
6
+
public/index.php
7
+
→ Kernel::handle(Request)
8
+
→ kernel.request RouterListener finds the route, then Firewall: who the user is
9
+
→ kernel.controller
10
+
→ ArgumentResolver Request, entities, DTOs
11
+
→ Controller
12
+
returned a Response → kernel.response
13
+
returned a non-Response → kernel.view → kernel.response
14
+
threw an exception → kernel.exception → kernel.response
15
+
→ Response::send()
16
+
→ kernel.terminate
17
+
```
18
+
19
+
| Symfony step | Closest in Magento | What happens there |
20
+
|---|---|---|
21
+
| public/index.php, Kernel | pub/index.php, Bootstrap, App\Http::launch() | Loading the compiled container. |
22
+
| kernel.request: RouterListener (priority 32) | FrontController::dispatch(), RouterList::match() | The route is written into the Request attributes. |
23
+
| kernel.request: Firewall (priority 8) | area + session, admin authentication plugin | Authentication, the user token. |
24
+
| kernel.controller | controller_action_predispatch, plugins on dispatch() | This is where #[IsGranted], #[Cache] fire. |
25
+
| ArgumentResolver | none; getParam() by hand | An entity by id, a DTO from JSON, the current user. |
26
+
| Controller | ActionInterface::execute() | Your code. |
27
+
| kernel.view | none | Turning a non-Response into a Response, e.g. #[Template]. |
28
+
| kernel.response | controller_front_send_response_before | Headers, cookies, the Web Profiler toolbar. |
29
+
| kernel.terminate | none | Work after the response is sent: logs, emails. |
30
+
| kernel.exception | ExceptionHandler, noroute | 404/403/500, error pages. |
31
+
32
+
To see all listeners and their priorities: `bin/console debug:event-dispatcher kernel.request`.