Simplify your code with annotations - SymfonyCon Warsaw 2013

1,791 views
1,668 views

Published on

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,791
On SlideShare
0
From Embeds
0
Number of Embeds
430
Actions
Shares
0
Downloads
24
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Simplify your code with annotations - SymfonyCon Warsaw 2013

  1. 1. /** * @SIMPLIFY YOUR CODE * WITH ANNOTATIONS **/ Created by Piotr Pasich / @piotrpasich
  2. 2. WWW.XSOLVE.PL @XSOLVE
  3. 3. „I HATE A LONG DISTANCE BETWEEN YOU AND ME” ENTITY
  4. 4. LET’S START WRITING A STORY
  5. 5. /* * * Ei s a e it n Ps e tt . d t n xs ig o t ni y * *@o t (/ i} ,n m= p s_ pa e) R ue "{ d" ae "o tu d t" *@e h d" U" M to (P T) *@e p ae "s le yf n Cn ud eP s: d th m. wg ) T ml t ( Xo v Sm oy oB n l: ot ei .t l ti " * / p bi f nt o u d tA to(e u s $ eu s,$ d u l c u c i n p a e c i nR q e t r q e t i ) { $ m= $h s > e Dc rn (- g ta ae (; e t i- gt ot i e) >e Mn gr ) $ ni y= $m > eR ps tr ( Xo vS mo yo B nl :o t) >i d$d ; ett e -g te o io y' sl ey f nC nu de P s' -f n(i ) i ( $n iy { f ! et t ) t rw $h s >r ae oF u dx et o(Ua l t fn P s e t t. ) ho t i- ce t Nt on Ec pi n'n be o i d o t ni y' ; } $ ee eo m= $ hs >r ae e ee om$d ; d l tF r t i- c et Dl tF r(i ) $ d t o m = $ h s> r a e d t o m $ n i y ; e i Fr ti-c e tE iF r( et t ) $ dt om>a d ee us (r q et ; e i Fr-h nl Rq e t$ eu s) i ( ei Fr-i Vl d ) { f $ dt om> sa i( ) $ m> ls ( ; e- fu h) r tr $ hs>e i et $h s> ee a er (p s_ d t, ar y ' d = $d ); eu n t i-r dr c( t i- gn rt Ul ' ot ei ' ra ( i' > i ) ) } r tr a ry eun ra( ' ni y et t' = $ ni y > e tt , ' dt fr ' = $ dt om>r ae i w) ei _o m > e iF r-c et Ve (, ' ee ef r '= $ ee eo m> ra e iw ) dl t_ om > d lt F r- ce tV e( , ) ; }
  6. 6. WELL, WE ARE NOT THE BEST WRITERS, ARE WE?
  7. 7. @ROUTE
  8. 8. /* * * @o t( /i }, n m= ps _p a e) Ru e "{ d" a e" o tu dt " * @e hd"U " Mt o(P T) */ *
  9. 9. c as Ru e ls ot { p ia e$a h rv t pt ; p ia e$a e rv t nm ; p ia e$e ur mn s =a ry ) rv t rq ie e t ra(; p ia e$p in =ar y) rv t ot os ra ( ; p ia e$e al s =ar y ) rv t df ut ra(; p ia e$o t rv t hs ; p ia e$e hd =ar y) rv t mt os ra ( ; p ia e$c ee =ar y) rv t sh ms ra ( ; p ia e$o dt o ; rv t cn ii n / *. . */ *( .) * }
  10. 10. /* * * @o t( /i }, n m= p s_ pa e, Ru e "{ d" ae "o tu d t" * m to s "U " eh d= PT * r qi e et =" d =" d" ) eu rm ns { i" +} */ *
  11. 11. @TEMPLATE
  12. 12. /* * * @e pa e "s le yf n Cn ud eP s: d th m. wg ) Tm l t( Xo v Sm oy oB n l: ot ei .t l ti " */ *
  13. 13. c as Tm lt l s e pa e { p ia e$e pa e rv t tm lt ; p ia e$n ie =’ ti ’ rv t eg n w g; pi ae $a s =a ry ) rv t v r ra(; p ia e$t em be =f l e rv t sr aa l as; / *. . */ *( .) * }
  14. 14. i (! $ hs >e (s cr t .o tx '- iG a td 'O EE I O' ){ f t i- gt ' eu iy cn e t) >s rn e( R L_ DT R ) tr w n wA c sD ne Ec p in ) h o e ce se i dx et o( ; }
  15. 15. @SECURITY
  16. 16. u eS ni u de F ae ok xr B nl o fg rt o e ui y s e s oB nl r mw r Et au de Cn i ua in Sc r t; /* * *@e u iy "a _o e' O EE IO '" S cr t ( hs r l( RL _D T R) ) * /
  17. 17. p bi f nt o u d tA to(e u s $ eu s,$ d u l c u c i n p a e c i nR q e t r q e t i ) { $ m=$h s> e Dc rn (- g ta ae (; e t i- gt ot i e) >e Mn gr ) $ ni y=$m > eR ps tr ( Xo vS mo yo B nl :o t) >i d$d ; ett e -g te o io y' sl ey f nC nu de P s' -f n(i ) i ($ ni y { f !e tt ) t r w $ h s> r a e o F u d x e t o ( U a l t f n P s e t t . ) h o ti-c e tN to nE cp i n' nb e o id ot n iy ' ; } }
  18. 18. @PARAMCONVERTER
  19. 19. u eS ni u de F ae ok xr B nl o fg rt o a aC ne tr s e s oB nl r mw r Et au de Cn i ua in Pr m ov re ; /* * * @a aC ne tr" ot ,c as " sl ey fn Cn u de Ps " Pr m ov re(p s" ls =X ov Sm o yo Bn l: o t) * / p bi f nt o u d tA to(e u s $ eu s,P s $o t u l c u c i n p a e c i nR q e t r q e t o t p s ) { }
  20. 20. c as Pr mo vr e ​ l s a aC ne tr ​ { p ia e$ ae ​ r v t nm; p ia e$ ls ; r v t ca s​ p i a e $ p i n = a r y) ​ r v t ot os ra(; p ia e$ pi n l= fl e r v t ot oa as; }
  21. 21. /* * * @o t( /l g{ a e/ su }" Ru e "b o/ dt }{ l g/ ) * @a aC ne tr" ot ,o to s {e cu e: {d t "} Pr m ov re(p s" pi n= "x ld " " ae }) * @a aC ne tr" ot , Pr m ov re(p s" c as "X ov Sm o yo Bn l: ot ) , l s= s l ey fn Cn u de Ps " o to s{ p in = " ap n" { dt " "a e, "l g :" lg } m pi g : " a e: d t" s u" s u ", " eo io ym t o" =" id ih o n" r ps t r_ eh d fn Wt Ji s} } * /
  22. 22. YOUR OWN PARAMCONVERTER
  23. 23. n ms aeSn i u de Fa eo k xr Bn l eu s a aC ne tr a ep c e so Bn l r mw rE ta ud e Rq et Pr m ov re ; u eS ni u de F ae ok xr B nl o fg rt o o fg rt oI t ra e s e s oB nl r mw r Et au de Cn i ua in Cn i ua in ne fc ; u eS mo yC mo e tH tF ud t o eu s; s y f n op nn t p on ai nR qe t i tr aePr mo v re It ra e n ef c a aC ne tr n ef c { f nt o ap yR qe t$e us ,C ni u ai nn ef c $o fg r to ) u c in pl ( eu s rq e t of gr to I tr ae c ni ua in ; f nt o sp ot (o f gr to It ra e $o fg rt o ) u c in up r sC ni ua i nn ef c cn i ua in ; }
  24. 24. n ms aeXo v y fn Cn ud e Rq et Pr mo v re ; a ep c S le Sm oy o Bn l eu s a aC ne tr u eS ni u de F ae ok xr B nl e us a a Cn et rP rm o vr eI tr a e s e s oB nl r mw r Et au de Rq e tP rm ov r e aa Cn et r ne fc ; c as Wb ev cP r mo vr e ip ee t Pr mo v re It ra e l s e sr ie aa Cn e tr m lm ns a aC ne tr n ef c { p oe td$e s ri e r t ce w be vc ; p bi f nt o _c nr c ( e sr ie $e sr i e{ u l c u ci n _o t ut Wb ev c w be vc ) $hs >e s ri e= $e s ri e ti -w be vc w be vc ; } p bi f nt o ap yR qe t $e us ,P rm o vr e $o fg rt o) u l c u ci n pl ( eu s rq et aa Cn et r cn iu a in { $ ae =$ o fg rt o- g ta e) / Te at iu e nm nm cn iu a in >e Nm (; / h t rb t ae $ ls = $o fg r to - g tl s ( ; /T ea ti u ec as nm ca s c ni ua in > eC as ) /h tr bt l s a e $ pi n =$ hs > eO to s$ of g rt o) / A ar y o o to s ot os ti - g tp i n( cn iu ai n ; / n ra f p in $ b =$ hs > e s ri e> id $p i n[ i ' ) oj t i-w be vc -fn (o to s'd ]; $ eu s-a ti ue (p r m $ b) rq et >t rb t s $ aa , oj ; r tr t u; eu n r e } p bi f nt o sp ot (o f gr to It ra e$o fg rt o ) u l c u ci n up r sC ni ua in n ef c cn i ua in { $ pi n =$hs > eO to s$ of g rt o) ot os ti -g tp i n( cn iu ai n ; r tr $ hs>e s ri e> id $p i n[ i')! n l; eu n t i-w be vc - fn (o to s ' d] = ul } }
  25. 25. # ap cn i/ of g yl p/ o fg cn i. m s ri e: e vc s w be vc .a a .o vr e e s ri ep rm cn e tr c as ls: X ov y f nC nu de Rq e tP rm ov re es ri ea a Cn e S l eS mo yo Bn l e us a a Cn et rW be v cP rm ov a gm ns ru et : - @e s ri e w be vc t g: as - {n m :r qe tp r mc ne tr p ir t: -,c ne tr w be vc O j} ae e u s. aa _o vr e , r o iy 2 o vr e : e s ri eb
  26. 26. /* * * @a aC ne tr Pr m ov re */ * p bi f nt o s o At o( es r ie b $ e sr ie b) u lc u ci n hw ci n Wb ev cO j wb ev c Oj ;
  27. 27. VALIDATION
  28. 28. p oe td $h rD s rp in r tc e s ot ec it o ; p oe td $a s= a ry ) r tc e t g ra(;
  29. 29. /* * *@s e tN tl n( A sr o Ba k ) *@s e tL nt ( A sr e gh * m n= "" i 2, * m x= "5 " a 2 0) * / p oe td $h rD s rp in r tc e s ot ec it o ; /* * *@s e tA l{ A sr l ( * @ se tN tl n, A sr o B ak * @ se tL nt (i = "" A sr e g hm n 1) *} ) * / p oe td $a s= a ry ) r tc e t g ra(;
  30. 30. YOUR OWN VALIDATOR
  31. 31. n ms aeXo v y fn Cn ud e Vl dt rC nt a ns a ep c S le Sm oy o Bn l ai ao os ri t; u eS mo yC mo e tV ld tr C nt an ; s y f n op nn a i ao o sr it /* * *@n o ai n A nt to * / c as Cn an Ea p ee tn sC n ta n l s o ti sx ml x e d os ri t { p bi $ es g =' h ea pe i nt vl d' u l c m sa e T e xm l s o a i.; }
  32. 32. u eX ov y fn C nu de Vl d tr Cn ta ns a Sm o yo ; s S l eS mo yo Bn l a ia o os r it s y fn Cn c as Ea pe ni y l s x ml Et t { / .. / . /* * * @ yf nC nC na n Ea pe S mo yo ot is xm l * / p oe td $r p ry r t ce p oe t; / .. / . }
  33. 33. $ hs >p ae ae =nw Dt Tm ( ; t i- u dt Dt e a ei e)
  34. 34. @ORMPREPERSIST() @ORMPREUPDATE()
  35. 35. /* * * @Rn iy OME tt * @Ra Lf cc e al ak OMH si ey lC lb c s * / c as Ps { ls ot /* * * @Rr Pr i t) O MP e e s s ( * @Rr Ud t ( O MP e p a e ) * / p bi f nt o pe pa e) / (. )/ u l c u ci n rU d t({* .. *} }
  36. 36. NOTIFICATIONS
  37. 37. SERVICES
  38. 38. JMSDIEXTRABUNDLE HTTP://JMSYST.COM/BUNDLES/JMSDIEXTR ABUNDLE/MASTER/ANNOTATIONS
  39. 39. /* * * @e vc Sr i e * @a(d cr n. v n_ it nr , at iu e ={ ee t =" ot pa e } Tg" ot ie ee tl s ee " tr bt s " v n" ps Ud t" ) * / c as Mi Nt fc t oS ri e l s a lo ii ai ne v c { /* * * @n et aa s { I jc Pr m( * " al r =@ ne t" a lr ) m ie " I j c( mi e" *} ) * / p bi f nt o _c nt ut S it Mi e $a lr { /( .) / u l c u ci n _o s rc (w f_ al r mi e ) * .. *} p bi f nt o ps Ud t ( i ey lE et rs$ rs { /( .) * } u l c u ci n ot p ae Lf cc ev n Ag a g) *. . / }
  40. 40. p bi f nt o p s Ud t( ie y lE et rs $r s u lc u ci n ot pa e Lf cc ev nA g a g) { $ ni y= $r s >e Et t( ; ett a g- gt n iy ) i ( et t i s ac o Ps ){ f $ ni y nt ne f ot / *s n nt fc t o * / * ed o ii ai n * } }
  41. 41. PERFORMANCE
  42. 42. @CACHE (+ VARNISH + ESI)
  43. 43. p bi f nt o s o At o( eu s $e us , Ps $ ot { u lc u ci n hw ci n Rq et r qe t ot p s) $ ep ne= n w Rs os (; r s os e ep n e) $ ep ne>e L sM df e( p s- gt pa eA ( ) r s os-s ta to i id $o t> eU d td t) ; i ( rs os-i Nt o ii d$ eu s) { f $ ep ne> so Md fe ( rq et ) r tr $ ep ne eu n r s os; } $ ep ne >e E pr s " oo r w) r s os -s tx ie ( tm ro "; $ ep ne>e M xg (0 ) r s os -s ta Ae 6 0; $ ep ne>e S ae Mx g( 0 ) r s os-s th rd a Ae 60 ; $ ep ne>e P bi (r e; r s os-s tu lc t u) r tr $ ep ne e u n r so s; }
  44. 44. /* * *@a h (x ie =t mr o " p b i= tu " C ce ep rs " oo rw , ul c" re ) * / p bi f nt o so At o (o t $ ot { *( .) *} ul c uc in h wc in Ps ps) / * .. */
  45. 45. CONCLUSION
  46. 46. BEFORE
  47. 47. /* * * Ei s a e it n Ps e tt . d t n xs ig o t ni y * *@o t (/ i} ,n m= p s_ pa e) R ue "{ d" ae "o tu d t" *@e h d" U" M to (P T) *@e p ae "s le yf n Cn ud eP s: d th m. wg ) T ml t ( Xo v Sm oy oB n l: ot ei .t l ti " * / p bi f nt o u d tA to(e u s $ eu s,$ d u l c u c i n p a e c i nR q e t r q e t i ) { i ( ! $ hs >e (s c rt .o tx '- i Ga td 'O E EI O' ){ f t i - g t' eu iy c ne t) >s rn e (R L_ DT R ) tr w n w Ac sD ne E cp in ) h o e ce s ei dx et o( ; } $ m= $h s > e Dc rn (- g ta ae (; e t i- gt ot i e) >e Mn gr ) $ ni y= $m > eR ps tr ( Xo vS mo yo B nl :o t) >i d$d ; ett e -g te o io y' sl ey f nC nu de P s' -f n(i ) i ( $n iy { f ! et t ) t rw $h s >r ae oF u dx et o(Ua l t fn P s e t t. ) ho t i- ce t Nt on Ec pi n'n be o i d o t ni y' ; } $ ee eo m= $ hs >r ae e ee om$d ; d l tF r t i- c et Dl tF r(i ) $ d t o m = $ h s> r a e d t o m $ n i y ; e i Fr ti-c e tE iF r( et t ) $ dt om>a d ee us (r q et ; e i Fr-h nl Rq e t$ eu s) i ( ei Fr-i Vl d ) { f $ dt om> sa i( ) $ ni y> e Ud tD t(e Dt Tm ( ) et t- st pa e aenw a ei e) ; $ m> ls ( ; e- fu h) t y{ r $ hs> e( xo v. m i. oi ia o'- sn (e tt ) ti-g t ' s le ea ln tf c tr)> ed $ ni y; } ct h(x et o $) { a c Ec pi n e $ hs> e( ss in) >e Fa ha ( t i - g t ' e s o '- g t l s B g )
  48. 48. AFTER
  49. 49. /* * *@o t (/ i} ,n m= p s_ pa e, mt o s" U" R ue "{ d" ae "o tu d t" e hd =P T ) *@e p ae "s le yf n Cn ud eP s: d th m. wg ) T ml t ( Xo v Sm oy oB n l: ot ei .t l ti " *@a a Cn et r P rm ov re *@e u iy "a _o e' O EE IO '" S cr t ( hs r l( RL _D T R) ) * / p bi f nt o u d tA to(e u s $ eu s,P s $o t u l c u c i n p a e c i nR q e t r q e t o t p s ) { $ ee eo m= $ hs >r ae e ee om$o t> e I( ) d l tF r t i- c et Dl tF r(p s- gt d) ; $ d t o m = $ h s> r a e d t o m $ o t ; e i Fr ti-c e tE iF r( ps ) $ dt om>a d ee us (r q et ; e i Fr-h nl Rq e t$ eu s) i ( ei Fr-i Vl d ) { f $ dt om> sa i( ) $ m> ls ( ; e- fu h) r tr $ hs>e i et $h s> ee a er (p s_ d t, ar y ' d = $d ); eu n t i-r dr c( t i- gn rt Ul ' ot ei ' ra ( i' > i ) ) } r tr a ry eun ra( ' ni y et t' = $ ni y > e tt , ' dt fr ' = $ dt om>r ae i w) ei _o m > e iF r-c et Ve (, ' ee ef r '= $ ee eo m> ra e iw ) dl t_ om > d lt F r- ce tV e( , ) ; }
  50. 50. @ANNOTATION
  51. 51. n ms aeXo v y fn Cn ud e An tt o; a ep c S le Sm oy o Bn l no ai n /* * *@n o ai n A nt to * / c as Si cL gt l s w th ih { p ia e$ om r v t ro; p bi f nt o st om $o m u l c u ci n eR o (r o) { $ hs>o m =$ om ti-r o ro; } p bi f nt o gt om $o m u l c u ci n eR o (r o) { r tr $ hs>o m eu n t i-r o; } }
  52. 52. n ms aeXo v y fn Cn ud e An tt o rv r a ep c S le Sm oy o Bn l no ai n Di e; u eX ov y fn C nu de An t to w th ih ; s S l eS mo yo Bn l n oa in Si c Lg t /* * *@n o ai n A nt to * / c as An tt oD i e l s n oa in rv r { p ia e$ ed r r v t ra e; p ia e$ om i h; r v t ro Lg t p bi f nt o _c nt ut $ ed r L g t$ om ih ) u l c u ci n _o s rc (r ae , ih r o Lg t { $ hs>e d r= $e dr / gt an tt os r ae ti-r ae r ae ;/ e no a in e dr $ hs>o m ih = $o mi h ; ti-r oL gt ro L gt } p bi f nt o oK re Cn r le (i tr ot o lr vn $ vn ) u l c u ci n ne n lo to lr Fl e Cn rl eE e t e et { i ( i_ ra (c n rl e =$ vn -g to t ol r) ){ /r t r i n c nr le f ! sa r y$ ot ol r e et > eC nr le ( ) / eu n f o o t ol r r tr ; eu n } $ be t= n w el ci n be t$ ot ol r0) / gt cn rl e oj c e R f et oO jc (c n rl e[]; / e ot o lr $ eh d= $ be t> eM t o( cn rl e[ ] ;/ gt mt o mt o o jc - gt eh d$ ot o lr1) / e e hd f ra h( t i - ra e- g te hd no ai n (m to ) a $ of gr t o) {/ Sa oe c $h s> e dr >e Mt oA n tt os $e h d s c n iu ai n /t r i(s o jc (c ni u ai n & $ of g rt o is ac o Si cL gt )/F u fi _b et $ of gr to ) & cn iu ai n nt ne f wt h ih ){ /o $ h s> o m i h - s i c ( c n i u a i n > e R o ( ) ti-r o Lg t> wt h $ o fg rt o- g to m) ; } } }
  53. 53. s ri e: e vc s s m_ no ai n di e: o e an tt o_ rv r c as X ov y f nC nu de An t to r vr A nt to Di e ls: S l eS mo yo B nl n oa in D ie n oa in r vr t g: [n m :k re .v n _i tn r ee t kr e. ot ol r mt o :o Kr eC as { ae e n le et ls ee , vn : en l cn rl e, e hd n e nl o a gm ns [ an t to _e dr @ om lg t ru et : @n oa in r ae , r o _i h]
  54. 54. /* * * @w th ih (o m "a o" Si c Lg tr o= sl n ) * / p bi f nt o s i cL gt na o At o( u lc u ci n wt hi h IS ln ci n) { .} ..
  55. 55. Q&A THANK YOU
  56. 56. NO QUESTIONS?
  57. 57. SHOULD WE CREATE AN ANNOTATION FOR BREADCRUMBS?
  58. 58. WE'RE HIRING XSOLVE.PL

×