SlideShare a Scribd company logo
1 of 33
Download to read offline
Symfony2
                   per utenti Symfony 1.x
                         Architettura, modelli ed esempi




 http://phpday.it                                          #phpday
venerdì 13 maggio 2011
Chi sono

            • Web developer @ideato
            • 3 anni da professionista con php
            • Se avete domande... fatele! Sono comprese
                   nel prezzo del biglietto




 http://phpday.it                                         #phpday
venerdì 13 maggio 2011
Symfony2 VS Symfony 1.x
                                Le basi: dove va cosa?

                          src                       i nostri bundles

                          app                        configurazione

                         vendor                     librerie esterne

                          web               php app/console assets:install --symlink web/



 http://phpday.it                                                                      #phpday
venerdì 13 maggio 2011
Symfony2 VS Symfony 1.x
                         Le basi: e chi gli dice che è lì?
                             app/autoload.php




                                                             L’ordine è importante!




 http://phpday.it                                                     #phpday
venerdì 13 maggio 2011
Symfony2 VS Symfony 1.x
          Le basi: Come funziona l’autoload? (namespace)
  app/autoload.php


  src/Ideato/XKanbanBundle/Entity/Activity.php




   new IdeatoXKanbanBundleEntityActivity()



                 autoload.php (namespace ‘Ideato’ in ‘src’) + <namespace><nome classe> = PATH


 http://phpday.it                                                                          #phpday
venerdì 13 maggio 2011
Symfony2 VS Symfony 1.x
                         Le basi: Come funziona l’autoload? (PEAR)
  app/autoload.php



    No namespace! PATH = __DIR__.’/../vendor/twig-extensions/lib/Twig/Extensions/MyClass.php’




 http://phpday.it                                                                    #phpday
venerdì 13 maggio 2011
Symfony2 VS Symfony 1.x
                         Le basi: Quali bundle sto usando?

     app/AppKernel.php




 http://phpday.it                                            #phpday
venerdì 13 maggio 2011
Symfony2 VS Symfony 1.x
                          Le basi: ok... e il routing?
  app/config/routing.yml




   src/Ideato/XKanbanBundle/Resources/config/routing.yml




 http://phpday.it                                         #phpday
venerdì 13 maggio 2011
Symfony2 VS Symfony 1.x
                          Internals



                         HttpFoundation




 http://phpday.it                         #phpday
venerdì 13 maggio 2011
Symfony2 VS Symfony 1.x
                          Internals


                           HttpKernel


                         HttpFoundation




 http://phpday.it                         #phpday
venerdì 13 maggio 2011
Symfony2 VS Symfony 1.x
                          Internals


                           HttpKernel
    Request

                         HttpFoundation




 http://phpday.it                         #phpday
venerdì 13 maggio 2011
Symfony2 VS Symfony 1.x
                          Internals       HttpKernel::handle()




    Request                HttpKernel      Response

                         HttpFoundation




 http://phpday.it                                     #phpday
venerdì 13 maggio 2011
Symfony2 VS Symfony 1.x
                               Internals
         Request                                                 Response
                         HttpKernel::handle()

                                                    Response
                                  GetResponseEvent::hasResponse()




                                      [Some listeners set a response...]



                            onCoreRequest Event

 http://phpday.it                                                          #phpday
venerdì 13 maggio 2011
Symfony2 VS Symfony 1.x
                                              Internals
         Request
                                  HttpKernel::handle()

                                                                   Controller
                                             Controller
                                                                   Arguments
    onCoreRequest Event
  [Sets _controller Request attribute]
                                         Resolver          Resolver


                                                    [Listeners can manipulate the callable]



                                onCoreController Event

 http://phpday.it                                                                             #phpday
venerdì 13 maggio 2011
Symfony2 VS Symfony 1.x
                                  Internals
                                                              Response
                         HttpKernel::handle()

                              Value
                                                 Response
                         Controller      GetResponseEvent::hasResponse()


                                               [Some listeners set a response...]


                                onCoreRequest Event


 http://phpday.it                                                         #phpday
venerdì 13 maggio 2011
Symfony2 VS Symfony 1.x
                                          Internals
         Request                                                          Response
                             HttpKernel::handle()

                                                           Response

                                           GetResponseEvent::hasResponse()
                         Controller


                               Response       [Some listeners can manipulate the response...]


                         onCoreResponse Event

 http://phpday.it                                                                    #phpday
