SlideShare uma empresa Scribd logo
1 de 66
Baixar para ler offline
ZFDAY - 2014

BUILD A CUSTOM (MICRO)FRAMEWORK
WITH ZF2 COMPONENTS AS BUILDING BLOCKS
Author Walter Dal Mut / @walterdalmut
WHO AM I?
Walter Dal Mut, I work at Corley S.r.l.
and also at UpCloo Ltd.
You can contact me at: walter.dalmut@gmail.com
On Twitter: @walterdalmut
On GitHub: wdalmut
WHY A CUSTOM FRAMEWORK?
Tipically because we want to solve a particular problem.
ZendFramework is a general purpose Web Framework that
can fit different problems easily.
IT SOUNDS LIKE REINVENTING THE WHEEL
NO, WE DON'T WANT!

We will use ZF2 components as building blocks
We will drive a personal behaviour
IT COULD WORK!!
REQUIREMENTS
Event Driven Design
Dependency Inversion Principle

TESTABLE/TDD
EVENT DRIVEN DESIGN
All framework operations are events (like ZF2)
DEPENDENCY INVERSION
We will focus on Service Manager
[ WE WANT TO TEST OUR APPLICATIONS ]
COMPOSE IT!
{

}

"eur" {
rqie:
"edrmwr/edeetaae" "."
znfaeokzn-vnmngr: 2*,
"edrmwr/edsrieaae" "."
znfaeokzn-evcmngr: 2*,
"edrmwr/edmc:"."
znfaeokzn-v" 2*,
"edrmwr/edht" "."
znfaeokzn-tp: 2*
}
,
"eur-e" {
rqiedv:
"hui/hui" ".."
ppntppnt: 37*
}
,
LET'S GO TO SCHOOL
We have to learn our building blocks!
THE EVENT MANAGER
$vnMngr=nwZnvnMngrEetaae(;
eetaae
e edEetaaevnMngr)
/ Tigra eet
/ rge n vn
pbi fnto tigr$vn,$agt=nl,$rv=nl)
ulc ucin rge(eet tre
ul ag
ul;
/ Atc alsee t a eet
/ tah
itnr o n vn
pbi fnto atc(eet $alak $roiy;
ulc ucin tah$vn, clbc, pirt)

There are many other methods (detach, triggerUntil, etc...)
See it on Github
HOW EVENT MANAGER WORKS?
pbi fnto tsEetaae(
ulc ucin etvnMngr)
{
$v =nwEetaae(;
e
e vnMngr)
$sald=fle
iCle
as;
$v>tah'neet,fnto(eet ue($sald {
e-atc(a-vn' ucin$vn) s &iCle)
$sald=tu;
iCle
re
};
)
$v>rge(a-vn";
e-tigr"neet)
}

$hs>setre$sald;
ti-asrTu(iCle)
THE SERVICE LOCATOR
$evcMngr=nwZnevcMngrSrieaae(;
srieaae
e edSrieaaeevcMngr)

"evcs = [
srie" >
"noals = [
ivkbe" >
"oraeop = "oraeop,
YuNmCm" > YuNmCm"
]
,
"atre"= [
fcois >
"oraeevc"= "oraeevcFcoy,
YuNmSrie > YuNmSrieatr"
]
,
"lae"= [
aiss >
"orais = "oraeevc"
yu.la" > YuNmSrie,
]
]

See it on Github
CONFIGURE S.L. FROM ARRAY
$evcMngr=nwZnevcMngrSrieaae(;
srieaae
e edSrieaaeevcMngr)
$ofg=nwZnevcMngrCni(
cni
e edSrieaaeofg[
"noals = [.]
ivkbe" > ..,
"atre"= [.]
fcois > ..,
"btatfcois = [.]
asrc_atre" > ..,
"lae"= [.]
aiss > ..
]
)
$ofg>ofgrSrieaae(srieaae)
cni-cniueevcMngr$evcMngr;
HOW SERVICE MANAGER WORKS?
pbi fnto tsSrieaae(
ulc ucin etevcMngr)
{
$m=nwSrieaae(;
s
e evcMngr)
$hs>ofg>ofgrSrieaae(s)
ti-cni-cniueevcMngr$m;
$hs>setre$m>a(eape);
ti-asrTu(s-hs"xml")

}

