How Symfony HTTP Object Works
How Symfony HTTP Object Works
How Symfony HTTP Object Works
Symfony 2 Internal
Abouzar Kamaee
([email protected])
Overview
Introduction
Component
Framework Bundle
Handling Reue!t
Introduction
/5er%t#ing i! bundle
HttpFoundation Component
de&ine! an ob,ect+oriented la%er &or t#e H..) !peci&ication.
Implement! Reue!t* Re!pon!e and (e!!ion
HttpKernel Component
1n top o& HttpFoundation i! t#e HttpKernel component.
HttpKernel #andle! t#e d%namic part o& H..)6 it i! a t#in wrapper
on top o& t#e Reue!t and Re!pon!e cla!!e! to !tandardize t#e
wa% reue!t! are #andled.
Framework Bundle
Kernel
.#e HttpKernel cla!! i! t#e central cla!! o& (%m&on%< and i!
re!pon!ible &or #andling client reue!t!. It! main goal i! to
=con5ert= a Reue!t ob,ect to a Re!pon!e ob,ect.
/5er% (%m&on%< Kernel implement! HttpKernelInter&ace@
&unction #andle(Reue!t Areue!t* At%pe* Acatc# )
Framework Bundle
Controller!
.o con5ert a Reue!t to a Re!pon!e* t#e Kernel relie! on a
=Controller=. A Controller can be an% 5alid )H) callable.
.#e Kernel delegate! t#e !election o& w#at Controller !#ould be
e$ecuted to an implementation o& ControllerRe!ol5erInter&ace@
public &unction getController(Reue!t Areue!t)6
public &unction getArgument!(Reue!t Areue!t* Acontroller)6
Handling Requet
:. Be&ore doing an%t#ing el!e* t#e kernel.reue!t e5ent i! noti&ied ++
i& one o& t#e li!tener! return! a Re!pon!e* it ,ump! to !tep B
directl%6
<. .#e Re!ol5er i! called to determine t#e Controller to e$ecute6
C. 0i!tener! o& t#e kernel.controller e5ent can now manipulate t#e
Controller callable t#e wa% t#e% want (c#ange it* wrap it* ...)6
D. .#e Kernel c#eck! t#at t#e Controller i! actuall% a 5alid )H)
callable6
7. .#e Re!ol5er i! called to determine t#e argument! to pa!! to t#e
Controller6
Handling Requet
;..#e Kernel call! t#e Controller6
E.I& t#e Controller doe! not return a Re!pon!e* li!tener! o& t#e
kernel.5iew e5ent can con5ert t#e Controller return 5alue to a
Re!pon!e6
B.0i!tener! o& t#e kernel.re!pon!e e5ent can manipulate t#e
Re!pon!e (content and #eader!)6
F..#e Re!pon!e i! returned.
Handling Requet
;..#e Kernel call! t#e Controller6
E.I& t#e Controller doe! not return a Re!pon!e* li!tener! o& t#e
kernel.5iew e5ent can con5ert t#e Controller return 5alue to a
Re!pon!e6
B.0i!tener! o& t#e kernel.re!pon!e e5ent can manipulate t#e
Re!pon!e (content and #eader!)6
F..#e Re!pon!e i! returned.
But How !vent "re Fired #
.#e di!patc#er noti&ie! (i.e. call! a met#od on) all li!tener! o& t#e
kernel.re!pon!e e5ent* allowing eac# o& t#em to make
modi&ication! to t#e Re!pon!e ob,ect.