venerdì 13 maggio 2011
Symfony2 VS Symfony 1.x
                                           Perchè Symfony2?

                         •   Symfony2 è un evoluzione

                         •   Sfrutta quelle che sono le potenzialità di php 5.3

                         •   Ad oggetti

                         •   Punta all’indipendenza dei propri componenti

                         •   CoC: Symfony2 offre la possibilità di utilizzare diversi strumenti per
                             raggiungere un risultato, ma non usa le configurazioni per
                             modificare il comportamento degli strumenti che utilizza.




 http://phpday.it                                                                                     #phpday
venerdì 13 maggio 2011
Symfony2 VS Symfony 1.x
                                Doctrine 2
                                                             $manager->persist($object);
             $object->save();
                                Paradigm shift (DDD)            $manager->flush();




                                         ORM
                                (Configurazione mapping)

                                        DBAL
                                (configurazione accesso db)

                                          DB


 http://phpday.it                                                              #phpday
venerdì 13 maggio 2011
Symfony2 VS Symfony 1.x
                                               Doctrine 2
                                    Le fixtures sono oggetti
                                          https://github.com/doctrine/data-fixtures
                         http://symfony.com/doc/current/cookbook/doctrine/doctrine_fixtures.html




 http://phpday.it                                                                                 #phpday
venerdì 13 maggio 2011
Symfony2 VS Symfony 1.x
                                               Doctrine 2
                                    Le fixtures sono oggetti
                                          https://github.com/doctrine/data-fixtures
                         http://symfony.com/doc/current/cookbook/doctrine/doctrine_fixtures.html




 http://phpday.it                                                                                 #phpday
venerdì 13 maggio 2011
Symfony2 VS Symfony 1.x
                         Doctrine 2: let’s go faster!

                                 Database
                                            serialized

                                  ORM


                                             object



                                  object




 http://phpday.it                                        #phpday
venerdì 13 maggio 2011
Symfony2 VS Symfony 1.x
                              Validation



             Class Activity




 http://phpday.it                          #phpday
venerdì 13 maggio 2011
Symfony2 VS Symfony 1.x
                                       Validation

             Class Activity


                                            Validator   Errori



         [annotation, yml, xml, php]



 http://phpday.it                                           #phpday
venerdì 13 maggio 2011
Symfony2 VS Symfony 1.x
                                       Validation

             Class Activity


                                            Validator   Errori



         [annotation, yml, xml, php]



 http://phpday.it                                           #phpday
venerdì 13 maggio 2011
Symfony2 VS Symfony 1.x
                                      Events
                                                                    Listeners

                                                                   my_listener


      EventDispatcher::dispatch($event)                            your_listener


                                                                   their_listener



                 Invece di definire classi nel filter.yml, definisci listeners!


 http://phpday.it                                                           #phpday
venerdì 13 maggio 2011
Symfony2 VS Symfony 1.x
                                     Events
                                                                Listeners

                                                                my_listener


   MyEventDispatcher::dispatch($event)                         your_listener


                                                               their_listener



                         Si può definire più di un EventDispatcher


 http://phpday.it                                                       #phpday
venerdì 13 maggio 2011
Symfony2 VS Symfony 1.x
                 Dependency Injection / Service container

                         DDD (Domain Driven Design)

                                      +

                         Service Oriented Architecture



 http://phpday.it                                        #phpday
venerdì 13 maggio 2011
Symfony2 VS Symfony 1.x
                 Dependency Injection / Service container
                EntityManager   Mailer   Logger   Validator   ...




                                   Service Container



              Oggetti che utilizzano i servizi definiti nel sistema

 http://phpday.it                                                   #phpday
venerdì 13 maggio 2011
Symfony2 VS Symfony 1.x
                 Dependency Injection / Service container

                         •   Separazione delle responsabilità

                         •   Test più specifici (se non unitari) per ogni classe

                         •   Dipendenze esplicite

                         •   Un solo oggetto che è responsabile di instaziare i servizi
                             della nostra applicazione




 http://phpday.it                                                                  #phpday
venerdì 13 maggio 2011
Symfony2 VS Symfony 1.x
                                                   TWIG

                         •   Ad oggetti

                         •   Refattorizzabile

                         •   Implementa l’ereditarietà

                         •   E’ possibile accedere ai blocchi dei template da cui si
                             eredita!




 http://phpday.it                                                                      #phpday
