SlideShare a Scribd company logo
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

PDF
Symfony (1/3) | Train to Symfony
PPTX
Suggestions and Ideas for DigitalOcean
PPT
Arquitectura I Escultura Grega
PDF
Xkanban: XP, Kanban and timeboxing
PPTX
Greytower identity Overview
PPTX
Easy Notes V1.0 En
PDF
Intro to Publishing iOS Apps - Full Cycle
PPT
Technologypowerpoint
Symfony (1/3) | Train to Symfony
Suggestions and Ideas for DigitalOcean
Arquitectura I Escultura Grega
Xkanban: XP, Kanban and timeboxing
Greytower identity Overview
Easy Notes V1.0 En
Intro to Publishing iOS Apps - Full Cycle
Technologypowerpoint

Viewers also liked (20)

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

Similar to Symfony2 per utenti Symfony 1.x: Architettura, modelli ed esempi (20)

PDF
introduzione a symfony 2
PDF
Zend Framework 2 per chi viene da Symfony2
PDF
Come sfruttare tutte le potenzialità di Symfony in Drupal 8
PDF
Come sfruttare tutte le potenzialità di Symfony in Drupal 8
PPT
Progettazione e sviluppo di applicazioni web 2.0 con PHP e Ajax
PDF
Codemotion workshop
ODP
ConfSL: Sviluppo Applicazioni web con Symfony
PDF
Combattere contro il codice del “cugino”? Symfony può aiutarti a sopravvivere...
PDF
PHP goes mobile
PDF
Back-end con SonataAdminBundle (e Symfony2, of course...)
PDF
Zend Framework 2
TXT
Link. php [santi caltabiano]
PDF
Hands on MVC - Mastering the Web
PDF
Sviluppo web dall'antichità all'avanguardia e ritorno
PDF
Hosting: il linguaggio PHP tra passato, presente e futuro #TipOfTheDay
ODP
Yii Framework - yes it is rapid web application development (Parte 1)
PDF
(My) Best Practices in Symfony
PDF
Apache Parte 1
PDF
Race condition in applicazioni PHP
PDF
Evoluzione del web development dalle cgi ai microservices
introduzione a symfony 2
Zend Framework 2 per chi viene da Symfony2
Come sfruttare tutte le potenzialità di Symfony in Drupal 8
Come sfruttare tutte le potenzialità di Symfony in Drupal 8
Progettazione e sviluppo di applicazioni web 2.0 con PHP e Ajax
Codemotion workshop
ConfSL: Sviluppo Applicazioni web con Symfony
Combattere contro il codice del “cugino”? Symfony può aiutarti a sopravvivere...
PHP goes mobile
Back-end con SonataAdminBundle (e Symfony2, of course...)
Zend Framework 2
Link. php [santi caltabiano]
Hands on MVC - Mastering the Web
Sviluppo web dall'antichità all'avanguardia e ritorno
Hosting: il linguaggio PHP tra passato, presente e futuro #TipOfTheDay
Yii Framework - yes it is rapid web application development (Parte 1)
(My) Best Practices in Symfony
Apache Parte 1
Race condition in applicazioni PHP
Evoluzione del web development dalle cgi ai microservices
Ad

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