Sonata Block Bundle - sfPot March 2014

9,137 views

Published on

Published in: Technology
1 Comment
11 Likes
Statistics
Notes
No Downloads
Views
Total views
9,137
On SlideShare
0
From Embeds
0
Number of Embeds
4,607
Actions
Shares
0
Downloads
48
Comments
1
Likes
11
Embeds 0
No embeds

No notes for slide

Sonata Block Bundle - sfPot March 2014

  1. 1. BlockBundle   Sonata  Project  
  2. 2.                SONATA-­‐PROJECT:  BlockBundle   •  Thomas  Rabaix   – Founder  and  Lead  dev  of  Sonata  Project   – Work  @  Ekino   •  Official  sponsor  of  Sonata  Project   •  PHP  Experts   •  Ekino[Drupal|Wordpress]Bundle,  EkinoNewRelicBundle    
  3. 3. Web  Developer’s  Job       ~     Let’s  take  a  standard  product  page   hRp://demo.sonata-­‐project.org/shop/product/travel-­‐paris-­‐ tour/1037     ~     The  page  point  to  a  MVC  ac[on:   ProductController::viewProduct   Get  the  product  and  check  validity     ~     How  can  we  reuse  shared  components  ?   Twig’s  extensions:  include,  use,  block     or  Symfony2’s  extension:  render     ...  or  …    
  4. 4.                SONATA-­‐PROJECT:  BlockBundle   What  ?   •  BlockBundle   – It  is  used  to  manage  fragments  of  content,  so-­‐ called  blocks,     – and  can  be  incorporated  into  any  page  layout.   – Think  of  “small  MVC  ac[on”  
  5. 5.                SONATA-­‐PROJECT:  BlockBundle   Why  ?   •  Rendering  controller  is  not  always  perfect   – Crea[ng  subrequest  can  be  heavy   – Not  everything  fits  into  an  url  =>  controller   – A  controller  cannot  define  or  validate  segngs   – Cannot  handle  cache  backends  (it  is  not  always   about  hRp:  redis,  memcached  or  mongodb)  
  6. 6.                SONATA-­‐PROJECT:  BlockBundle   How  ?  
  7. 7. THE  RSS  BLOCK  SERVICE   Your  First  Block  Service  
  8. 8.                SONATA-­‐PROJECT:  BlockBundle   Let’s  create  your  first  block  service     From   h3p://sonata-­‐project.org/bundles/block/master/ doc/reference/your_first_block.html     ~     A  RSS  Live  Feed  reader  
  9. 9. composer require sonata-project/block-bundle:~2.2!
  10. 10. A  block  service  is  just  a  service  which  implements  the   BlockServiceInterface  interface.       There  is  only  one  instance  of  a  block  service,  however  there  are  many   block  instances.   1/5  
  11. 11. A  block  service  needs  segngs  to  work  properly     and  to  ensure  consistency,       The  service  should  define  a  setDefaultSettings  method  to   configure  the  default  op[ons  (like  a  FormType)   2/5  
  12. 12. This  method  must  return  a  Response  object,       this  object  is  used  to  render  the  block.   3/5  
  13. 13. A  block  template  is  very  simple.       We  are  looping  on  feeds  or  if  not  defined,  a  error  message  is  displayed.   4/5  
  14. 14. We  just  need  to  declare  the  BlockService  as  Service    with  the  tag  sonata.tag!   We  also  need  to  enable  the  block    in  the  sonata_blocks.blocks  sec[on.   5/5  
  15. 15. CONCEPT   behind  the  scenes  
  16. 16. •  BlockInterface! –  Contains  the  block  informa[on   –  Can  have  children  and  parent   •  BlockContextInterface! –  Contains  data  for  the  current  execu[on   –  Can  be  altered  during  run[me   •  BlockServiceInterface! –  Manipulate  the  BlockInterface! –  Render  a  BlockContextInterface! •  BlockContextManagerInterface! –  Create  a  valid  BlockContext  from  any  provided  data   •  BlockLoaderInterface! –  Call  by  the  BlockContextManager  to  get  a  BlockInterface! •  BlockRendererInterface! –  Render  the  BlockContext! –  Generates  a  valid  Response!
  17. 17.                SONATA-­‐PROJECT:  BlockBundle   Rendering  Workflow  
  18. 18. CACHE   Speed  up  the  code  
  19. 19.                SONATA-­‐PROJECT:  BlockBundle   composer require sonata-project/cache-bundle:~2.1!
  20. 20. Cache  Configura[on  
  21. 21. Ttl  default  is  84600   extra_cache_keys  can  be  used  to  ovewrite  default   values,  like  ones  aRached  at  run[me  
  22. 22. SYMFONY2  INTEGRATION   Small  nice  things  
  23. 23. EXTERNAL  INTEGRATIONS   We  are  not  alone  
  24. 24. Symfony  CMF  
  25. 25. Sylius  
  26. 26. Sonata  Page  Bundle  
  27. 27. PrestaCMS  
  28. 28.                SONATA-­‐PROJECT:  BlockBundle   Other  Features   •  Block  events   •  Javascript  and  Stylesheet  helpers   •  Excep[on  strategy   •  Rapid  Prototyping  
  29. 29.                SONATA-­‐PROJECT:  BlockBundle   References   •  hRp://sonata-­‐project.org/bundles/block/ master/doc/index.html   •  hRp://symfony.com/doc/current/cmf/ bundles/block/introduc[on.html  
  30. 30. QUESTIONS?   What  the  SonataBlockBundle  does  ?  

×