venerdì 13 maggio 2011
Symfony2 VS Symfony 1.x
                                 FORM

                  Object

                           Form Factory/Builder   isValid()

               Validator




 http://phpday.it                                      #phpday
venerdì 13 maggio 2011
Symfony2 VS Symfony 1.x
                                   Le ultime considerazioni...
                         •   Semplicità

                         •   Symfony2 contiene Symfony 1.x

                         •   La barriera di apprendimento iniziale è alta

                         •   Ha un sistema di caching che fa paura! (vedi @fabpot)

                         •   Doctrine 2: nuovo approccio (rif. “Paradigm shift”)

                         •   Traduzioni? Form? Comandi shell? Stanno arrivando!



 http://phpday.it                                                                    #phpday
venerdì 13 maggio 2011
Symfony2 VS Symfony 1.x

                                   Filippo De Santis
                               Twitter: @filippodesantis
                                      fd@ideato.it

                         Joind.in: http://joind.in/talk/view/3004
                         Examples: https://github.com/p16/ikb

 http://phpday.it                                                   #phpday
venerdì 13 maggio 2011

More Related Content

Viewers also liked

Professional Work
Professional WorkProfessional Work
Professional Work
onite
 
AméRica En El Mundo
AméRica En El MundoAméRica En El Mundo
AméRica En El Mundo
Isa Espinoza
 
xkanban v2 (ALE Bathtub III)
xkanban v2 (ALE Bathtub III)xkanban v2 (ALE Bathtub III)
xkanban v2 (ALE Bathtub III)
Filippo De Santis
 
VEKO digital marketing 12 2010
VEKO digital marketing 12 2010VEKO digital marketing 12 2010
VEKO digital marketing 12 2010
Antti Leino
 
Applied linear algebra
Applied linear algebraApplied linear algebra
Applied linear algebra
rch850 -
 

Viewers also liked (20)

Professional Work
Professional WorkProfessional Work
Professional Work
 
VEKO13 Joulu 2009
VEKO13 Joulu 2009VEKO13 Joulu 2009
VEKO13 Joulu 2009
 
Design attern in php
Design attern in phpDesign attern in php
Design attern in php
 
Grey tower and NetIQ - Identity Manager Integration with MuleSoft ESB
Grey tower and NetIQ - Identity Manager Integration with MuleSoft ESBGrey tower and NetIQ - Identity Manager Integration with MuleSoft ESB
Grey tower and NetIQ - Identity Manager Integration with MuleSoft ESB
 
Xkanban V3: eXtreme Programming, Kanban and Timboxing
Xkanban V3: eXtreme Programming, Kanban and TimboxingXkanban V3: eXtreme Programming, Kanban and Timboxing
Xkanban V3: eXtreme Programming, Kanban and Timboxing
 
Blocks & Grand Central Dispatch
Blocks & Grand Central DispatchBlocks & Grand Central Dispatch
Blocks & Grand Central Dispatch
 
Ruby On Rails Pitfalls
Ruby On Rails PitfallsRuby On Rails Pitfalls
Ruby On Rails Pitfalls
 
Хостеры и регистраторы - операторы персональных данных
Хостеры и регистраторы - операторы персональных данныхХостеры и регистраторы - операторы персональных данных
Хостеры и регистраторы - операторы персональных данных
 
Vsena.Foss.Migration.Guide.V1.01
Vsena.Foss.Migration.Guide.V1.01Vsena.Foss.Migration.Guide.V1.01
Vsena.Foss.Migration.Guide.V1.01
 
AméRica En El Mundo
AméRica En El MundoAméRica En El Mundo
AméRica En El Mundo
 
Домен .tel - новый способ коммуникации
Домен .tel - новый способ коммуникацииДомен .tel - новый способ коммуникации
Домен .tel - новый способ коммуникации
 
Project Slide Show
Project Slide ShowProject Slide Show
Project Slide Show
 
How we build caibangzi.com
How we build caibangzi.comHow we build caibangzi.com
How we build caibangzi.com
 
xkanban v2 (ALE Bathtub III)
xkanban v2 (ALE Bathtub III)xkanban v2 (ALE Bathtub III)
xkanban v2 (ALE Bathtub III)
 
VEKO digital marketing 12 2010
VEKO digital marketing 12 2010VEKO digital marketing 12 2010
VEKO digital marketing 12 2010
 
Symfony2: the world slowest framework
Symfony2: the world slowest frameworkSymfony2: the world slowest framework
Symfony2: the world slowest framework
 
