Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
MAKING THE MOST OF 2.2
        MARK STORY
         @MARK_STORY
PACKING IN THE GOOD
2.0.0 was release October 18, 2011
Since then 2.1, 2.2, and 2.3 have been released or started.
Over 20 releases since 2.0.0.
Highest release velocity ever for CakePHP.
FOCUS ON PROBLEMS
We've tried to keep releases focused on solving real world problems
                    developers have everyday.
               Make upgrading as easy as possible.
VIEW BLOCKS
                            PROBLEM
Multiple similar views would often contain repeated structural
HTML.
Apps suffered from element-itis to keep HTML DRY.
Piles of elements make code hard to follow and understand.
Inspired by blocks in Jinja/Twig.
Allows you to create slots/blocks in layouts or parent templates.
Helps keep views/layouts more DRY by letting you create
extensible HTML content.
Replaces annoying magic variables like $ c i t _ o _ a o t
                                         srpsfrlyu
and $ o t n _ o _ a o t
      cnetfrlyu.
EXAMPLE
Parent wrapper view with a child view
PARENT VIEW
<1cas"otn-il"<=$hs>ec(tte) ?<h>
 h ls=cnettte>? ti-fth'il'; >/1
<i cas"otn"
 dv ls=cnet>
<=$hs>ec(cnet) ?
 ? ti-fth'otn'; >
<dv
 /i>
<i cas"iea"
 dv ls=sdbr>
<=$hs>ec(sdbr) ?
 ? ti-fth'iea'; >
<dv
 /i>
