Symfony2 per utenti Symfony 1.x: Architettura, modelli ed esempi
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