Your SlideShare is downloading. ×
0
REFACTORING TOSYMFONY COMPONENTS     ...AND THEIR FRIENDS         Michael Peacock
@MICHAELPEACOCKHead Developer @ Ground SixTechnical authorOccasional conference speaker
THE COMPONENTShttp://symfony.com/components
WHY USE COMPONENTSSolve common web application problemsIncredibly well documented(relatively) Standalone: use them how you...
INSTALLATION       Composer: the knight in shining armour                   Download itcr - hts/gtopsrogisalr|ppul s tp:/e...
THEIR FRIENDS
WHATS IN STOREAutoloading classes with ClassLoaderRouting requests with RoutingListening for events with the EventDispatch...
OUR REFACTORING TALESPEED UP DEVELOPMENT & MODERNISE LEGACY CODEBASE
OUR JOURNEYMessy structure, some procedural code: ClassLoaderGlobals, singletons and crazy objects: PimpleScattered routin...
MESSY STRUCTURE & PROCEDURAL CODE
CLASS LOADER
LAYING THE FOUNDATIONSControllersPSR-0  Namespace the code  Restructure into a better directory heirarchy  Component based...
USAGE$aepcs=ary nmsae   ra(   edraeaepc= _DR_./,    VnoNmNmsae > _I_    edraenteNmsae = _DR_./    VnoNmAohraepc > _I_ );$o...
CACHINGSupport for APC available, just needs to be enabled
GLOBALS, SINGLETONS AND CRAZY OBJECTS
PIMPLE  Pimple is a dependency injection container which lets useasily manage and inject our dependencies into our project...
REFACTORING TO USE A CONTAINER<pp ?hcasSmMdl ls oeoe{     pbi fnto _cntut)      ulc ucin _osrc(     {          $q =";     ...
LAZY LOADINGBy utilising closures, code isnt run until it is first requested /called; i.e. database connection is establis...
SHARING OBJECTS$otie[d =$otie-saefnto(c {cnanrb]   cnanr>hr(ucin$)    rtr nwD(..,$[d_sr] $[d_w)     eun e PO"." cbue, cbpd...
FURTHER REFACTORING<pp ?hcasSmMdl ls oeoe{     pbi fnto _cntut$otie=ra()      ulc ucin _osrc(cnanrary)     {          $q =...
CREATING YOUR OWN CONTAINERParticularly useful for re-use and different use-cases (cli vs                            web) ...
CONTROLLER REFACTORING (BEFORE)<pp ?hcasSmCnrle ls oeotolr{     / ..      / .      pbi fnto smAto(       ulc ucin oecin)  ...
REDUCING NEW...CONTAINERS WITHIN              CONTAINERS<pp?hnmsaeFciiFaeokCnanraepc aefrmwrotie;casDtAcsOjcsetnsipe ls aa...
CONTROLLER REFACTORING (AFTER)<pp ?hcasSmCnrle ls oeotolr{     / ..      / .     pbi fnto smAto(      ulc ucin oecin)     ...
HARDCODED CONFIGURATIONS
YAML
A YAML FILEd_yq:bmsl hs:oahs  ot lclot ue:ot  sr ro ps:  as  nm:b  ae d pr:30  ot 36 at_ac:tu  uopth regnrleea: pouto:fle ...
PARSING A YAML FILE$al=nwSmoyCmoetYmasr)ym   e yfnopnnalPre(;$asdstig =$al>as(iegtcnet(_I_./ofgyl) pre_etns  ym-prefl_e_ot...
CACHING  :-(
SCATTERED ROUTING LOGIC, LONG IF/ELSE            CONDITIONS
ROUTING
REFACTORING FOUNDATIONSMostly taken care of when we ensured all controllers were  objects and that the new structure follo...
SETTING IT UP        Alias some of the namespacesueSmoyCmoetCniieoao;s yfnopnnofgFlLctrueSmoyCmoetRuigRqetotx;s yfnopnnotn...
ROUTES FILEidxne: pten /  atr: dfut:{cas rjcttcCnrle mto:oeae }  eals   ls: PoetSaiotolr, ehd hmPg rqieet:  eurmns  _ehd G...
ROUTINGty{ r   $r =(se(_EVREUS_R) ?$SRE[RQETUI]:    ul  ist$SRE[RQETUI])   _EVREUS_R;   / gtrdo tetaln sah    / e i f h ri...
ROUTE VARIABLEScmetsoyadomn_tr_d: pten /es{aeoy/dt}{ril}  atr: nw/ctgr}{ae/atce dfut:{cas omnsCnrle:adomn}  eals   ls: Cme...
AUTHENTICATION CONTROLacutcon: pten /con  atr: acut dfut:{cas rjcconotolr,mto:aae,lg  eals   ls: PoetAcutCnrle ehd mng oge...
ROUTE CACHING$otr=nwRuigRue(e YmFlLae(lctr,otsyl,rue   e otnotrnw alieodr$oao) rue.maryah_i= vrwwcce,$otx)ra(ccedr > /a/w/...
UTM DATA, ETC $r =pe_elc(/?t_.?[&+ ,$r) ul   rgrpae&um(*)=^]/,  ul; $r =(usr$r,-)=  ?rrm$r, :$r; ul   sbt(ul 1 = ?) ti(ul ...
DUPLICATED LOGIC
EVENT DISPATCHER
WHY?
USE CASESRedirecting the user / flash notificationsSending transactional emailsAdding a product to a basketHooking into ot...
REDIRECTION & "FLASH" NOTIFICATIONS1. Raise an event2. Listen for notification events, and log the notification in-   sess...
APPROACHNotifiableMessageInterfaceRequestRedirection eventRedirectableNotification event (extends and implementsthe above)...
NOTIFIABLE MESSAGE INTERFACE<pp?hnmsaePoetFaeokEet;aepc rjcrmwrvnsitraeNtfalMsaenefc nefc oiibeesgItrae{  pbi fnto gtoiiai...
REQUEST REDIRECTION EVENT<pp ?hnmsaePoetFaeokEet; aepc rjcrmwrvnsueSmoyCmoetEetipthrEet s yfnopnnvnDsacevn;casRqeteieto et...
LISTENER<pp?hnmsaePoetFaeokLseesaepc rjcrmwritnr;uePoetFaeokEet;s rjcrmwrvnsueSmoyCmoetEetipthrEets yfnopnnvnDsacevn;casSt...
ANOTHER LISTENER<pp?hnmsaePoetFaeokLseesaepc rjcrmwritnr;uePoetFaeokEet;s rjcrmwrvnsueSmoyCmoetEetipthrEets yfnopnnvnDsace...
LISTEN UP...Create an event dispatcherCreate instance of listenerAdd the listener  Event name  A callable e.g. Object/Meth...
LISTEN UP$ipthr=nwEetipthr)dsace   e vnDsace(;/ Ntfcto (ucs,Wrig Err / oiiain Sces ann, ro)$ePritnNtfcto =nwLseesStessatoi...
DISPATCH$r =$aeul.conul   bs_r  acut;$esg =orpswr wscagdscesuymsae   Yu asod a hne ucsfl.;$vn =nwEeteietbeoiiain$r,$esg,uc...
GOTCHASget/set Name
STANDARD EVENT  We tend to use our own event object which extends thesymfony one. This holds a payload which is our event ...
QUEUEABLEInterface to define an event as something that can bequeuedListener to queue the event e.g. in beanstalk <pp ?h n...
QUEUE AN EVENT IN YOUR LISTENERpbi fnto cekvn(vnsEet$vn) ulc ucin hcEetEetvn eet{  i (eet>ePyod)isaco Qeebenefc){   f $vn-...
PHP & HTML MIXED TOGETHER
TWIG
SETUP AND LOAD/ cet ati flsse lae s i cnacs tmlts / rae  wg ieytm odr o t a ces epae$odr=nwwgLae_ieytmepae; lae   e Ti_odr...
REFACTORING TO TWIGA place to prepare twig and also perform any non-twigpresentation logic. Keeps the data de-coupled from...
PIMPLE ISSUE / ADD GLOBAL
TWIG TEMPLATES{ sm_aibe} { oevral }{ sm cmet# # oe omn }{ stls_fies=vral.eIes)% % e ito_tm aibegttm( }{ frie i ls_fies% % ...
TEMPLATE CACHING    This caches compiled templates not output$hs>wg=nwwgEvrnet$odr aryti-ti   e Ti_niomn(lae, ra(         ...
OUTPUT CACHING
SETUP OUTPUT CACHINGueDsrol2CceCces earlaahah;ueDsrol2CceAatrFl;s earlaahdpeie$dpe =nwFl(; aatr   e ie)$dpe-stpint (n)$oti...
INTEGRATING OUTPUT CACHING$ah_e =m5$r) cceky   d(ul;i (cceeald& $ot[ccal){ f $ah_nbe & rueahbe]     i(snl(ti-cnanrsr]& $ah...
VALIDATOR (FUEL)There is a symfony component which does this, though we         opted for the Fuel validation component.
HTTPFOUNDATIONAbstracting superglobals, the HTTP request and the HTTP                        response
REQUEST   ueSmoyCmoetHtFudtoeus;   s yfnopnntponainRqet   $eus =Rqet:raermlbl(;   rqet   eus:cetFoGoas)             Provid...
A PARAMETER BAG?Request properties are all ParameterBag or sub-classesProvides special methods to manage contents, includi...
RESPONSEueSmoyCmoetHtFudtoepnes yfnopnntponainRsos;$epne=nwRsos(;rsos  e epne)$epne>eCnetel PPK)rsos-stotn(Hlo HU;$epne>eS...
TRANSLATIONWorth a mention
SWIFT MAILER
SMTP TRANSPORT$rnpr =wf_mprnpr:nwntne$otie[stig[stasot   SitStTasot:eIsac(cnanretns]mt[hs,2)p]ot] 5       -stsrae$otie[sti...
CREATE THE MESSAGE$hs>esg =wf_esg:nwntne$ujc)ti-msae  SitMsae:eIsac(sbet    -strmary$rm= $rmnm)     >eFo(ra(fo > fo_ae)   ...
SEND THE MESSAGE$alr=wf_alr:eIsac(tasot;mie   SitMie:nwntne$rnpr)rtr $alr>ed$esg)eun mie-sn(msae;
THANKS!    @MICHAELPEACOCKWWW.MICHAELPEACOCK.CO.UK  HTTPS://JOIND.IN/8046
IMAGE CREDITShttp://www.flickr.com/photos/oskay/275142789/http://www.flickr.com/photos/martin_bircher/5287769680/http://ww...
Upcoming SlideShare
Loading in...5
×

Refactoring to symfony components

241

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
241
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Refactoring to symfony components"

  1. 1. REFACTORING TOSYMFONY COMPONENTS ...AND THEIR FRIENDS Michael Peacock
  2. 2. @MICHAELPEACOCKHead Developer @ Ground SixTechnical authorOccasional conference speaker
  3. 3. THE COMPONENTShttp://symfony.com/components
  4. 4. WHY USE COMPONENTSSolve common web application problemsIncredibly well documented(relatively) Standalone: use them how you likeIdeal for refactoring
  5. 5. INSTALLATION Composer: the knight in shining armour Download itcr - hts/gtopsrogisalr|ppul s tp:/ecmoe.r/ntle h Create a composer.json file{ "eur" { rqie: "yfn/h-rjc-ae:"e-atr, smoytepoetnm" dvmse" }} Run composerppcmoe.hrisalh opsrpa ntl
  6. 6. THEIR FRIENDS
  7. 7. WHATS IN STOREAutoloading classes with ClassLoaderRouting requests with RoutingListening for events with the EventDispatcherParsing YAML files with the YAML componentHTTP Requests and responses with HTTPFoundationInjecting dependencies with PimpleTemplates with Twig
  8. 8. OUR REFACTORING TALESPEED UP DEVELOPMENT & MODERNISE LEGACY CODEBASE
  9. 9. OUR JOURNEYMessy structure, some procedural code: ClassLoaderGlobals, singletons and crazy objects: PimpleScattered routing logic, long if/else conditions: RoutingHardcoded configurations: YAMLDuplicated logic: EventDispatcherPHP & HTML mixed together: TwigDuplicate form logic, spagetti code: Validator (Fuel)Other improvements: Mailer, HTTPFoundation,Translation & Validator
  10. 10. MESSY STRUCTURE & PROCEDURAL CODE
  11. 11. CLASS LOADER
  12. 12. LAYING THE FOUNDATIONSControllersPSR-0 Namespace the code Restructure into a better directory heirarchy Component based structure for our own code too
  13. 13. USAGE$aepcs=ary nmsae ra( edraeaepc= _DR_./, VnoNmNmsae > _I_ edraenteNmsae = _DR_./ VnoNmAohraepc > _I_ );$odr=nwyfnopnnlsLaenvraCasodr)lae e SmoyCmoetCasodrUiesllsLae(;$odr>eitr)lae-rgse(;$odr>eitraepcs$aepcs;lae-rgseNmsae(nmsae)
  14. 14. CACHINGSupport for APC available, just needs to be enabled
  15. 15. GLOBALS, SINGLETONS AND CRAZY OBJECTS
  16. 16. PIMPLE Pimple is a dependency injection container which lets useasily manage and inject our dependencies into our projects.We put the dependencies into a container, and then we inject this container into our code which uses it.
  17. 17. REFACTORING TO USE A CONTAINER<pp ?hcasSmMdl ls oeoe{ pbi fnto _cntut) ulc ucin _osrc( { $q ="; sl " $ur =Dtbs:qey$q) qey aaae:ur(sl; }}bfr eoe<pp ?hcasSmMdl ls oeoe{ pbi fnto _cntut$otie=ra() ulc ucin _osrc(cnanrary) { / TD:frhrrfco oc dic i pae / OO ute eatr ne ... n lc $q ="; sl " $ur =Dtbs:qey$q) qey aaae:ur(sl; }}atr fe
  18. 18. LAZY LOADINGBy utilising closures, code isnt run until it is first requested /called; i.e. database connection is established only when you first try and use the connection $otie[d =fnto(c { cnanrb] ucin$) rtr nwD(..,$[d_sr] $[d_w) eun e PO"." cbue, cbpd]; };
  19. 19. SHARING OBJECTS$otie[d =$otie-saefnto(c {cnanrb] cnanr>hr(ucin$) rtr nwD(..,$[d_sr] $[d_w) eun e PO"." cbue, cbpd];};)
  20. 20. FURTHER REFACTORING<pp ?hcasSmMdl ls oeoe{ pbi fnto _cntut$otie=ra() ulc ucin _osrc(cnanrary) { $q ="; sl " $ur =$otie[d-qey$q) qey cnanrb]>ur(sl; }}
  21. 21. CREATING YOUR OWN CONTAINERParticularly useful for re-use and different use-cases (cli vs web) <pp ?h nmsaePoetFaeokCnanr aepc rjcrmwrotie; casMCnanretnsipe ls yotie xed Pml { pbi fnto _cntutary$aus=ary) ulc ucin _osrc(ra vle ra() { prn:_cntut$aus; aet:_osrc(vle) / adtig t tecnanrhr / d hns o h otie ee } }
  22. 22. CONTROLLER REFACTORING (BEFORE)<pp ?hcasSmCnrle ls oeotolr{ / .. / . pbi fnto smAto( ulc ucin oecin) { $oe =nwSmMdl$hs>otie) mdl e oeoe(ti-cnanr; }}
  23. 23. REDUCING NEW...CONTAINERS WITHIN CONTAINERS<pp?hnmsaeFciiFaeokCnanraepc aefrmwrotie;casDtAcsOjcsetnsipe ls aacesbet xed Pml{ pbi fnto _cntutary$aus=ary) ulc ucin _osrc(ra vle ra() { prn:_cntut$aus; aet:_osrc(vle) $hssr]=$hs>hr(ucin$){ ti[ue ti-saefnto(c rtr nwUeDo$[cnanr]; eun e sra(cotie) }; ) }}
  24. 24. CONTROLLER REFACTORING (AFTER)<pp ?hcasSmCnrle ls oeotolr{ / .. / . pbi fnto smAto( ulc ucin oecin) { $oe =$hs>otie[fcois]oemdl]>e mdl ti-cnanratre[sm_oe-nwMdl) oe(; }}
  25. 25. HARDCODED CONFIGURATIONS
  26. 26. YAML
  27. 27. A YAML FILEd_yq:bmsl hs:oahs ot lclot ue:ot sr ro ps: as nm:b ae d pr:30 ot 36 at_ac:tu uopth regnrleea: pouto:fle rdcin as si:ees kn rlae st_r:tp/lclot46/ ieul ht:/oahs:57
  28. 28. PARSING A YAML FILE$al=nwSmoyCmoetYmasr)ym e yfnopnnalPre(;$asdstig =$al>as(iegtcnet(_I_./ofgyl) pre_etns ym-prefl_e_otns_DR_cni.m);
  29. 29. CACHING :-(
  30. 30. SCATTERED ROUTING LOGIC, LONG IF/ELSE CONDITIONS
  31. 31. ROUTING
  32. 32. REFACTORING FOUNDATIONSMostly taken care of when we ensured all controllers were objects and that the new structure followed PSR-0. Controllers refactored like so: pbi fnto _cntut$otie) ulc ucin _osrc(cnanr { $hs>otie =$otie; ti-cnanr cnanr } pbi fnto aOdcin$ae $oei) ulc ucin nlAto(dt, sm_d pbi fnto aeAto(ulprm=ra() ulc ucin Nwcin$r_aasary)
  33. 33. SETTING IT UP Alias some of the namespacesueSmoyCmoetCniieoao;s yfnopnnofgFlLctrueSmoyCmoetRuigRqetotx;s yfnopnnotneusCnetueSmoyCmoetRuigs yfnopnnotn; Prepare dependencies$oao =nwFlLctraryFAEOKPT);lctr e ieoao(ra(RMWR_AH)$eus =(se(_EVREUS_R)?$SRE[RQETUI];rqet ist$SRE[RQETUI]) _EVREUS_R:$otx =nwRqetotx(rqet $SRE[RQETMTO)cnet e eusCnet$eus, _EVREUS_EHD]; Construct$otr=nwRuigRue(e YmFlLae(lctr,otsyl,rue e otnotrnw alieodr$oao) rue.mary) $otx)ra(, cnet;
  34. 34. ROUTES FILEidxne: pten / atr: dfut:{cas rjcttcCnrle mto:oeae } eals ls: PoetSaiotolr, ehd hmPg rqieet: eurmns _ehd GT mto: E
  35. 35. ROUTINGty{ r $r =(se(_EVREUS_R) ?$SRE[RQETUI]: ul ist$SRE[RQETUI]) _EVREUS_R; / gtrdo tetaln sah / e i f h riig ls $r =(tln$eusUL >1 ?rrm$eusUL :$r; ul sre(rqetR) ) ti(rqetR, /) ul $ot =$otr>ac(ul; rue rue-mth$r) $otolr=nw$ot[cas]$otie) cnrle e ruels(cnanr; $cin=$otolr>rueehd]) ato cnrle-$ot[mto(;}cth(otnxetoeoreoFudxeto $){ ac RuigEcpinRsucNtonEcpin e / td:44 / oo 0}
  36. 36. ROUTE VARIABLEScmetsoyadomn_tr_d: pten /es{aeoy/dt}{ril} atr: nw/ctgr}{ae/atce dfut:{cas omnsCnrle:adomn} eals ls: Cmetotolr:dCmet rqieet: eurmns dt:"09{}[-]2-09{} ae [-]2-09{}[-]4" _ehd PS mto: OT$ot =$otr>ac(ul;rue rue-mth$r) $otolr=nw$ot[cas]$otie) cnrle e ruels(cnanr; $aibe =$ot; vrals rue ust$aibe[nm,$aibe[cas] $aibe[mto) ne(vralsae] vralsls, vralsehd]; $cin=$otolr>rueehd]) ato cnrle-$ot[mto(;
  37. 37. AUTHENTICATION CONTROLacutcon: pten /con atr: acut dfut:{cas rjcconotolr,mto:aae,lg eals ls: PoetAcutCnrle ehd mng oge_n tu }di: re rqieet: eurmns _ehd GT mto: Ei (se(rueogdi) { f ist$ot[lge_n]) i (snl(cnanrsr]){ f i_ul$otie[ue) / Ue i tyn t acs lge i ol cnet-rdrc t / sr s rig o ces ogd n ny otn eiet olgnadsoerdrc oi n tr eiet $SSINeiet]=$SRE[RQETUI] _ESO[rdrc _EVREUS_R; $vn =nwEeteusRdrcin$otie[stig[b eet e vnsRqeteieto(cnanretns]as_r .oi/) eul] lgn; $hs>otie[dsace-dsac(rdrc $vn) ti-cnanripthr]>iptheiet, eet; }}
  38. 38. ROUTE CACHING$otr=nwRuigRue(e YmFlLae(lctr,otsyl,rue e otnotrnw alieodr$oao) rue.maryah_i= vrwwcce,$otx)ra(ccedr > /a/w/ah/) cnet;
  39. 39. UTM DATA, ETC $r =pe_elc(/?t_.?[&+ ,$r) ul rgrpae&um(*)=^]/, ul; $r =(usr$r,-)= ?rrm$r, :$r; ul sbt(ul 1 = ?) ti(ul ?) ulhttp://forums.phpfreaks.com/topic/257622-remove-utm- tags-from-url-regex/
  40. 40. DUPLICATED LOGIC
  41. 41. EVENT DISPATCHER
  42. 42. WHY?
  43. 43. USE CASESRedirecting the user / flash notificationsSending transactional emailsAdding a product to a basketHooking into other features to share other features e.g.tweet on content creation
  44. 44. REDIRECTION & "FLASH" NOTIFICATIONS1. Raise an event2. Listen for notification events, and log the notification in- session3. Listen for a redirect event, and redirect Ordering is important here as we dont want to redirect before setting the session!
  45. 45. APPROACHNotifiableMessageInterfaceRequestRedirection eventRedirectableNotification event (extends and implementsthe above)Events must extend the symfony event
  46. 46. NOTIFIABLE MESSAGE INTERFACE<pp?hnmsaePoetFaeokEet;aepc rjcrmwrvnsitraeNtfalMsaenefc nefc oiibeesgItrae{ pbi fnto gtoiiain) ulc ucin eNtfcto(; / tehm cast b apid / h tl ls o e ple pbi fnto gtls(; ulc ucin eCas)}
  47. 47. REQUEST REDIRECTION EVENT<pp ?hnmsaePoetFaeokEet; aepc rjcrmwrvnsueSmoyCmoetEetipthrEet s yfnopnnvnDsacevn;casRqeteieto etnsEet ls eusRdrcin xed vn{ poetd$r; rtce ul pbi fnto _cntut$r =nl) ulc ucin _osrc(ul ul { $hs>r =$r; ti-ul ul } pbi fnto gtR( ulc ucin eUL) { rtr $hs>r; eun ti-ul }}
  48. 48. LISTENER<pp?hnmsaePoetFaeokLseesaepc rjcrmwritnr;uePoetFaeokEet;s rjcrmwrvnsueSmoyCmoetEetipthrEets yfnopnnvnDsacevn;casStessatoiiain ls ePritnNtfcto{ pbi fnto stoiiain EetoiibeesgItrae$ ulc ucin eNtfcto( vnsNtfalMsaenefc evn ) et { $SSINytmntfcto =$vn-gtoiiain) _ESO[sse_oiiain] eet>eNtfcto(; $SSINytmntfcto_ls =$vn-gtls(; _ESO[sse_oiiaincas] eet>eCas) }}
  49. 49. ANOTHER LISTENER<pp?hnmsaePoetFaeokLseesaepc rjcrmwritnr;uePoetFaeokEet;s rjcrmwrvnsueSmoyCmoetEetipthrEets yfnopnnvnDsacevn;casRdrc ls eiet{ pbi fnto rdrcUe(EeteusRdrcin$vn ) ulc ucin eietsr vnsRqeteieto eet { / TD:uiiehtfaeok / OO tls tprmwr hae(Lcto:".$vn-gtR( ) edr"oain eet>eUL) ; ei(; xt) }}
  50. 50. LISTEN UP...Create an event dispatcherCreate instance of listenerAdd the listener Event name A callable e.g. Object/Method array combo, Closure, etc Priority: for multiple listeners listening for the same event
  51. 51. LISTEN UP$ipthr=nwEetipthr)dsace e vnDsace(;/ Ntfcto (ucs,Wrig Err / oiiain Sces ann, ro)$ePritnNtfcto =nwLseesStessatoiiain) stessatoiiain e itnrePritnNtfcto(;$ipthr>dLsee(ntf ary$ePritnNtfcto,e dsace-aditnroiy, ra(stessatoiiain stNtfcto,1) oiiain) 0;/ Rdrc / eiet$eietsr=nwLseesRdrc(; rdrcUe e itnreiet)$ipthr>dLsee(ntfy,ary$eietsr eietsr) dsace-aditnroii ra(rdrcUe, rdrcUe, 0; )
  52. 52. DISPATCH$r =$aeul.conul bs_r acut;$esg =orpswr wscagdscesuymsae Yu asod a hne ucsfl.;$vn =nwEeteietbeoiiain$r,$esg,ucs;eet e vnsRdrcalNtfcto(ul msae sces)$ipthr>ipthoiy,$vn)dsace-dsac(ntf eet;
  53. 53. GOTCHASget/set Name
  54. 54. STANDARD EVENT We tend to use our own event object which extends thesymfony one. This holds a payload which is our event related object. <pp ?h nmsaePoetFaeokEet; aepc rjcrmwrvns casEetetnsyfnopnnvnDsacevn ls vn xed SmoyCmoetEetipthrEet { poetd$aLa; rtce pyod pbi fnto staLa(pyod ulc ucin ePyod$ala) { $hs>aLa =$ala; ti-pyod pyod } pbi fnto gtaLa( ulc ucin ePyod) { rtr $hs>aLa; eun ti-pyod } }
  55. 55. QUEUEABLEInterface to define an event as something that can bequeuedListener to queue the event e.g. in beanstalk <pp ?h nmsaePoetFaeokEet; aepc rjcrmwrvns itraeQeebenefc nefc uualItrae { pbi fnto gtd) ulc ucin eI(; }
  56. 56. QUEUE AN EVENT IN YOUR LISTENERpbi fnto cekvn(vnsEet$vn) ulc ucin hcEetEetvn eet{ i (eet>ePyod)isaco Qeebenefc){ f $vn-gtaLa( ntnef uualItrae $ue_a =arye.sr = we; tbsmp ra(nwue > tet) $d=$vn-gtaLa(-gtd) i eet>ePyod)>eI(; $ue=$ue_a[eet>eNm(] tb tbsmp$vn-gtae); $hs>otie[q]>sTb(tb)>u(i) ti-cnanr-ueue$ue-pt$d) }}
  57. 57. PHP & HTML MIXED TOGETHER
  58. 58. TWIG
  59. 59. SETUP AND LOAD/ cet ati flsse lae s i cnacs tmlts / rae wg ieytm odr o t a ces epae$odr=nwwgLae_ieytmepae; lae e Ti_odrFlsse(tmlts)/ cet anwti evrnetadps i telae / rae e wg niomn n as t h odr$wg=wgEvrnet$odr; ti Ti_niomn(lae) Load and render template/ la tetmlt / od h epae$wg>odepaene.wg) ti-laTmlt(idxti;/ rne i / edr t$wg>edraryil= aibe); ti-rne(ra(tte > vral)
  60. 60. REFACTORING TO TWIGA place to prepare twig and also perform any non-twigpresentation logic. Keeps the data de-coupled from the workings of the template engineasrc casVe btat ls iw{ pbi fnto _cntut$otie) ulc ucin _osrc(cnanr { $odr=nwwgLae_ieytmepae; lae e Ti_odrFlSse(tmlts) $hs>epaenie=nwwgEvrnet$odr; ti-tmltEgn e Ti_niomn(lae) } pbi fnto gnrt(mdlnl) ulc ucin eeae$oe=ul; pbi fnto rne(tmlt_ie ulc ucin edr$epaefl) { $hs>epaenie>odepae$epaefl) ti-tmltEgn-laTmlt(tmlt_ie; eh $wg>edr$hs>otie-tmltVrals; co ti-rne(ti-cnanr>epaeaibe) ei; xt }}
  61. 61. PIMPLE ISSUE / ADD GLOBAL
  62. 62. TWIG TEMPLATES{ sm_aibe} { oevral }{ sm cmet# # oe omn }{ stls_fies=vral.eIes)% % e ito_tm aibegttm( }{ frie i ls_fies% % o tm n ito_tm } <i{lo.ne}:{ie.ae}/i l>{opidx} {tmnm}<l>{ es % % le } <iEpy:(/i l>mt -<l>{ edo % % nfr }
  63. 63. TEMPLATE CACHING This caches compiled templates not output$hs>wg=nwwgEvrnet$odr aryti-ti e Ti_niomn(lae, ra( ah= vrwwccetmlts, cce > /a/w/ah/epae/ ); )
  64. 64. OUTPUT CACHING
  65. 65. SETUP OUTPUT CACHINGueDsrol2CceCces earlaahah;ueDsrol2CceAatrFl;s earlaahdpeie$dpe =nwFl(; aatr e ie)$dpe-stpint (n)$otie[ms_ofg]>ah-tl; aatr>eOto(tl, it cnanriccni-cce>t)ty{ r $dpe-stpinahDr,vrwwccepgs; aatr>eOto(ccei /a/w/ah/ae/)}cth(Ecpin$){ ac xeto e / tmoaiyltteapiainuete/m fle? / eprrl e h plcto s h tp odr}$ah =nwCce$dpe)cce e ah(aatr;
  66. 66. INTEGRATING OUTPUT CACHING$ah_e =m5$r) cceky d(ul;i (cceeald& $ot[ccal){ f $ah_nbe & rueahbe] i(snl(ti-cnanrsr]& $ah-hs$ah_e) { fi_ul$hs>otie[ue & cce>a(cceky) eh $ah-gt$ah_e) co cce>e(cceky; ei; xt }}
  67. 67. VALIDATOR (FUEL)There is a symfony component which does this, though we opted for the Fuel validation component.
  68. 68. HTTPFOUNDATIONAbstracting superglobals, the HTTP request and the HTTP response
  69. 69. REQUEST ueSmoyCmoetHtFudtoeus; s yfnopnntponainRqet $eus =Rqet:raermlbl(; rqet eus:cetFoGoas) Provides a parameter bag of propertiesProperty Purposerequest store $_POSTquery store $_GETcookies store $_COOKIEattributes application specificfiles $_FILEserver $_SERVERheaders subset of $_SERVER
  70. 70. A PARAMETER BAG?Request properties are all ParameterBag or sub-classesProvides special methods to manage contents, including: all keys get add set has remove
  71. 71. RESPONSEueSmoyCmoetHtFudtoepnes yfnopnntponainRsos;$epne=nwRsos(;rsos e epne)$epne>eCnetel PPK)rsos-stotn(Hlo HU;$epne>eSauCd(0)rsos-stttsoe20;$epne>edr-stotn-ye,etpan)rsos-haes>e(CnetTp tx/li;/ atraiey. / lentvl..$epne=nwRsos(HloPPK,20 aryotn-ye,et rsos e epneel HU 0, ra(cnettp tx/pan); li)$epne>rpr(;rsos-peae)/ sn tersos t teue / ed h epne o h sr$epne>ed) rsos-sn(;
  72. 72. TRANSLATIONWorth a mention
  73. 73. SWIFT MAILER
  74. 74. SMTP TRANSPORT$rnpr =wf_mprnpr:nwntne$otie[stig[stasot SitStTasot:eIsac(cnanretns]mt[hs,2)p]ot] 5 -stsrae$otie[stig[st[ue) >eUenm(cnanretns]mp]sr] -stasod$otie[stig[st[ps) >ePswr(cnanretns]mp]as];
  75. 75. CREATE THE MESSAGE$hs>esg =wf_esg:nwntne$ujc)ti-msae SitMsae:eIsac(sbet -strmary$rm= $rmnm) >eFo(ra(fo > fo_ae) -stoary$eiin = $eiin_ae) >eT(ra(rcpet > rcpetnm) -stoy$oy $otn_ye; >eBd(bd, cnettp)
  76. 76. SEND THE MESSAGE$alr=wf_alr:eIsac(tasot;mie SitMie:nwntne$rnpr)rtr $alr>ed$esg)eun mie-sn(msae;
  77. 77. THANKS! @MICHAELPEACOCKWWW.MICHAELPEACOCK.CO.UK HTTPS://JOIND.IN/8046
  78. 78. IMAGE CREDITShttp://www.flickr.com/photos/oskay/275142789/http://www.flickr.com/photos/martin_bircher/5287769680/http://www.flickr.com/photos/tronixstuff/5122815499/http://www.flickr.com/photos/tronixstuff/4581416773/http://www.flickr.com/photos/oskay/437339684/http://www.flickr.com/photos/oskay/437342078/http://www.flickr.com/photos/laughingsquid/2885196845/
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×