<ppi (ti-fth'aiain):?
 ?h f $hs>ec(pgnto') >
<i cas"aiain>
 dv ls=pgnto"
<=$hs>ec(pgnto';?
 ? ti-fth'aiain) >
<dv
 /i>
<ppedf ?
 ?h ni; >
CHILD VIEW
<pp$hs>xed'.cmo/iea.t';?
 ?h ti-etn(./omnsdbrcp) >
<pp$hs>sin'il' 'rdc ls';?
 ?h ti-asg(tte, Pout it) >
<pp$hs>tr(cnet) ?
 ?h ti-sat'otn'; >
<>hsi tecnet/>
 pTi s h otn<p
<pp$hs>n(;?
 ?h ti-ed) >

<pp$hs>tr(sdbr) ?
 ?h ti-sat'iea'; >
<>hsi asdbr/>
 pTi s  iea<p
<pp$hs>n(;?
 ?h ti-ed) >
JSON & XML VIEWS
                            PROBLEM
Previously creating JSON and XML views that just serialized data
was a pain.
Tons of repetitive views and layout files required.
Two view classes that allow you to easily serialize data for simple
uses.
Special _ e i l z view variable defines which view variables
         sraie
should be serialized.
You can also use normal view files if you need to massage data first.
Integrates well with existing features like exception handling and
RequestHandlerComponent.
EXAMPLE
<pp
 ?h
/ I acnrle.
 / n  otolr
fnto idx){
 ucin ne(
     $hs>e(tss,$hs>aiae);
      ti-st'ak' ti-pgnt()
     $hs>e(_eilz' ary'ak')
      ti-st'sraie, ra(tss);
}
HASH CLASS
                            PROBLEM
S t full of inconsistencies. Both in the API and path selector
 e is
syntax.
Set::extract() while powerful, is slow and insane inside.
xpath-ish syntax full of un-fixable bugs and not supported in most
methods.
Hash implements >90% of Set's API.
All methods have a consistent signature.
The same dot notation features are supported everywhere.
Up to 1.6x faster on extract().
Most methods are faster as well.
PERFORMANCE COMPARISONS
Do a similar operation 1000 times, on the same data.
Hs:etat$,'n.ril.d)
 ah:xrc(d {}Atcei'   0.215131998
St:xrc(/ril/d,$)
 e:etat'Atcei' d     0.23719382
1.1x improvement
H s : e t a t $ , ' n . o m n . n . d ) 0.173635005
 ah:xrc(d {}Cmet{}i'
St:xrc(/omn/d,$)
 e:etat'Cmeti' d                        0.201920986
1.1x improvement
Hs:mxiesos$)
 ah:aDmnin(d       0.075587987
St:onDm$,tu)
 e:cuti(d re       0.575523138
7.6x improvement
API CONSISTENCY
Every method takes an array of data as the first argument.
Second argument is always one or more paths.
A consistent API is easier to document, understand and remember.
CAKETIME & CAKENUMBER
                      PROBLEM
T m H l e , N m e H l e and T x H l e have some very
 ieepr ubrepr                         etepr
useful methods.
But they are all trapped in a helper.
Expose non HTML related features as a utility library.
Greatly improve timezone handling.
New features for testing & working with datetimes.
EXAMPLE
<pp
 ?h
Ap:ss'aeie,'tlt';
 p:ue(CkTm' Uiiy)
Ap:ss'aeubr,'tlt';
 p:ue(CkNme' Uiiy)

$t =CkTm:tSre(dttm,'mrc/oot';
 uc  aeie:oevr$aeie AeiaTrno)
$oa =CkTm:iTdy$ietm)
 tdy  aeie:soa(tmsap;

$eut=CkNme:tRaalSz(oeeaye;
 rsl  aeubr:oedbeie$nTrbt)
LOGGING++
                         PROBLEM
Granular logging based on application section was impossible.
Log messages were simply broadcast to every connected logger.
Borrowed idea of logging 'scopes' from python's l g i g
                                                   o g n module.
Log messages can be tagged with scopes.
Only loggers interested in those scopes will get scoped messages.
ATTACH A LOGGER WITH A SCOPE
<pp
 ?h
CkLg:ofg'amns,ary
 aeo:cni(pyet' ra(
    'nie = 'mi'
     egn' > Eal
    'cps = ary'amns,'iln',
     soe' > ra(pyet' blig)
    'o = 'akeapecm
     t' > mr@xml.o'
);
 )
LOG MESSAGES WITH A SCOPE
<pp
 ?h
ty{
 r
     $aea-poes$amn)
      gtwy>rcs(pyet;
}cth(amnEcpin$){
  ac  Pyetxeto e
     CkLg:ro(
      aeo:err
          'rnato fie '.$-gtesg(,
           Tascin ald   e>eMsae)
          ary'amns,'iln'
           ra(pyet' blig)
     );
}
NOW TO JOSE

More Related Content

Making the most of 2.2

  • 1. MAKING THE MOST OF 2.2 MARK STORY @MARK_STORY
  • 2. PACKING IN THE GOOD 2.0.0 was release October 18, 2011 Since then 2.1, 2.2, and 2.3 have been released or started. Over 20 releases since 2.0.0. Highest release velocity ever for CakePHP.
  • 3. FOCUS ON PROBLEMS We've tried to keep releases focused on solving real world problems developers have everyday. Make upgrading as easy as possible.
  • 4. VIEW BLOCKS PROBLEM Multiple similar views would often contain repeated structural HTML. Apps suffered from element-itis to keep HTML DRY. Piles of elements make code hard to follow and understand.
  • 5. Inspired by blocks in Jinja/Twig. Allows you to create slots/blocks in layouts or parent templates. Helps keep views/layouts more DRY by letting you create extensible HTML content. Replaces annoying magic variables like $ c i t _ o _ a o t srpsfrlyu and $ o t n _ o _ a o t cnetfrlyu.
  • 6. EXAMPLE Parent wrapper view with a child view
  • 7. PARENT VIEW <1cas"otn-il"<=$hs>ec(tte) ?<h> h ls=cnettte>? ti-fth'il'; >/1 <i cas"otn" dv ls=cnet> <=$hs>ec(cnet) ? ? ti-fth'otn'; > <dv /i> <i cas"iea" dv ls=sdbr> <=$hs>ec(sdbr) ? ? ti-fth'iea'; > <dv /i> <ppi (ti-fth'aiain):? ?h f $hs>ec(pgnto') > <i cas"aiain> dv ls=pgnto" <=$hs>ec(pgnto';? ? ti-fth'aiain) > <dv /i> <ppedf ? ?h ni; >
  • 8. CHILD VIEW <pp$hs>xed'.cmo/iea.t';? ?h ti-etn(./omnsdbrcp) > <pp$hs>sin'il' 'rdc ls';? ?h ti-asg(tte, Pout it) > <pp$hs>tr(cnet) ? ?h ti-sat'otn'; > <>hsi tecnet/> pTi s h otn<p <pp$hs>n(;? ?h ti-ed) > <pp$hs>tr(sdbr) ? ?h ti-sat'iea'; > <>hsi asdbr/> pTi s iea<p <pp$hs>n(;? ?h ti-ed) >
  • 9. JSON & XML VIEWS PROBLEM Previously creating JSON and XML views that just serialized data was a pain. Tons of repetitive views and layout files required.
  • 10. Two view classes that allow you to easily serialize data for simple uses. Special _ e i l z view variable defines which view variables sraie should be serialized. You can also use normal view files if you need to massage data first. Integrates well with existing features like exception handling and RequestHandlerComponent.
  • 11. EXAMPLE <pp ?h / I acnrle. / n otolr fnto idx){ ucin ne( $hs>e(tss,$hs>aiae); ti-st'ak' ti-pgnt() $hs>e(_eilz' ary'ak') ti-st'sraie, ra(tss); }
  • 12. HASH CLASS PROBLEM S t full of inconsistencies. Both in the API and path selector e is syntax. Set::extract() while powerful, is slow and insane inside. xpath-ish syntax full of un-fixable bugs and not supported in most methods.
  • 13. Hash implements >90% of Set's API. All methods have a consistent signature. The same dot notation features are supported everywhere. Up to 1.6x faster on extract(). Most methods are faster as well.
  • 14. PERFORMANCE COMPARISONS Do a similar operation 1000 times, on the same data.
  • 15. Hs:etat$,'n.ril.d) ah:xrc(d {}Atcei' 0.215131998 St:xrc(/ril/d,$) e:etat'Atcei' d 0.23719382 1.1x improvement
  • 16. H s : e t a t $ , ' n . o m n . n . d ) 0.173635005 ah:xrc(d {}Cmet{}i' St:xrc(/omn/d,$) e:etat'Cmeti' d 0.201920986 1.1x improvement
  • 17. Hs:mxiesos$) ah:aDmnin(d 0.075587987 St:onDm$,tu) e:cuti(d re 0.575523138 7.6x improvement
  • 18. API CONSISTENCY Every method takes an array of data as the first argument. Second argument is always one or more paths. A consistent API is easier to document, understand and remember.
  • 19. CAKETIME & CAKENUMBER PROBLEM T m H l e , N m e H l e and T x H l e have some very ieepr ubrepr etepr useful methods. But they are all trapped in a helper.
  • 20. Expose non HTML related features as a utility library. Greatly improve timezone handling. New features for testing & working with datetimes.
  • 21. EXAMPLE <pp ?h Ap:ss'aeie,'tlt'; p:ue(CkTm' Uiiy) Ap:ss'aeubr,'tlt'; p:ue(CkNme' Uiiy) $t =CkTm:tSre(dttm,'mrc/oot'; uc aeie:oevr$aeie AeiaTrno) $oa =CkTm:iTdy$ietm) tdy aeie:soa(tmsap; $eut=CkNme:tRaalSz(oeeaye; rsl aeubr:oedbeie$nTrbt)
  • 22. LOGGING++ PROBLEM Granular logging based on application section was impossible. Log messages were simply broadcast to every connected logger.
  • 23. Borrowed idea of logging 'scopes' from python's l g i g o g n module. Log messages can be tagged with scopes. Only loggers interested in those scopes will get scoped messages.
  • 24. ATTACH A LOGGER WITH A SCOPE <pp ?h CkLg:ofg'amns,ary aeo:cni(pyet' ra( 'nie = 'mi' egn' > Eal 'cps = ary'amns,'iln', soe' > ra(pyet' blig) 'o = 'akeapecm t' > mr@xml.o' ); )
  • 25. LOG MESSAGES WITH A SCOPE <pp ?h ty{ r $aea-poes$amn) gtwy>rcs(pyet; }cth(amnEcpin$){ ac Pyetxeto e CkLg:ro( aeo:err 'rnato fie '.$-gtesg(, Tascin ald e>eMsae) ary'amns,'iln' ra(pyet' blig) ); }