Upload
filippo-de-santis
View
2.823
Download
0
Embed Size (px)
DESCRIPTION
Citation preview
http://phpday.it #phpday
Architettura, modelli ed esempi
Symfony2 per utenti Symfony 1.x
venerdì 13 maggio 2011
http://phpday.it #phpday
• Web developer @ideato
• 3 anni da professionista con php
• Se avete domande... fatele! Sono comprese nel prezzo del biglietto
Chi sono
venerdì 13 maggio 2011
http://phpday.it #phpday
Symfony2 VS Symfony 1.xLe basi: dove va cosa?
src i nostri bundles
app configurazione
vendor librerie esterne
web php app/console assets:install --symlink web/
venerdì 13 maggio 2011
http://phpday.it #phpday
Symfony2 VS Symfony 1.xLe basi: e chi gli dice che è lì?
app/autoload.php
L’ordine è importante!
venerdì 13 maggio 2011
http://phpday.it #phpday
Symfony2 VS Symfony 1.x
app/autoload.php
src/Ideato/XKanbanBundle/Entity/Activity.php
new \Ideato\XKanbanBundle\Entity\Activity()
autoload.php (namespace ‘Ideato’ in ‘src’) + <namespace>\<nome classe> = PATH
Le basi: Come funziona l’autoload? (namespace)
venerdì 13 maggio 2011
http://phpday.it #phpday
Symfony2 VS Symfony 1.x
No namespace! PATH = __DIR__.’/../vendor/twig-extensions/lib/Twig/Extensions/MyClass.php’
Le basi: Come funziona l’autoload? (PEAR)app/autoload.php
venerdì 13 maggio 2011
http://phpday.it #phpday
Symfony2 VS Symfony 1.x
app/AppKernel.php
Le basi: Quali bundle sto usando?
venerdì 13 maggio 2011
http://phpday.it #phpday
Symfony2 VS Symfony 1.x
app/config/routing.yml
Le basi: ok... e il routing?
src/Ideato/XKanbanBundle/Resources/config/routing.yml
venerdì 13 maggio 2011
http://phpday.it #phpday
Symfony2 VS Symfony 1.x
HttpFoundation
Internals
venerdì 13 maggio 2011
http://phpday.it #phpday
Symfony2 VS Symfony 1.x
HttpFoundation
HttpKernel
Internals
venerdì 13 maggio 2011
http://phpday.it #phpday
Symfony2 VS Symfony 1.x
HttpFoundation
Internals
HttpKernelRequest
venerdì 13 maggio 2011
http://phpday.it #phpday
Symfony2 VS Symfony 1.x
HttpFoundation
Internals
HttpKernelRequest
HttpKernel::handle()
Response
venerdì 13 maggio 2011
http://phpday.it #phpday
Symfony2 VS Symfony 1.xInternals
HttpKernel::handle()Request Response
onCoreRequest Event
GetResponseEvent::hasResponse()
Response
[Some listeners set a response...]
venerdì 13 maggio 2011
http://phpday.it #phpday
Symfony2 VS Symfony 1.xInternals
HttpKernel::handle()Request
onCoreRequest Event
[Sets _controller Request attribute]Resolver
Controller
onCoreController Event
[Listeners can manipulate the callable]
Resolver
ControllerArguments
venerdì 13 maggio 2011
http://phpday.it #phpday
Symfony2 VS Symfony 1.xInternals
HttpKernel::handle()Response
Controller
Value
onCoreRequest Event
GetResponseEvent::hasResponse()
Response
[Some listeners set a response...]
venerdì 13 maggio 2011
http://phpday.it #phpday
Symfony2 VS Symfony 1.xInternals
HttpKernel::handle()Request Response
Controller
onCoreResponse Event
GetResponseEvent::hasResponse()
Response [Some listeners can manipulate the response...]
Response
venerdì 13 maggio 2011
http://phpday.it #phpday
Symfony2 VS Symfony 1.xPerchè 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.
venerdì 13 maggio 2011
http://phpday.it #phpday
Symfony2 VS Symfony 1.xDoctrine 2
$object->save(); $manager->persist($object);$manager->flush();Paradigm shift (DDD)
ORM(Configurazione mapping)
DBAL(configurazione accesso db)
DB
venerdì 13 maggio 2011
http://phpday.it #phpday
Symfony2 VS Symfony 1.xDoctrine 2
Le fixtures sono oggettihttps://github.com/doctrine/data-fixtures
http://symfony.com/doc/current/cookbook/doctrine/doctrine_fixtures.html
venerdì 13 maggio 2011
http://phpday.it #phpday
Symfony2 VS Symfony 1.xDoctrine 2
Le fixtures sono oggettihttps://github.com/doctrine/data-fixtures
http://symfony.com/doc/current/cookbook/doctrine/doctrine_fixtures.html
venerdì 13 maggio 2011
http://phpday.it #phpday
Symfony2 VS Symfony 1.xDoctrine 2: let’s go faster!
Database
ORM
serialized
object
object
venerdì 13 maggio 2011
http://phpday.it #phpday
Symfony2 VS Symfony 1.xValidation
Class Activity
venerdì 13 maggio 2011
http://phpday.it #phpday
Symfony2 VS Symfony 1.xValidation
Class Activity
Validator Errori
[annotation, yml, xml, php]
venerdì 13 maggio 2011
http://phpday.it #phpday
Symfony2 VS Symfony 1.xValidation
Class Activity
Validator Errori
[annotation, yml, xml, php]
venerdì 13 maggio 2011
http://phpday.it #phpday
Symfony2 VS Symfony 1.xEvents
EventDispatcher::dispatch($event)
Listeners
my_listener
your_listener
their_listener
Invece di definire classi nel filter.yml, definisci listeners!
venerdì 13 maggio 2011
http://phpday.it #phpday
Symfony2 VS Symfony 1.xEvents
MyEventDispatcher::dispatch($event)
Listeners
my_listener
your_listener
their_listener
Si può definire più di un EventDispatcher
venerdì 13 maggio 2011
http://phpday.it #phpday
Symfony2 VS Symfony 1.xDependency Injection / Service container
Service Oriented Architecture
DDD (Domain Driven Design)
+
venerdì 13 maggio 2011
http://phpday.it #phpday
Symfony2 VS Symfony 1.xDependency Injection / Service container
Mailer LoggerEntityManager Validator ...
Service Container
Oggetti che utilizzano i servizi definiti nel sistema
venerdì 13 maggio 2011
http://phpday.it #phpday
Symfony2 VS Symfony 1.xDependency 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
venerdì 13 maggio 2011
http://phpday.it #phpday
Symfony2 VS Symfony 1.xTWIG
• Ad oggetti
• Refattorizzabile
• Implementa l’ereditarietà
• E’ possibile accedere ai blocchi dei template da cui si eredita!
venerdì 13 maggio 2011
http://phpday.it #phpday
Symfony2 VS Symfony 1.xFORM
Object
Validator
Form Factory/Builder isValid()
venerdì 13 maggio 2011
http://phpday.it #phpday
Symfony2 VS Symfony 1.xLe 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!
venerdì 13 maggio 2011
http://phpday.it #phpday
Symfony2 VS Symfony 1.x
Joind.in: http://joind.in/talk/view/3004
Filippo De Santis
Twitter: @filippodesantis
Examples: https://github.com/p16/ikb
venerdì 13 maggio 2011