High quality iOS development
High quality iOS developmentHigh quality iOS development
High quality iOS development
 
Building a-self-sufficient-team
Building a-self-sufficient-teamBuilding a-self-sufficient-team
Building a-self-sufficient-team
 
Cocoa Design Patterns
Cocoa Design PatternsCocoa Design Patterns
Cocoa Design Patterns
 
Applied linear algebra
Applied linear algebraApplied linear algebra
Applied linear algebra
 

Symfony2 per utenti Symfony 1.x: Architettura, modelli ed esempi

  • 1. Symfony2 per utenti Symfony 1.x Architettura, modelli ed esempi http://phpday.it #phpday venerdì 13 maggio 2011
  • 2. Chi sono • Web developer @ideato • 3 anni da professionista con php • Se avete domande... fatele! Sono comprese nel prezzo del biglietto http://phpday.it #phpday venerdì 13 maggio 2011
  • 3. Symfony2 VS Symfony 1.x Le basi: dove va cosa? src i nostri bundles app configurazione vendor librerie esterne web php app/console assets:install --symlink web/ http://phpday.it #phpday venerdì 13 maggio 2011
  • 4. Symfony2 VS Symfony 1.x Le basi: e chi gli dice che è lì? app/autoload.php L’ordine è importante! http://phpday.it #phpday venerdì 13 maggio 2011
  • 5. Symfony2 VS Symfony 1.x Le basi: Come funziona l’autoload? (namespace) app/autoload.php src/Ideato/XKanbanBundle/Entity/Activity.php new IdeatoXKanbanBundleEntityActivity() autoload.php (namespace ‘Ideato’ in ‘src’) + <namespace><nome classe> = PATH http://phpday.it #phpday venerdì 13 maggio 2011
  • 6. Symfony2 VS Symfony 1.x Le basi: Come funziona l’autoload? (PEAR) app/autoload.php No namespace! PATH = __DIR__.’/../vendor/twig-extensions/lib/Twig/Extensions/MyClass.php’ http://phpday.it #phpday venerdì 13 maggio 2011
  • 7. Symfony2 VS Symfony 1.x Le basi: Quali bundle sto usando? app/AppKernel.php http://phpday.it #phpday venerdì 13 maggio 2011
  • 8. Symfony2 VS Symfony 1.x Le basi: ok... e il routing? app/config/routing.yml src/Ideato/XKanbanBundle/Resources/config/routing.yml http://phpday.it #phpday venerdì 13 maggio 2011
  • 9. Symfony2 VS Symfony 1.x Internals HttpFoundation http://phpday.it #phpday venerdì 13 maggio 2011
  • 10. Symfony2 VS Symfony 1.x Internals HttpKernel HttpFoundation http://phpday.it #phpday venerdì 13 maggio 2011
  • 11. Symfony2 VS Symfony 1.x Internals HttpKernel Request HttpFoundation http://phpday.it #phpday venerdì 13 maggio 2011
  • 12. Symfony2 VS Symfony 1.x Internals HttpKernel::handle() Request HttpKernel Response HttpFoundation http://phpday.it #phpday venerdì 13 maggio 2011
  • 13. Symfony2 VS Symfony 1.x Internals Request Response HttpKernel::handle() Response GetResponseEvent::hasResponse() [Some listeners set a response...] onCoreRequest Event http://phpday.it #phpday venerdì 13 maggio 2011
  • 14. Symfony2 VS Symfony 1.x Internals Request HttpKernel::handle() Controller Controller Arguments onCoreRequest Event [Sets _controller Request attribute] Resolver Resolver [Listeners can manipulate the callable] onCoreController Event http://phpday.it #phpday venerdì 13 maggio 2011
  • 15. Symfony2 VS Symfony 1.x Internals Response HttpKernel::handle() Value Response Controller GetResponseEvent::hasResponse() [Some listeners set a response...] onCoreRequest Event http://phpday.it #phpday venerdì 13 maggio 2011
  • 16. Symfony2 VS Symfony 1.x Internals Request Response HttpKernel::handle() Response GetResponseEvent::hasResponse() Controller Response [Some listeners can manipulate the response...] onCoreResponse Event http://phpday.it #phpday venerdì 13 maggio 2011
  • 17. Symfony2 VS Symfony 1.x Perchè Symfony2? • Symfony2 è un evoluzione • Sfrutta quelle che sono le potenzialità di php 5.3 • Ad oggetti • Punta all’indipendenza dei propri componenti • CoC: Symfony2 offre la possibilità di utilizzare diversi strumenti per raggiungere un risultato, ma non usa le configurazioni per modificare il comportamento degli strumenti che utilizza. http://phpday.it #phpday venerdì 13 maggio 2011
  • 18. Symfony2 VS Symfony 1.x Doctrine 2 $manager->persist($object); $object->save(); Paradigm shift (DDD) $manager->flush(); ORM (Configurazione mapping) DBAL (configurazione accesso db) DB http://phpday.it #phpday venerdì 13 maggio 2011
  • 19. Symfony2 VS Symfony 1.x Doctrine 2 Le fixtures sono oggetti https://github.com/doctrine/data-fixtures http://symfony.com/doc/current/cookbook/doctrine/doctrine_fixtures.html http://phpday.it #phpday venerdì 13 maggio 2011
  • 20. Symfony2 VS Symfony 1.x Doctrine 2 Le fixtures sono oggetti https://github.com/doctrine/data-fixtures http://symfony.com/doc/current/cookbook/doctrine/doctrine_fixtures.html http://phpday.it #phpday venerdì 13 maggio 2011
  • 21. Symfony2 VS Symfony 1.x Doctrine 2: let’s go faster! Database serialized ORM object object http://phpday.it #phpday venerdì 13 maggio 2011
  • 22. Symfony2 VS Symfony 1.x Validation Class Activity http://phpday.it #phpday venerdì 13 maggio 2011
  • 23. Symfony2 VS Symfony 1.x Validation Class Activity Validator Errori [annotation, yml, xml, php] http://phpday.it #phpday venerdì 13 maggio 2011
  • 24. Symfony2 VS Symfony 1.x Validation Class Activity Validator Errori [annotation, yml, xml, php] http://phpday.it #phpday venerdì 13 maggio 2011
  • 25. Symfony2 VS Symfony 1.x Events Listeners my_listener EventDispatcher::dispatch($event) your_listener their_listener Invece di definire classi nel filter.yml, definisci listeners! http://phpday.it #phpday venerdì 13 maggio 2011
  • 26. Symfony2 VS Symfony 1.x Events Listeners my_listener MyEventDispatcher::dispatch($event) your_listener their_listener Si può definire più di un EventDispatcher http://phpday.it #phpday venerdì 13 maggio 2011
  • 27. Symfony2 VS Symfony 1.x Dependency Injection / Service container DDD (Domain Driven Design) + Service Oriented Architecture http://phpday.it #phpday venerdì 13 maggio 2011
  • 28. Symfony2 VS Symfony 1.x Dependency Injection / Service container EntityManager Mailer Logger Validator ... Service Container Oggetti che utilizzano i servizi definiti nel sistema http://phpday.it #phpday venerdì 13 maggio 2011
  • 29. Symfony2 VS Symfony 1.x Dependency Injection / Service container • Separazione delle responsabilità • Test più specifici (se non unitari) per ogni classe • Dipendenze esplicite • Un solo oggetto che è responsabile di instaziare i servizi della nostra applicazione http://phpday.it #phpday venerdì 13 maggio 2011
  • 30. Symfony2 VS Symfony 1.x TWIG • Ad oggetti • Refattorizzabile • Implementa l’ereditarietà • E’ possibile accedere ai blocchi dei template da cui si eredita! http://phpday.it #phpday venerdì 13 maggio 2011
  • 31. Symfony2 VS Symfony 1.x FORM Object Form Factory/Builder isValid() Validator http://phpday.it #phpday venerdì 13 maggio 2011
  • 32. Symfony2 VS Symfony 1.x Le ultime considerazioni... • Semplicità • Symfony2 contiene Symfony 1.x • La barriera di apprendimento iniziale è alta • Ha un sistema di caching che fa paura! (vedi @fabpot) • Doctrine 2: nuovo approccio (rif. “Paradigm shift”) • Traduzioni? Form? Comandi shell? Stanno arrivando! http://phpday.it #phpday venerdì 13 maggio 2011
  • 33. Symfony2 VS Symfony 1.x Filippo De Santis Twitter: @filippodesantis fd@ideato.it Joind.in: http://joind.in/talk/view/3004 Examples: https://github.com/p16/ikb http://phpday.it #phpday venerdì 13 maggio 2011