$hs>setae
ti-asrSm(
$m>e(eape)
s-gt"xml",
$m>e(eape)
s-gt"xml"
)
;
THE ROUTER
$t =ZnvotrHtreotSak:atr(ra $ofg;
rr
edMcRuetpTeRuetc:fcoyary cni)
"ots = [
rue" >
"otNm"= [
rueae >
"ye = "iea"
tp" > Ltrl,
"pin"= [
otos >
"ot"= "pt"
rue > /ah,
"eals = [
dfut" >
"otolr = "Fae,
cnrle" > ZNm"
"cin =>"cinae,
ato"
atoNm"
]
]
,
"a_emnt"= tu,
mytriae > re
]
]
$otMth=$t-mthRqet$eus)
rueac
rr>ac(eus rqet;
HOW ROUTER WORKS?
pbi fnto tsRueac(
ulc ucin etotMth)
{
$otr=TeRuetc:fcoy$hs>ofg;
rue
reotSak:atr(ti-cni)
$eus =nwRqet"pt";
rqet
e eus(/ah)
$otMth=$otr>ac(rqet;
rueac
rue-mth$eus)
$otolrae=$otrac-gtaa(cnrle";
cnrleNm
rueMth>ePrm"otolr)
$cinae=$otMth>ePrm"cin)
atoNm
rueac-gtaa(ato";

}

$hs>setqas"Fae,$otolrae)
ti-asrEul(ZNm" cnrleNm)
$hs>setqas"cinae,$cinae)
ti-asrEul(atoNm" atoNm)
REQUEST
/
/
$eus =nwedHthEvrnetRqet)
rqet
e ZntpPpniomneus(;
RESPONSE
$epne=nwedHthEvrnetRsos(;
rsos
e ZntpPpniomnepne)
$epne>dHaes[.];
rsos-adedr(..)
$epne>eCnet".";
rsos-stotn(..)
$epne>ed)
rsos-sn(;
HYDRATORS
pbi fnto etat$bet;
ulc ucin xrc(ojc)
pbi fnto hdaeary$aa $bet;
ulc ucin yrt(ra dt, ojc)
$lsMtos=nwedSdiyrtrCasehd(;
casehd
e ZntlbHdaolsMtos)
$betrp=nwedSdiyrtobetrpry)
ojcPo
e ZntlbHdarrOjcPoet(;
$ra =nwedSdiyrtoraSraial(;
ary
e ZntlbHdarrAryeilzbe)
LET'S START!
EVENTS!
THE FRAMEWORK EVENTS LIST
BEGIN

The loop begins

ROUTE

Parse the actual route in order to found a dispatchable action

PRE.FETCH

Before dispatch the action

EXECUTE

Dispatch all actions

RENDER

Render your data

FINISH

The loop ends
ON ERRORS?
BEGIN
ROUTE
PRE.FETCH
404/500/HALT
RENDER
FINISH
TEST IT!
pbi fnto tsBsAplw)
ulc ucin etaepFo(
{
$eus =Rqetatr:cetRqet"vldul,"E" [)
rqet
eusFcoy:raeeus(/ai-r" GT, ];
$p =nwAp)
ap
e p(;
$p-steus(rqet;
ap>eRqet$eus)
$p-stevcMngrnwZnevcMngrSrieaae()
ap>eSrieaae(e edSrieaaeevcMngr);
$p-stvnMngrnwZnvnMngrEetaae()
ap>eEetaae(e edEetaaevnMngr);
$epne=$p-rn)>epne)
rsos
ap>u(-rsos(;
}

$hs>setqas44 $epne>eSauCd()
ti-asrEul(0, rsos-gtttsoe);

F
FI ( tss 1asrin)
AL 1 et,
setos
REQUEST
pbi fnto steus(eus $eus)
ulc ucin eRqetRqet rqet
{
$hs>eus =$eus;
ti-rqet
rqet
}
pbi fnto rqet)
ulc ucin eus(
{
i ($hs>eus){
f !ti-rqet
$hs>eus =nwRqet)
ti-rqet
e eus(;
}
}

rtr $hs>eus;
eun ti-rqet
RESPONSE
pbi fnto stepneRsos $epne
ulc ucin eRsos(epne rsos)
{
$hs>epne=$epne
ti-rsos
rsos;
}
pbi fnto rsos(
ulc ucin epne)
{
i ($hs>epne {
f !ti-rsos)
$hs>epne=nwRsos(;
ti-rsos
e epne)
}
}

rtr $hs>epne
eun ti-rsos;
EVENT MANAGER
pbi fnto stvnMngr$vnMngr
ulc ucin eEetaae(eetaae)
{
$hs>vnMngr=$vnMngr
ti-eetaae
eetaae;
}
pbi fnto eet(
ulc ucin vns)
{
rtr $hs>vnMngr
eun ti-eetaae;
}
EVENT TRIGGER HELPER
pbi fnto tigr$ae ary$aas=[)
ulc ucin rge(nm, ra prm
]
{
$vn =nwEet)
eet
e vn(;
$vn-stagt$hs;
eet>eTre(ti)
$vn-staas$aas;
eet>ePrm(prm)
}

rtr $hs>vns)>rge(nm,$vn)
eun ti-eet(-tigr$ae eet;
SERVICE MANAGER
pbi fnto stevcMngr$evcMngr
ulc ucin eSrieaae(srieaae)
{
$hs>evcMngr=$evcMngr
ti-srieaae
srieaae;
}
pbi fnto srie(
ulc ucin evcs)
{
rtr $hs>evcMngr
eun ti-srieaae;
}
ENTRY POINT!
pbi fnto rn)
ulc ucin u(
{
$hs>rge(bgn)
ti-tigr"ei";
$vnsit=$hs>ipthsrcineaeEet(;
eetLs
ti-dsacUeAtoRltdvns)
$hs>rge(rne" [dt"= $vnsit)
ti-tigr"edr, "aa > eetLs];
$hs>rge(fns";
ti-tigr"iih)
}

rtr $hs
eun ti;
HEY, CAN YOU DO IT?
poetdfnto dsacUeAtoRltdvns)
rtce ucin ipthsrcineaeEet(
{
ty{
r
$vnsit=$hs>ipthsreus(;
eetLs
ti-dsacUeRqet)
}cth(atxeto $){
ac HlEcpin e
$vnsit=$hs>rge(hl";
eetLs
ti-tigr"at)
}cth(aeoFudxeto $){
ac PgNtonEcpin e
$hs>epne)>eSauCd(0)
ti-rsos(-stttsoe44;
$vnsit=$hs>rge(44)
eetLs
ti-tigr"0";
}cth(Ecpin$){
ac xeto e
$hs>epne)>eSauCd(0)
ti-rsos(-stttsoe50;
$vnsit=$hs>rge(50)
eetLs
ti-tigr"0";
}
}

rtr $vnsit
eun eetLs;
JUST TRY IT!
poetdfnto dsacUeRqet)
rtce ucin ipthsreus(
{
$vit=$hs>rge(rue,[rqet = $hs>eus(];
eLs
ti-tigr"ot" "eus" > ti-rqet))
$otMth=$vit>at)
rueac
eLs-ls(;
i (ul==$otMth {
f nl = rueac)
trwnwPgNtonEcpin"aentfud";
ho e aeoFudxeto(Pg o on!)
}
$hs>epne)>eSauCd(0)
ti-rsos(-stttsoe20;
$hs>rge(pefth,[rueac"= $otMth)
ti-tigr"r.ec" "otMth > rueac];
$otolr =$hs>vns)>rge(eeue,$otMth;
cnrles
ti-eet(-tigr"xct" rueac)
}

rtr $otolr;
eun cnrles

Why the "execute" trigger is different?
NOW IT WORKS!
pbi fnto tsBsAplw)
ulc ucin etaepFo(
{
$eus =Rqetatr:cetRqet"apg" "E";
rqet
eusFcoy:raeeus(/-ae, GT)
$p =nwAp)
ap
e p(;
$p-steus(rqet;
ap>eRqet$eus)
$p-stevcMngrnwZnevcMngrSrieaae()
ap>eSrieaae(e edSrieaaeevcMngr);
$p-stvnMngrnwZnvnMngrEetaae()
ap>eEetaae(e edEetaaevnMngr);
$epne=$p-rn)>epne)
rsos
ap>u(-rsos(;
}

$hs>setqas44 $epne>eSauCd()
ti-asrEul(0, rsos-gtttsoe);

.
O ( tss 1asrin)
K 1 et,
setos

See it on Github Gist
EASY TO MOCK!
pbi fnto tsORsosORueac(
ulc ucin etkepnenotMth)
{
$p =nwAp)
ap
e p(;
$vnMngr=nwZnvnMngrEetaae(;
eetaae
e edEetaaevnMngr)
$vnmngr>tah"ot" fnto( {
eetaae-atc(rue, ucin)
rtr nwRueac(]
eun e otMth[)
};
)
$p-stvnMngr$vnMngr;
ap>eEetaae(eetaae)
$p-stevcMngrnwZnevcMngrSrieaae()
ap>eSrieaae(e edSrieaaeevcMngr);
$epne=$p-rn)>epne)
rsos
ap>u(-rsos(;
}

$hs>setqas20 $epne>eSauCd()
ti-asrEul(0, rsos-gtttsoe);

.
.
O ( tss 2asrin)
K 2 et,
setos
WE NEED A BOOTSTRAPPER!
Or better, something that can prepare the event manager and
the service manager from a default configuration!
LINK DEFAULT LISTENERS
"itnr"= [
lsees >
"ot"= [
rue >
[ruelsee" "notEet]
"ot.itnr, oRuevn",
]
,
"edrr = [
rnee" >
[rnee.itnr,"edr]
"edrrlsee" rne",
]
,
"iih = [
fns" >
[rsos.itnr,"edepne]
"epnelsee" snRsos",
]
,
]
FRAMEWORK BASE SERVICES CONFIG
"lae"= [
aiss >
"ot.itnr
ruelsee"
= "itnrotLsee"
> LseeRueitnr,
"edrrlsee"= "itnredrrsn,
rnee.itnr > LseeRneeJo"
"epnelsee"= "itnredepneitnr,
rsos.itnr > LseeSnRsosLsee"
]
,
"atre"= [
fcois >
"itnrotLsee"= "evcRueitnratr"
LseeRueitnr > SrieotLseeFcoy,
]
,
"noals = [
ivkbe" >
"itnredrrsn
LseeRneeJo"
= "itnredrrsn,
> LseeRneeJo"
"itnredepneitnr = "itnredepneitnr,
LseeSnRsosLsee" > LseeSnRsosLsee"
]
,
THE ROUTER!
FOLLOW ZF2 IDEAS!
rtr [
eun
"otr = [
rue" >
"ots = [
rue" >
"oe = [
hm" >
"ye = "iea"
tp" > Ltrl,
"pin"= [
otos >
"ot"= ""
rue > /,
"eals = [
dfut" >
"otolr = "FaIay,
cnrle" > ZDytl"
"cin = "e21Dy
ato" > gt04a"
]
]
,
'a_emnt'= tu,
mytriae > re
]
]
]
]
;
ROUTE LISTENER
casRueitnr
ls otLsee
{
pbi fnto _cntut$otr
ulc ucin _osrc(rue)
{
$hs>otr=$otr
ti-rue
rue;
}
}

pbi fnto oRuevn(eet {..}
ulc ucin notEet$vn)
.

/Rueitnratr
/otLseeFcoy
$otr=TeRuetc:fcoy$ofg"otr];
rue
reotSak:atr(cni[rue")
$otLsee =nwRueitnr$otr;
rueitnr
e otLsee(rue)
$hs>tah"ot" [rueitnr "notEet];
ti-atc(rue, $otLsee, oRuevn")
ON ROUTE EVENT
pbi fnto oRuevn(eet
ulc ucin notEet$vn)
{
$agt=$vn-gtagt)
tre
eet>eTre(;
$eus =$vn-gtaa(rqet)
rqet
eet>ePrm"eus";
$ac =$hs>eRue(-mth$eus)
mth
ti-gtotr)>ac(rqet;
i (mth {
f $ac)
$c =$ac-gtaa(ato";
at
mth>ePrm"cin)
$tl=$ac-gtaa(cnrle";
cr
mth>ePrm"otolr)
i (tre-srie(-hs$tr){
f $agt>evcs)>a(cl)
$tl=$agt>evcs)>e(cl)
cr
tre-srie(-gt$tr;
}
$agt>vns)>tah"xct" [cr,$c];
tre-eet(-atc(eeue, $tl at)

}

}
rtr $ac;
eun mth
CONTROLLERS [ACTION LISTENERS]
Controllers are POPO objects that returns serializable data
nmsaeZa;
aepc FDy
casIay
ls tl
{
pbi fnto gt04a(
ulc ucin e21Dy)
{
rtr [
eun
"ak"= [
tls >
"is"= [
frt >
"il"= "utatte."
tte > Js
il..
]
]
,
..
.
]
;
}
}
BUT, POPOS ARE TOO SIMPLE
We want to use other services into actions!
pbi fnto tecin)
ulc ucin hAto(
{
/Ine asriehr!
/ ed
evc ee
$yevc =$hs>evcs)>e(m.evc";
mSrie
ti-srie(-gt"ysrie)
}

/uei..
/s t.

But how to do that?
CONTROLLERS USES
casTeotolr
ls hCnrle
{
ueSrieaae;
s evcMngr
pbi fnto tecin){
ulc ucin hAto(
$evc =$hs>evcs)>e(m.evc";
srie
ti-srie(-gt"ysrie)

}

}

..
.
TRAITS
tatSrieaae(
ri evcMngr)
{
piae$evcMngr
rvt srieaae;
pbi fnto stevcMngr$evcMngr
ulc ucin eSrieaae(srieaae)
{
$hs>evcMngr=$evcMngr
ti-srieaae
srieaae;
}

}

pbi fnto srie(
ulc ucin evcs)
{
rtr $hs>evcMngr
eun ti-srieaae;
}
ZENDSTDLIBHYDRATOR
$aa=[
dt
"evcMngr = $agt>evcs)
srieaae" > tre-srie(,
"vnMngr = $agt>vns)
eetaae" > tre-eet(,
"epne = $agt>epne)
rsos" > tre-rsos(,
"eus"= $agt>eus(,
rqet > tre-rqet)
]
;
$yrtr=nwedSdiyrtrCasehd(;
hdao
e ZntlbHdaolsMtos)
$yrtr>yrt(dt,$otolr;
hdao-hdae$aa cnrle)
AND ALSO CONTROLLERS AS SERVICES
"evcs = [
srie" >
"noals = [
ivkbe" >
"FaIay = "FaIay,
ZDytl" > ZDytl"
]
]
"atre"= [
fcois >
"FaIay = fnto(evcLctrnefc $l {
ZDytl" > ucinSrieoaoItrae s)
$otolr=nwFDyIay)
cnrle
e Zatl(;
$otolr>eMSrie$l>e(m.evc")
cnrle-styevc(s-gt"ysrie);

]

}
,
..
.

rtr $otolr
eun cnrle;

And all others ZF2 services opportunities
RENDERERS!
Serialize your data
JSON RENDERER
casJo
ls sn
{
pbi fnto rne(vn $vn)
ulc ucin edrEet eet
{
$agt=$vn-gtagt)
tre
eet>eTre(;
$aaak=$vn-gtaa(dt"-ls(
dtPc
eet>ePrm"aa)>at)
$epne=$agt>epne)
rsos
tre-rsos(;
$epne>dHaes[
rsos-adedr(
"otn-ye = "plcto/sn,
CnetTp" > apiainjo"
];
)

}

}

$epne>eCnetjo_noe$aaak)
rsos-stotn(snecd(dtPc);

/ Ap
/ p
$hs>vns)>tah"edr,[rnee,"edr];
ti-eet(-atc(rne" $edrr rne")
SEND RESPONSE TO THE CLIENT
It's an event of course!
EMIT!
casEi
ls mt
{
pbi fnto sn(eet
ulc ucin ed$vn)
{
$agt=$vn-gtagt)
tre
eet>eTre(;

}

}

$agt>epne)>ed)
tre-rsos(-sn(;

/Ap
/p
$hs>vns)>tah"iih,[eitr "ed];
ti-eet(-atc(fns" $mte, sn")

We can remove it or mock it out during testing!
SEE THE FIRST IMPLEMENTATION
The first impl
AT LEAST 3 RESPONSIBILITIES
BUT EFFECTIVELY MORE...

Configure the application
Prepare the application
Run the application
Single Responsibility Principle
REFACTOR THE FRAMEWORK
6d695f6 -> 87ad7e73
OK, RECAP!
EVENTS

ANY IDEAS?
PERFORMANCE INSPECTION & TRACKING
Symfony2 Stopwatch component
casSowthitnr
ls tpacLsee
pbi fnto sat$vn)
ulc ucin tr(eet
{
$xctoNm =gtcas$vn-gtagt);
eeuinae
e_ls(eet>eTre()
$hs>eSowth)>tr(eeuinae;
ti-gttpac(-sat$xctoNm)
}
pbi fnto lp$vn){..}
ulc ucin a(eet
.
pbi fnto so(eet
ulc ucin tp$vn)
{
$xctoNm =gtcas$vn-gtagt);
eeuinae
e_ls(eet>eTre()
$xcto =$hs>eSowth)>tp$xctoNm)
eeuin
ti-gttpac(-so(eeuinae;

}

}

/sn t DTDGSRIE LGES.
/ed o AAO EVC, OGR..

SmoyCmoetSowthSowth
yfnopnntpactpac
PERFORMANCE INSPECTION & TRACKING
"itnr"= [
lsees >
"ei"= [
bgn >
[lsee.tpac" "tr",
"itnrsowth, sat]
]
,
"r.ec"= [
pefth >
[lsee.tpac" "a",
"itnrsowth, lp]
]
,
"iih = [
fns" >
[lsee.tpac" "tp]
"itnrsowth, so",
]
,
]
"evcs = [
srie" >
"lae"= [
aiss >
"itnrsowth = "tpacLseeFcoy
lsee.tpac" > Sowthitnratr"
]
]
PERFORMANCE INSPECTION & TRACKING
PERFORMANCE INSPECTION & TRACKING
PERSONAL EVENTS
pbi fnto cnimusrpincin$otMthvn)
ulc ucin ofrSbcitoAto(rueacEet
{
$sr=nwUe(;
ue
e sr)
$sr>eNm(.)
ue-stae..;
..
.
$niyaae-prit$sr;
ettMngr>ess(ue)
$niyaae-fuh)
ettMngr>ls(;
}

$hs>vns)>rge(sbcie.e" $sr;
ti-eet(-tigr"usrbrnw, ue)

"itnr"= [
lsees >
"usrbrnw = [
sbcie.e" >
[sbcie.ade" "oiyiEal]
"usrbrhnlr, ntfVami"
[sascutr,"eSbcie"
"tt.one" nwusrbr]
]
]
MAINTENANCE PAGES
"itnr"= [
lsees >
"ot"= [
rue >
[mitnnelsees,"aneacPg"
"aneac.itnr" mitnneae]
]
,
"xct"= [
eeue >
[mitnnecnrle" "aneacAto"
"aneac.otolr, mitnnecin]
]
,
]
casMitnneotLsee
ls aneacRueitnr
{
pbi fnto mitnneaeEet$vn)
ulc ucin aneacPg(vn eet
{
rtr nwRueac(];
eun e otMth[)
}
}

Don't use this, there are better ways
TRY IT!
Fork it on Github
https://github.com/wdalmut/upcloo-web-framework
THANKS FOR LISTENING
ALWAYS EVENTS?
Author Walter Dal Mut / @walterdalmut

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

穏やかにファイルを削除する
穏やかにファイルを削除する穏やかにファイルを削除する
穏やかにファイルを削除する
 
[Webinar] An Hour with the CTO: All About APIs and the Nuxeo Platform
[Webinar] An Hour with the CTO: All About APIs and the Nuxeo Platform[Webinar] An Hour with the CTO: All About APIs and the Nuxeo Platform
[Webinar] An Hour with the CTO: All About APIs and the Nuxeo Platform
 
The Ring programming language version 1.6 book - Part 61 of 189
The Ring programming language version 1.6 book - Part 61 of 189The Ring programming language version 1.6 book - Part 61 of 189
The Ring programming language version 1.6 book - Part 61 of 189
 
One page app with AngularJS
One page app with AngularJSOne page app with AngularJS
One page app with AngularJS
 
Yg byev2e
Yg byev2eYg byev2e
Yg byev2e
 
RabbitMQ
RabbitMQRabbitMQ
RabbitMQ
 
FrontDays #3. Иван Федяев, Эволюция JavaScript. Обзор нововведений ECMAScript 6
FrontDays #3. Иван Федяев, Эволюция JavaScript. Обзор нововведений ECMAScript 6FrontDays #3. Иван Федяев, Эволюция JavaScript. Обзор нововведений ECMAScript 6
FrontDays #3. Иван Федяев, Эволюция JavaScript. Обзор нововведений ECMAScript 6
 
Project hotel on hotel management fo
Project  hotel on hotel management foProject  hotel on hotel management fo
Project hotel on hotel management fo
 
Serhii Korolenko - Passing Security By
Serhii Korolenko - Passing Security BySerhii Korolenko - Passing Security By
Serhii Korolenko - Passing Security By
 
Build a compiler in 2hrs - NCrafts Paris 2015
Build a compiler in 2hrs -  NCrafts Paris 2015Build a compiler in 2hrs -  NCrafts Paris 2015
Build a compiler in 2hrs - NCrafts Paris 2015
 
Jamming attack in wireless network
Jamming attack in wireless networkJamming attack in wireless network
Jamming attack in wireless network
 
Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)
 
Aodv routing protocol code in ns2
Aodv routing protocol code in ns2Aodv routing protocol code in ns2
Aodv routing protocol code in ns2
 
Augeas
AugeasAugeas
Augeas
 
Try Redis - interactive Tutorial
Try Redis - interactive TutorialTry Redis - interactive Tutorial
Try Redis - interactive Tutorial
 
Using Phing for Fun and Profit
Using Phing for Fun and ProfitUsing Phing for Fun and Profit
Using Phing for Fun and Profit
 
The Ring programming language version 1.5.4 book - Part 51 of 185
The Ring programming language version 1.5.4 book - Part 51 of 185The Ring programming language version 1.5.4 book - Part 51 of 185
The Ring programming language version 1.5.4 book - Part 51 of 185
 
Arquillian Extensions
Arquillian ExtensionsArquillian Extensions
Arquillian Extensions
 
The Ring programming language version 1.5.2 book - Part 50 of 181
The Ring programming language version 1.5.2 book - Part 50 of 181The Ring programming language version 1.5.2 book - Part 50 of 181
The Ring programming language version 1.5.2 book - Part 50 of 181
 
teste
testeteste
teste
 

Destaque

Destaque (13)

Corley scalability
Corley scalabilityCorley scalability
Corley scalability
 
Cloud party 2014 - Deploy your infrastructure with Saltstack - Salt Cloud wit...
Cloud party 2014 - Deploy your infrastructure with Saltstack - Salt Cloud wit...Cloud party 2014 - Deploy your infrastructure with Saltstack - Salt Cloud wit...
Cloud party 2014 - Deploy your infrastructure with Saltstack - Salt Cloud wit...
 
Scale your PHP application with Elastic Beanstalk - CloudParty Genova
Scale your PHP application with Elastic Beanstalk - CloudParty GenovaScale your PHP application with Elastic Beanstalk - CloudParty Genova
Scale your PHP application with Elastic Beanstalk - CloudParty Genova
 
MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden
MySQL - Scale Out @ CloudParty 2013 Milano Talent GardenMySQL - Scale Out @ CloudParty 2013 Milano Talent Garden
MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden
 
From Chef to Saltstack on Cloud Providers - Incontro DevOps 2015
From Chef to Saltstack on Cloud Providers - Incontro DevOps 2015From Chef to Saltstack on Cloud Providers - Incontro DevOps 2015
From Chef to Saltstack on Cloud Providers - Incontro DevOps 2015
 
Php & cloud computing
Php & cloud computingPhp & cloud computing
Php & cloud computing
 
Disaster Recovery - On-Premise & Cloud
Disaster Recovery - On-Premise & CloudDisaster Recovery - On-Premise & Cloud
Disaster Recovery - On-Premise & Cloud
 
An introduction to Hubot - CloudConf 2015 - Turin Italy
An introduction to Hubot - CloudConf 2015 - Turin ItalyAn introduction to Hubot - CloudConf 2015 - Turin Italy
An introduction to Hubot - CloudConf 2015 - Turin Italy
 
Middleware PHP - A simple micro-framework
Middleware PHP - A simple micro-frameworkMiddleware PHP - A simple micro-framework
Middleware PHP - A simple micro-framework
 
Cloud computing & lamp applications
Cloud computing & lamp applicationsCloud computing & lamp applications
Cloud computing & lamp applications
 
Scale your Magento app with Elastic Beanstalk
Scale your Magento app with Elastic BeanstalkScale your Magento app with Elastic Beanstalk
Scale your Magento app with Elastic Beanstalk
 
React vs Angular2
React vs Angular2React vs Angular2
React vs Angular2
 
Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour L...
Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour L...Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour L...
Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour L...
 

Semelhante a Build a custom (micro)framework with ZF2 Components (as building blocks)

R57shell
R57shellR57shell
R57shell
ady36
 
R57php 1231677414471772-2
R57php 1231677414471772-2R57php 1231677414471772-2
R57php 1231677414471772-2
ady36
 

Semelhante a Build a custom (micro)framework with ZF2 Components (as building blocks) (20)

R57shell
R57shellR57shell
R57shell
 
Beginner workshop to angularjs presentation at Google
Beginner workshop to angularjs presentation at GoogleBeginner workshop to angularjs presentation at Google
Beginner workshop to angularjs presentation at Google
 
Flow of events during Media Player creation in Android
Flow of events during Media Player creation in AndroidFlow of events during Media Player creation in Android
Flow of events during Media Player creation in Android
 
Automated tests - facts and myths
Automated tests - facts and mythsAutomated tests - facts and myths
Automated tests - facts and myths
 
Ae internals
Ae internalsAe internals
Ae internals
 
Climbing the Abstract Syntax Tree (php[world] 2019)
Climbing the Abstract Syntax Tree (php[world] 2019)Climbing the Abstract Syntax Tree (php[world] 2019)
Climbing the Abstract Syntax Tree (php[world] 2019)
 
Create Custom Post Type Plugin
Create Custom Post Type PluginCreate Custom Post Type Plugin
Create Custom Post Type Plugin
 
Angular.js + Rails at WeWork or: The Accidental Feature
Angular.js + Rails at WeWork or: The Accidental FeatureAngular.js + Rails at WeWork or: The Accidental Feature
Angular.js + Rails at WeWork or: The Accidental Feature
 
Climbing the Abstract Syntax Tree (Bulgaria PHP 2016)
Climbing the Abstract Syntax Tree (Bulgaria PHP 2016)Climbing the Abstract Syntax Tree (Bulgaria PHP 2016)
Climbing the Abstract Syntax Tree (Bulgaria PHP 2016)
 
Climbing the Abstract Syntax Tree (DPC 2017)
Climbing the Abstract Syntax Tree (DPC 2017)Climbing the Abstract Syntax Tree (DPC 2017)
Climbing the Abstract Syntax Tree (DPC 2017)
 
Climbing the Abstract Syntax Tree (IPC Fall 2017)
Climbing the Abstract Syntax Tree (IPC Fall 2017)Climbing the Abstract Syntax Tree (IPC Fall 2017)
Climbing the Abstract Syntax Tree (IPC Fall 2017)
 
Climbing the Abstract Syntax Tree (CodeiD PHP Odessa 2017)
Climbing the Abstract Syntax Tree (CodeiD PHP Odessa 2017)Climbing the Abstract Syntax Tree (CodeiD PHP Odessa 2017)
Climbing the Abstract Syntax Tree (CodeiD PHP Odessa 2017)
 
Proxy OOP Pattern in PHP
Proxy OOP Pattern in PHPProxy OOP Pattern in PHP
Proxy OOP Pattern in PHP
 
Climbing the Abstract Syntax Tree (phpDay 2017)
Climbing the Abstract Syntax Tree (phpDay 2017)Climbing the Abstract Syntax Tree (phpDay 2017)
Climbing the Abstract Syntax Tree (phpDay 2017)
 
Climbing the Abstract Syntax Tree (PHP South Africa 2017)
Climbing the Abstract Syntax Tree (PHP South Africa 2017)Climbing the Abstract Syntax Tree (PHP South Africa 2017)
Climbing the Abstract Syntax Tree (PHP South Africa 2017)
 
Building Maintainable Applications in Apex
Building Maintainable Applications in ApexBuilding Maintainable Applications in Apex
Building Maintainable Applications in Apex
 
Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018)
Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018)Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018)
Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018)
 
R57php 1231677414471772-2
R57php 1231677414471772-2R57php 1231677414471772-2
R57php 1231677414471772-2
 
Climbing the Abstract Syntax Tree (Midwest PHP 2020)
Climbing the Abstract Syntax Tree (Midwest PHP 2020)Climbing the Abstract Syntax Tree (Midwest PHP 2020)
Climbing the Abstract Syntax Tree (Midwest PHP 2020)
 
[Erlang LT] Regexp Perl And Port
[Erlang LT] Regexp Perl And Port[Erlang LT] Regexp Perl And Port
[Erlang LT] Regexp Perl And Port
 

Mais de Corley S.r.l.

Mais de Corley S.r.l. (20)

Aws rekognition - riconoscimento facciale
Aws rekognition  - riconoscimento faccialeAws rekognition  - riconoscimento facciale
Aws rekognition - riconoscimento facciale
 
AWSome day 2018 - scalability and cost optimization with container services
AWSome day 2018 - scalability and cost optimization with container servicesAWSome day 2018 - scalability and cost optimization with container services
AWSome day 2018 - scalability and cost optimization with container services
 
AWSome day 2018 - API serverless with aws
AWSome day 2018  - API serverless with awsAWSome day 2018  - API serverless with aws
AWSome day 2018 - API serverless with aws
 
AWSome day 2018 - database in cloud
AWSome day 2018 -  database in cloudAWSome day 2018 -  database in cloud
AWSome day 2018 - database in cloud
 
Trace your micro-services oriented application with Zipkin and OpenTracing
Trace your micro-services oriented application with Zipkin and OpenTracing Trace your micro-services oriented application with Zipkin and OpenTracing
Trace your micro-services oriented application with Zipkin and OpenTracing
 
Apiconf - The perfect REST solution
Apiconf - The perfect REST solutionApiconf - The perfect REST solution
Apiconf - The perfect REST solution
 
Apiconf - Doc Driven Development
Apiconf - Doc Driven DevelopmentApiconf - Doc Driven Development
Apiconf - Doc Driven Development
 
Authentication and authorization in res tful infrastructures
Authentication and authorization in res tful infrastructuresAuthentication and authorization in res tful infrastructures
Authentication and authorization in res tful infrastructures
 
Flexibility and scalability of costs in serverless infrastructures
Flexibility and scalability of costs in serverless infrastructuresFlexibility and scalability of costs in serverless infrastructures
Flexibility and scalability of costs in serverless infrastructures
 
CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application
CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented applicationCloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application
CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application
 
A single language for backend and frontend from AngularJS to cloud with Clau...
A single language for backend and frontend  from AngularJS to cloud with Clau...A single language for backend and frontend  from AngularJS to cloud with Clau...
A single language for backend and frontend from AngularJS to cloud with Clau...
 
AngularJS: Service, factory & provider
AngularJS: Service, factory & providerAngularJS: Service, factory & provider
AngularJS: Service, factory & provider
 
The advantage of developing with TypeScript
The advantage of developing with TypeScript The advantage of developing with TypeScript
The advantage of developing with TypeScript
 
Angular coding: from project management to web and mobile deploy
Angular coding: from project management to web and mobile deployAngular coding: from project management to web and mobile deploy
Angular coding: from project management to web and mobile deploy
 
Corley cloud angular in cloud
Corley cloud   angular in cloudCorley cloud   angular in cloud
Corley cloud angular in cloud
 
Measure your app internals with InfluxDB and Symfony2
Measure your app internals with InfluxDB and Symfony2Measure your app internals with InfluxDB and Symfony2
Measure your app internals with InfluxDB and Symfony2
 
Read Twitter Stream and Tweet back pictures with Raspberry Pi & AWS Lambda
Read Twitter Stream and Tweet back pictures with Raspberry Pi & AWS LambdaRead Twitter Stream and Tweet back pictures with Raspberry Pi & AWS Lambda
Read Twitter Stream and Tweet back pictures with Raspberry Pi & AWS Lambda
 
Cloud Conf 2015 - Develop and Deploy IOT Applications
Cloud Conf 2015 - Develop and Deploy IOT ApplicationsCloud Conf 2015 - Develop and Deploy IOT Applications
Cloud Conf 2015 - Develop and Deploy IOT Applications
 
AngularJS advanced project management
AngularJS advanced project managementAngularJS advanced project management
AngularJS advanced project management
 
Raspberry Pi - HW/SW Application Development
Raspberry Pi - HW/SW Application DevelopmentRaspberry Pi - HW/SW Application Development
Raspberry Pi - HW/SW Application Development
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Último (20)

EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 

Build a custom (micro)framework with ZF2 Components (as building blocks)

  • 1. ZFDAY - 2014 BUILD A CUSTOM (MICRO)FRAMEWORK WITH ZF2 COMPONENTS AS BUILDING BLOCKS Author Walter Dal Mut / @walterdalmut
  • 2. WHO AM I? Walter Dal Mut, I work at Corley S.r.l. and also at UpCloo Ltd. You can contact me at: walter.dalmut@gmail.com On Twitter: @walterdalmut On GitHub: wdalmut
  • 3. WHY A CUSTOM FRAMEWORK? Tipically because we want to solve a particular problem. ZendFramework is a general purpose Web Framework that can fit different problems easily.
  • 4. IT SOUNDS LIKE REINVENTING THE WHEEL NO, WE DON'T WANT! We will use ZF2 components as building blocks We will drive a personal behaviour
  • 6. REQUIREMENTS Event Driven Design Dependency Inversion Principle TESTABLE/TDD
  • 7. EVENT DRIVEN DESIGN All framework operations are events (like ZF2)
  • 8. DEPENDENCY INVERSION We will focus on Service Manager
  • 9. [ WE WANT TO TEST OUR APPLICATIONS ]
  • 10. COMPOSE IT! { } "eur" { rqie: "edrmwr/edeetaae" "." znfaeokzn-vnmngr: 2*, "edrmwr/edsrieaae" "." znfaeokzn-evcmngr: 2*, "edrmwr/edmc:"." znfaeokzn-v" 2*, "edrmwr/edht" "." znfaeokzn-tp: 2* } , "eur-e" { rqiedv: "hui/hui" ".." ppntppnt: 37* } ,
  • 11. LET'S GO TO SCHOOL We have to learn our building blocks!
  • 12. THE EVENT MANAGER $vnMngr=nwZnvnMngrEetaae(; eetaae e edEetaaevnMngr) / Tigra eet / rge n vn pbi fnto tigr$vn,$agt=nl,$rv=nl) ulc ucin rge(eet tre ul ag ul; / Atc alsee t a eet / tah itnr o n vn pbi fnto atc(eet $alak $roiy; ulc ucin tah$vn, clbc, pirt) There are many other methods (detach, triggerUntil, etc...) See it on Github
  • 13. HOW EVENT MANAGER WORKS? pbi fnto tsEetaae( ulc ucin etvnMngr) { $v =nwEetaae(; e e vnMngr) $sald=fle iCle as; $v>tah'neet,fnto(eet ue($sald { e-atc(a-vn' ucin$vn) s &iCle) $sald=tu; iCle re }; ) $v>rge(a-vn"; e-tigr"neet) } $hs>setre$sald; ti-asrTu(iCle)
  • 14. THE SERVICE LOCATOR $evcMngr=nwZnevcMngrSrieaae(; srieaae e edSrieaaeevcMngr) "evcs = [ srie" > "noals = [ ivkbe" > "oraeop = "oraeop, YuNmCm" > YuNmCm" ] , "atre"= [ fcois > "oraeevc"= "oraeevcFcoy, YuNmSrie > YuNmSrieatr" ] , "lae"= [ aiss > "orais = "oraeevc" yu.la" > YuNmSrie, ] ] See it on Github
  • 15. CONFIGURE S.L. FROM ARRAY $evcMngr=nwZnevcMngrSrieaae(; srieaae e edSrieaaeevcMngr) $ofg=nwZnevcMngrCni( cni e edSrieaaeofg[ "noals = [.] ivkbe" > .., "atre"= [.] fcois > .., "btatfcois = [.] asrc_atre" > .., "lae"= [.] aiss > .. ] ) $ofg>ofgrSrieaae(srieaae) cni-cniueevcMngr$evcMngr;
  • 16. HOW SERVICE MANAGER WORKS? pbi fnto tsSrieaae( ulc ucin etevcMngr) { $m=nwSrieaae(; s e evcMngr) $hs>ofg>ofgrSrieaae(s) ti-cni-cniueevcMngr$m; $hs>setre$m>a(eape); ti-asrTu(s-hs"xml") } $hs>setae ti-asrSm( $m>e(eape) s-gt"xml", $m>e(eape) s-gt"xml" ) ;
  • 17. THE ROUTER $t =ZnvotrHtreotSak:atr(ra $ofg; rr edMcRuetpTeRuetc:fcoyary cni) "ots = [ rue" > "otNm"= [ rueae > "ye = "iea" tp" > Ltrl, "pin"= [ otos > "ot"= "pt" rue > /ah, "eals = [ dfut" > "otolr = "Fae, cnrle" > ZNm" "cin =>"cinae, ato" atoNm" ] ] , "a_emnt"= tu, mytriae > re ] ] $otMth=$t-mthRqet$eus) rueac rr>ac(eus rqet;
  • 18. HOW ROUTER WORKS? pbi fnto tsRueac( ulc ucin etotMth) { $otr=TeRuetc:fcoy$hs>ofg; rue reotSak:atr(ti-cni) $eus =nwRqet"pt"; rqet e eus(/ah) $otMth=$otr>ac(rqet; rueac rue-mth$eus) $otolrae=$otrac-gtaa(cnrle"; cnrleNm rueMth>ePrm"otolr) $cinae=$otMth>ePrm"cin) atoNm rueac-gtaa(ato"; } $hs>setqas"Fae,$otolrae) ti-asrEul(ZNm" cnrleNm) $hs>setqas"cinae,$cinae) ti-asrEul(atoNm" atoNm)
  • 21. HYDRATORS pbi fnto etat$bet; ulc ucin xrc(ojc) pbi fnto hdaeary$aa $bet; ulc ucin yrt(ra dt, ojc) $lsMtos=nwedSdiyrtrCasehd(; casehd e ZntlbHdaolsMtos) $betrp=nwedSdiyrtobetrpry) ojcPo e ZntlbHdarrOjcPoet(; $ra =nwedSdiyrtoraSraial(; ary e ZntlbHdarrAryeilzbe)
  • 24. THE FRAMEWORK EVENTS LIST BEGIN The loop begins ROUTE Parse the actual route in order to found a dispatchable action PRE.FETCH Before dispatch the action EXECUTE Dispatch all actions RENDER Render your data FINISH The loop ends
  • 26. TEST IT! pbi fnto tsBsAplw) ulc ucin etaepFo( { $eus =Rqetatr:cetRqet"vldul,"E" [) rqet eusFcoy:raeeus(/ai-r" GT, ]; $p =nwAp) ap e p(; $p-steus(rqet; ap>eRqet$eus) $p-stevcMngrnwZnevcMngrSrieaae() ap>eSrieaae(e edSrieaaeevcMngr); $p-stvnMngrnwZnvnMngrEetaae() ap>eEetaae(e edEetaaevnMngr); $epne=$p-rn)>epne) rsos ap>u(-rsos(; } $hs>setqas44 $epne>eSauCd() ti-asrEul(0, rsos-gtttsoe); F FI ( tss 1asrin) AL 1 et, setos
  • 27. REQUEST pbi fnto steus(eus $eus) ulc ucin eRqetRqet rqet { $hs>eus =$eus; ti-rqet rqet } pbi fnto rqet) ulc ucin eus( { i ($hs>eus){ f !ti-rqet $hs>eus =nwRqet) ti-rqet e eus(; } } rtr $hs>eus; eun ti-rqet
  • 28. RESPONSE pbi fnto stepneRsos $epne ulc ucin eRsos(epne rsos) { $hs>epne=$epne ti-rsos rsos; } pbi fnto rsos( ulc ucin epne) { i ($hs>epne { f !ti-rsos) $hs>epne=nwRsos(; ti-rsos e epne) } } rtr $hs>epne eun ti-rsos;
  • 29. EVENT MANAGER pbi fnto stvnMngr$vnMngr ulc ucin eEetaae(eetaae) { $hs>vnMngr=$vnMngr ti-eetaae eetaae; } pbi fnto eet( ulc ucin vns) { rtr $hs>vnMngr eun ti-eetaae; }
  • 30. EVENT TRIGGER HELPER pbi fnto tigr$ae ary$aas=[) ulc ucin rge(nm, ra prm ] { $vn =nwEet) eet e vn(; $vn-stagt$hs; eet>eTre(ti) $vn-staas$aas; eet>ePrm(prm) } rtr $hs>vns)>rge(nm,$vn) eun ti-eet(-tigr$ae eet;
  • 31. SERVICE MANAGER pbi fnto stevcMngr$evcMngr ulc ucin eSrieaae(srieaae) { $hs>evcMngr=$evcMngr ti-srieaae srieaae; } pbi fnto srie( ulc ucin evcs) { rtr $hs>evcMngr eun ti-srieaae; }
  • 32. ENTRY POINT! pbi fnto rn) ulc ucin u( { $hs>rge(bgn) ti-tigr"ei"; $vnsit=$hs>ipthsrcineaeEet(; eetLs ti-dsacUeAtoRltdvns) $hs>rge(rne" [dt"= $vnsit) ti-tigr"edr, "aa > eetLs]; $hs>rge(fns"; ti-tigr"iih) } rtr $hs eun ti;
  • 33. HEY, CAN YOU DO IT? poetdfnto dsacUeAtoRltdvns) rtce ucin ipthsrcineaeEet( { ty{ r $vnsit=$hs>ipthsreus(; eetLs ti-dsacUeRqet) }cth(atxeto $){ ac HlEcpin e $vnsit=$hs>rge(hl"; eetLs ti-tigr"at) }cth(aeoFudxeto $){ ac PgNtonEcpin e $hs>epne)>eSauCd(0) ti-rsos(-stttsoe44; $vnsit=$hs>rge(44) eetLs ti-tigr"0"; }cth(Ecpin$){ ac xeto e $hs>epne)>eSauCd(0) ti-rsos(-stttsoe50; $vnsit=$hs>rge(50) eetLs ti-tigr"0"; } } rtr $vnsit eun eetLs;
  • 34. JUST TRY IT! poetdfnto dsacUeRqet) rtce ucin ipthsreus( { $vit=$hs>rge(rue,[rqet = $hs>eus(]; eLs ti-tigr"ot" "eus" > ti-rqet)) $otMth=$vit>at) rueac eLs-ls(; i (ul==$otMth { f nl = rueac) trwnwPgNtonEcpin"aentfud"; ho e aeoFudxeto(Pg o on!) } $hs>epne)>eSauCd(0) ti-rsos(-stttsoe20; $hs>rge(pefth,[rueac"= $otMth) ti-tigr"r.ec" "otMth > rueac]; $otolr =$hs>vns)>rge(eeue,$otMth; cnrles ti-eet(-tigr"xct" rueac) } rtr $otolr; eun cnrles Why the "execute" trigger is different?
  • 35. NOW IT WORKS! pbi fnto tsBsAplw) ulc ucin etaepFo( { $eus =Rqetatr:cetRqet"apg" "E"; rqet eusFcoy:raeeus(/-ae, GT) $p =nwAp) ap e p(; $p-steus(rqet; ap>eRqet$eus) $p-stevcMngrnwZnevcMngrSrieaae() ap>eSrieaae(e edSrieaaeevcMngr); $p-stvnMngrnwZnvnMngrEetaae() ap>eEetaae(e edEetaaevnMngr); $epne=$p-rn)>epne) rsos ap>u(-rsos(; } $hs>setqas44 $epne>eSauCd() ti-asrEul(0, rsos-gtttsoe); . O ( tss 1asrin) K 1 et, setos See it on Github Gist
  • 36. EASY TO MOCK! pbi fnto tsORsosORueac( ulc ucin etkepnenotMth) { $p =nwAp) ap e p(; $vnMngr=nwZnvnMngrEetaae(; eetaae e edEetaaevnMngr) $vnmngr>tah"ot" fnto( { eetaae-atc(rue, ucin) rtr nwRueac(] eun e otMth[) }; ) $p-stvnMngr$vnMngr; ap>eEetaae(eetaae) $p-stevcMngrnwZnevcMngrSrieaae() ap>eSrieaae(e edSrieaaeevcMngr); $epne=$p-rn)>epne) rsos ap>u(-rsos(; } $hs>setqas20 $epne>eSauCd() ti-asrEul(0, rsos-gtttsoe); . . O ( tss 2asrin) K 2 et, setos
  • 37. WE NEED A BOOTSTRAPPER! Or better, something that can prepare the event manager and the service manager from a default configuration!
  • 38. LINK DEFAULT LISTENERS "itnr"= [ lsees > "ot"= [ rue > [ruelsee" "notEet] "ot.itnr, oRuevn", ] , "edrr = [ rnee" > [rnee.itnr,"edr] "edrrlsee" rne", ] , "iih = [ fns" > [rsos.itnr,"edepne] "epnelsee" snRsos", ] , ]
  • 39. FRAMEWORK BASE SERVICES CONFIG "lae"= [ aiss > "ot.itnr ruelsee" = "itnrotLsee" > LseeRueitnr, "edrrlsee"= "itnredrrsn, rnee.itnr > LseeRneeJo" "epnelsee"= "itnredepneitnr, rsos.itnr > LseeSnRsosLsee" ] , "atre"= [ fcois > "itnrotLsee"= "evcRueitnratr" LseeRueitnr > SrieotLseeFcoy, ] , "noals = [ ivkbe" > "itnredrrsn LseeRneeJo" = "itnredrrsn, > LseeRneeJo" "itnredepneitnr = "itnredepneitnr, LseeSnRsosLsee" > LseeSnRsosLsee" ] ,
  • 41. FOLLOW ZF2 IDEAS! rtr [ eun "otr = [ rue" > "ots = [ rue" > "oe = [ hm" > "ye = "iea" tp" > Ltrl, "pin"= [ otos > "ot"= "" rue > /, "eals = [ dfut" > "otolr = "FaIay, cnrle" > ZDytl" "cin = "e21Dy ato" > gt04a" ] ] , 'a_emnt'= tu, mytriae > re ] ] ] ] ;
  • 42. ROUTE LISTENER casRueitnr ls otLsee { pbi fnto _cntut$otr ulc ucin _osrc(rue) { $hs>otr=$otr ti-rue rue; } } pbi fnto oRuevn(eet {..} ulc ucin notEet$vn) . /Rueitnratr /otLseeFcoy $otr=TeRuetc:fcoy$ofg"otr]; rue reotSak:atr(cni[rue") $otLsee =nwRueitnr$otr; rueitnr e otLsee(rue) $hs>tah"ot" [rueitnr "notEet]; ti-atc(rue, $otLsee, oRuevn")
  • 43. ON ROUTE EVENT pbi fnto oRuevn(eet ulc ucin notEet$vn) { $agt=$vn-gtagt) tre eet>eTre(; $eus =$vn-gtaa(rqet) rqet eet>ePrm"eus"; $ac =$hs>eRue(-mth$eus) mth ti-gtotr)>ac(rqet; i (mth { f $ac) $c =$ac-gtaa(ato"; at mth>ePrm"cin) $tl=$ac-gtaa(cnrle"; cr mth>ePrm"otolr) i (tre-srie(-hs$tr){ f $agt>evcs)>a(cl) $tl=$agt>evcs)>e(cl) cr tre-srie(-gt$tr; } $agt>vns)>tah"xct" [cr,$c]; tre-eet(-atc(eeue, $tl at) } } rtr $ac; eun mth
  • 44. CONTROLLERS [ACTION LISTENERS] Controllers are POPO objects that returns serializable data nmsaeZa; aepc FDy casIay ls tl { pbi fnto gt04a( ulc ucin e21Dy) { rtr [ eun "ak"= [ tls > "is"= [ frt > "il"= "utatte." tte > Js il.. ] ] , .. . ] ; } }
  • 45. BUT, POPOS ARE TOO SIMPLE We want to use other services into actions! pbi fnto tecin) ulc ucin hAto( { /Ine asriehr! / ed evc ee $yevc =$hs>evcs)>e(m.evc"; mSrie ti-srie(-gt"ysrie) } /uei.. /s t. But how to do that?
  • 46. CONTROLLERS USES casTeotolr ls hCnrle { ueSrieaae; s evcMngr pbi fnto tecin){ ulc ucin hAto( $evc =$hs>evcs)>e(m.evc"; srie ti-srie(-gt"ysrie) } } .. .
  • 47. TRAITS tatSrieaae( ri evcMngr) { piae$evcMngr rvt srieaae; pbi fnto stevcMngr$evcMngr ulc ucin eSrieaae(srieaae) { $hs>evcMngr=$evcMngr ti-srieaae srieaae; } } pbi fnto srie( ulc ucin evcs) { rtr $hs>evcMngr eun ti-srieaae; }
  • 48. ZENDSTDLIBHYDRATOR $aa=[ dt "evcMngr = $agt>evcs) srieaae" > tre-srie(, "vnMngr = $agt>vns) eetaae" > tre-eet(, "epne = $agt>epne) rsos" > tre-rsos(, "eus"= $agt>eus(, rqet > tre-rqet) ] ; $yrtr=nwedSdiyrtrCasehd(; hdao e ZntlbHdaolsMtos) $yrtr>yrt(dt,$otolr; hdao-hdae$aa cnrle)
  • 49. AND ALSO CONTROLLERS AS SERVICES "evcs = [ srie" > "noals = [ ivkbe" > "FaIay = "FaIay, ZDytl" > ZDytl" ] ] "atre"= [ fcois > "FaIay = fnto(evcLctrnefc $l { ZDytl" > ucinSrieoaoItrae s) $otolr=nwFDyIay) cnrle e Zatl(; $otolr>eMSrie$l>e(m.evc") cnrle-styevc(s-gt"ysrie); ] } , .. . rtr $otolr eun cnrle; And all others ZF2 services opportunities
  • 51. JSON RENDERER casJo ls sn { pbi fnto rne(vn $vn) ulc ucin edrEet eet { $agt=$vn-gtagt) tre eet>eTre(; $aaak=$vn-gtaa(dt"-ls( dtPc eet>ePrm"aa)>at) $epne=$agt>epne) rsos tre-rsos(; $epne>dHaes[ rsos-adedr( "otn-ye = "plcto/sn, CnetTp" > apiainjo" ]; ) } } $epne>eCnetjo_noe$aaak) rsos-stotn(snecd(dtPc); / Ap / p $hs>vns)>tah"edr,[rnee,"edr]; ti-eet(-atc(rne" $edrr rne")
  • 52. SEND RESPONSE TO THE CLIENT It's an event of course!
  • 53. EMIT! casEi ls mt { pbi fnto sn(eet ulc ucin ed$vn) { $agt=$vn-gtagt) tre eet>eTre(; } } $agt>epne)>ed) tre-rsos(-sn(; /Ap /p $hs>vns)>tah"iih,[eitr "ed]; ti-eet(-atc(fns" $mte, sn") We can remove it or mock it out during testing!
  • 54. SEE THE FIRST IMPLEMENTATION The first impl
  • 55. AT LEAST 3 RESPONSIBILITIES BUT EFFECTIVELY MORE... Configure the application Prepare the application Run the application Single Responsibility Principle
  • 59. PERFORMANCE INSPECTION & TRACKING Symfony2 Stopwatch component casSowthitnr ls tpacLsee pbi fnto sat$vn) ulc ucin tr(eet { $xctoNm =gtcas$vn-gtagt); eeuinae e_ls(eet>eTre() $hs>eSowth)>tr(eeuinae; ti-gttpac(-sat$xctoNm) } pbi fnto lp$vn){..} ulc ucin a(eet . pbi fnto so(eet ulc ucin tp$vn) { $xctoNm =gtcas$vn-gtagt); eeuinae e_ls(eet>eTre() $xcto =$hs>eSowth)>tp$xctoNm) eeuin ti-gttpac(-so(eeuinae; } } /sn t DTDGSRIE LGES. /ed o AAO EVC, OGR.. SmoyCmoetSowthSowth yfnopnntpactpac
  • 60. PERFORMANCE INSPECTION & TRACKING "itnr"= [ lsees > "ei"= [ bgn > [lsee.tpac" "tr", "itnrsowth, sat] ] , "r.ec"= [ pefth > [lsee.tpac" "a", "itnrsowth, lp] ] , "iih = [ fns" > [lsee.tpac" "tp] "itnrsowth, so", ] , ] "evcs = [ srie" > "lae"= [ aiss > "itnrsowth = "tpacLseeFcoy lsee.tpac" > Sowthitnratr" ] ]
  • 63. PERSONAL EVENTS pbi fnto cnimusrpincin$otMthvn) ulc ucin ofrSbcitoAto(rueacEet { $sr=nwUe(; ue e sr) $sr>eNm(.) ue-stae..; .. . $niyaae-prit$sr; ettMngr>ess(ue) $niyaae-fuh) ettMngr>ls(; } $hs>vns)>rge(sbcie.e" $sr; ti-eet(-tigr"usrbrnw, ue) "itnr"= [ lsees > "usrbrnw = [ sbcie.e" > [sbcie.ade" "oiyiEal] "usrbrhnlr, ntfVami" [sascutr,"eSbcie" "tt.one" nwusrbr] ] ]
  • 64. MAINTENANCE PAGES "itnr"= [ lsees > "ot"= [ rue > [mitnnelsees,"aneacPg" "aneac.itnr" mitnneae] ] , "xct"= [ eeue > [mitnnecnrle" "aneacAto" "aneac.otolr, mitnnecin] ] , ] casMitnneotLsee ls aneacRueitnr { pbi fnto mitnneaeEet$vn) ulc ucin aneacPg(vn eet { rtr nwRueac(]; eun e otMth[) } } Don't use this, there are better ways
  • 65. TRY IT! Fork it on Github https://github.com/wdalmut/upcloo-web-framework
  • 66. THANKS FOR LISTENING ALWAYS EVENTS? Author Walter Dal Mut / @walterdalmut