How Symfony HTTP Object Works

Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

Introduction To

Symfony 2 Internal
Abouzar Kamaee
([email protected])


Overview

Introduction

Component

Framework Bundle

Handling Reue!t


Introduction

"#at e$actl% !%m&on% i! '


Ba!ed on o&&icial document! (%m&on% i! a )H) Framework* a
)#ilo!op#%* and a Communit% + all working toget#er in #armon%.

"#% !%m&on% '


(%m&on% i! not a &ramework but a pro,ect. -epending on %our
need!* %ou can c#oo!e to u!e !ome o& t#e (%m&on%
Component!* t#e (ile$ micro+&ramework* or t#e &ull+!tack
&ramework.


Introduction

"#% !%m&on% '


(%m&on% i! u!ed b% man% large companie! (like t#e BBC or
CB()* b% man% large web!ite! (like ./-* wetter.com* 0ocker!)
and !ome 1pen+(ource pro,ect! are al!o powered b% (%m&on%
(C2(e! like -rupal or e3publi!#* librarie! like )H)4nit or
-octrine* product! like p#pBB or !#opware* and e5en
&ramework! like ))I or 0ara5el).
(%m&on% en,o%! a #uge communit% o& u!er! and contributor!6
during t#e la!t %ear alone* 7789 people contributed to t#e
(%m&on% core and t#e communit% created o5er :*;88 bundle! &or
t#e &ull+!tack &ramework. (%m&on% al!o #a! !e5eral annual
dedicated con&erence! around t#e world and a large number o&
u!er group!.


Introduction

"#% !%m&on% '


(%m&on% #a! been created in <887 and #ere to !ta%. Be!ide!
(en!io0ab!* man% ot#er companie! rel% on (%m&on% &or t#eir
client! and t#e% contribute* in5e!t mone%* and !pon!or t#e &uture
o& t#e pro,ect.
(%m&on% embrace! t#e =don>t rein5ent t#e w#eel= p#ilo!op#%*
and pro5ide! tig#t integration wit# man% ot#er 1pen+(ource
pro,ect! (like 2onolog* A!!etic* -octrine* )ropel* ...).





Component

/5er%t#ing i! bundle

/a!% to u!e t#ird part bundle!

/a!% to implement %our!el& bundle!




Component

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

.#e Framework Bundle i! t#e bundle


t#at tie! t#e main component! and
librarie! toget#er to make a lig#tweig#t
and &a!t 2?C &ramework. It come! wit#
a !en!ible de&ault con&iguration and
con5ention! to ea!e t#e learning cur5e.


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 #

An!wer Ke% i! /5ent -i!patc#er 6)


.#e (%m&on%< /5ent -i!patc#er component implement! t#e
2ediator pattern in a !imple and e&&ecti5e wa% to make all t#e!e
t#ing! po!!ible and to make %our pro,ect! trul% e$ten!ible.


But How !vent "re Fired #

A li!tener ()H) ob,ect) tell! a central di!patc#er ob,ect t#at it


want! to li!ten to t#e kernel.re!pon!e e5ent6

At !ome point* t#e (%m&on%< kernel tell! t#e di!patc#er ob,ect to


di!patc# t#e kernel.re!pon!e e5ent* pa!!ing wit# it an /5ent
ob,ect t#at #a! acce!! to t#e Re!pon!e ob,ect6

.#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.

You might also like