@@ -27,9 +27,14 @@ The Workflow of a Request
27
27
Every HTTP web interaction begins with a request and ends with a response.
28
28
Your job as a developer is to create PHP code that reads the request information
29
29
(e.g. the URL) and creates and returns a response (e.g. an HTML page or JSON string).
30
+ This is a simplified overview of the request workflow in Symfony applications:
30
31
31
- .. image :: /_images/components/http_kernel/request-response-flow.png
32
- :align: center
32
+ #. The **user ** asks for a **resource ** in a **browser **;
33
+ #. The **browser ** sends a **request ** to the **server **;
34
+ #. **Symfony ** gives the **application ** a **Request ** object;
35
+ #. The **application ** generates a **Response ** object using the data of the **Request ** object;
36
+ #. The **server ** sends back the **response ** to the **browser **;
37
+ #. The **browser ** displays the **resource ** to the **user **.
33
38
34
39
Typically, some sort of framework or system is built to handle all the repetitive
35
40
tasks (e.g. routing, security, etc) so that a developer can easily build
@@ -62,8 +67,9 @@ the concrete implementation of :method:`HttpKernelInterface::handle() <Symfony\\
62
67
defines a workflow that starts with a :class: `Symfony\\ Component\\ HttpFoundation\\ Request `
63
68
and ends with a :class: `Symfony\\ Component\\ HttpFoundation\\ Response `.
64
69
65
- .. image :: /_images/components/http_kernel/01-workflow.png
66
- :align: center
70
+ .. raw :: html
71
+
72
+ <object data =" ../_images/components/http_kernel/http-workflow.svg" type =" image/svg+xml" ></object >
67
73
68
74
The exact details of this workflow are the key to understanding how the kernel
69
75
(and the Symfony Framework or any other library that uses the kernel) works.
@@ -149,9 +155,6 @@ layer that denies access).
149
155
The first event that is dispatched inside :method: `HttpKernel::handle <Symfony\\ Component\\ HttpKernel\\ HttpKernel::handle> `
150
156
is ``kernel.request ``, which may have a variety of different listeners.
151
157
152
- .. image :: /_images/components/http_kernel/02-kernel-request.png
153
- :align: center
154
-
155
158
Listeners of this event can be quite varied. Some listeners - such as a security
156
159
listener - might have enough information to create a ``Response `` object immediately.
157
160
For example, if a security listener determined that a user doesn't have access,
@@ -161,9 +164,6 @@ to the login page or a 403 Access Denied response.
161
164
If a ``Response `` is returned at this stage, the process skips directly to
162
165
the :ref: `kernel.response <component-http-kernel-kernel-response >` event.
163
166
164
- .. image :: /_images/components/http_kernel/03-kernel-request-response.png
165
- :align: center
166
-
167
167
Other listeners simply initialize things or add more information to the request.
168
168
For example, a listener might determine and set the locale on the ``Request ``
169
169
object.
@@ -216,9 +216,6 @@ to your application. This is the job of the "controller resolver" - a class
216
216
that implements :class: `Symfony\\ Component\\ HttpKernel\\ Controller\\ ControllerResolverInterface `
217
217
and is one of the constructor arguments to ``HttpKernel ``.
218
218
219
- .. image :: /_images/components/http_kernel/04-resolve-controller.png
220
- :align: center
221
-
222
219
Your job is to create a class that implements the interface and fill in its
223
220
method: ``getController() ``. In fact, one default implementation already
224
221
exists, which you can use directly or learn from:
@@ -286,9 +283,6 @@ some part of the system that needs to be initialized after certain things
286
283
have been determined (e.g. the controller, routing information) but before
287
284
the controller is executed. For some examples, see the Symfony section below.
288
285
289
- .. image :: /_images/components/http_kernel/06-kernel-controller.png
290
- :align: center
291
-
292
286
Listeners to this event can also change the controller callable completely
293
287
by calling :method: `FilterControllerEvent::setController <Symfony\\ Component\\ HttpKernel\\ Event\\ FilterControllerEvent::setController> `
294
288
on the event object that's passed to listeners on this event.
@@ -319,9 +313,6 @@ should be passed to that controller. Exactly how this is done is completely
319
313
up to your design, though the built-in :class: `Symfony\\ Component\\ HttpKernel\\ Controller\\ ArgumentResolver `
320
314
is a good example.
321
315
322
- .. image :: /_images/components/http_kernel/07-controller-arguments.png
323
- :align: center
324
-
325
316
At this point the kernel has a PHP callable (the controller) and an array
326
317
of arguments that should be passed when executing that callable.
327
318
@@ -362,9 +353,6 @@ of arguments that should be passed when executing that callable.
362
353
363
354
The next step is simple! ``HttpKernel::handle() `` executes the controller.
364
355
365
- .. image :: /_images/components/http_kernel/08-call-controller.png
366
- :align: center
367
-
368
356
The job of the controller is to build the response for the given resource.
369
357
This could be an HTML page, a JSON string or anything else. Unlike every
370
358
other part of the process so far, this step is implemented by the "end-developer",
@@ -374,9 +362,6 @@ Usually, the controller will return a ``Response`` object. If this is true,
374
362
then the work of the kernel is just about done! In this case, the next step
375
363
is the :ref: `kernel.response <component-http-kernel-kernel-response >` event.
376
364
377
- .. image :: /_images/components/http_kernel/09-controller-returns-response.png
378
- :align: center
379
-
380
365
But if the controller returns anything besides a ``Response ``, then the kernel
381
366
has a little bit more work to do - :ref: `kernel.view <component-http-kernel-kernel-view >`
382
367
(since the end goal is *always * to generate a ``Response `` object).
@@ -401,9 +386,6 @@ another event - ``kernel.view``. The job of a listener to this event is to
401
386
use the return value of the controller (e.g. an array of data or an object)
402
387
to create a ``Response ``.
403
388
404
- .. image :: /_images/components/http_kernel/10-kernel-view.png
405
- :align: center
406
-
407
389
This can be useful if you want to use a "view" layer: instead of returning
408
390
a ``Response `` from the controller, you return data that represents the page.
409
391
A listener to this event could then use this data to create a ``Response `` that
@@ -531,8 +513,9 @@ function is wrapped in a try-catch block. When any exception is thrown, the
531
513
``kernel.exception `` event is dispatched so that your system can somehow respond
532
514
to the exception.
533
515
534
- .. image :: /_images/components/http_kernel/11-kernel-exception.png
535
- :align: center
516
+ .. raw :: html
517
+
518
+ <object data =" ../_images/components/http_kernel/http-workflow-exception.svg" type =" image/svg+xml" ></object >
536
519
537
520
Each listener to this event is passed a :class: `Symfony\\ Component\\ HttpKernel\\ Event\\ GetResponseForExceptionEvent `
538
521
object, which you can use to access the original exception via the
@@ -688,8 +671,9 @@ a page instead of a full page. You'll most commonly make sub-requests from
688
671
your controller (or perhaps from inside a template, that's being rendered by
689
672
your controller).
690
673
691
- .. image :: /_images/components/http_kernel/sub-request.png
692
- :align: center
674
+ .. raw :: html
675
+
676
+ <object data =" ../_images/components/http_kernel/http-workflow-subrequest.svg" type =" image/svg+xml" ></object >
693
677
694
678
To execute a sub request, use ``HttpKernel::handle() ``, but change the second
695
679
argument as follows::
0 commit comments