SlideShare a Scribd company logo
1 of 158
Download to read offline
A Practical Introduction
                                 to Symfony2
                                        Kris Wallsmith




                                   PHP Matsuri • October 2, 2010

Saturday, October 2, 2010
@kriswallsmith

                  •         Release Manager for symfony 1.3 & 1.4

                  •         Doctrine contributor

                  •         Senior Software Engineer at

                  •         10 years experience in web development

                  •         Open source evangelist and international speaker


Saturday, October 2, 2010
the evolution of symfony


                  •         Mojavi 3

                  •         symfony (2007)

                  •         Symfony2 (2011)




Saturday, October 2, 2010
a quick note for the
                            case-sensitive among us



Saturday, October 2, 2010
talk about “symfony”



Saturday, October 2, 2010
talk about “symfony 1”



Saturday, October 2, 2010
talk about “Symfony2”



Saturday, October 2, 2010
there is no “Symfony 1”



Saturday, October 2, 2010
there is no “symfony 2”



Saturday, October 2, 2010
there is no “Symfony 2”



Saturday, October 2, 2010
there is no “Symfony 2”




                                       {
                                         less search-friendly




Saturday, October 2, 2010
Symfony2



Saturday, October 2, 2010
# Symfony2



Saturday, October 2, 2010
the evolution of symfony


               •      Mojavi 3

               •      symfony (2007)

               •      Symfony2 (2011)




Saturday, October 2, 2010
what’s old?




Saturday, October 2, 2010
what’s old?
                  •         same philosophy as symfony 1




Saturday, October 2, 2010
what’s old?
                  •         same philosophy as symfony 1

                      •      don’t reinvent the wheel




Saturday, October 2, 2010
what’s old?
                  •         same philosophy as symfony 1

                      •      don’t reinvent the wheel

                      •      loosely-coupled components




Saturday, October 2, 2010
what’s old?
                  •         same philosophy as symfony 1

                      •      don’t reinvent the wheel

                      •      loosely-coupled components

                      •      predictable conventions




Saturday, October 2, 2010
what’s old?
                  •         same philosophy as symfony 1

                      •      don’t reinvent the wheel

                      •      loosely-coupled components

                      •      predictable conventions

                      •      highly configurable




Saturday, October 2, 2010
what’s old?
                  •         same philosophy as symfony 1

                      •      don’t reinvent the wheel

                      •      loosely-coupled components

                      •      predictable conventions

                      •      highly configurable

                      •      testable



Saturday, October 2, 2010
what’s old?
                  •         same philosophy as symfony 1

                      •      don’t reinvent the wheel

                      •      loosely-coupled components

                      •      predictable conventions

                      •      highly configurable

                      •      testable

                      •      awesome developer tools

Saturday, October 2, 2010
what’s new?




Saturday, October 2, 2010
what’s new?

                  •         PHP 5.3

                  •         a brand new foundation




Saturday, October 2, 2010
what’s new?

                  •         PHP 5.3

                  •         a brand new foundation

                  •         more smart, more lazy




Saturday, October 2, 2010
what’s new?

                  •         PHP 5.3

                  •         a brand new foundation

                  •         more smart, more lazy

                  •         REALLY REALLY FAST



Saturday, October 2, 2010
what’s new?

                  •         PHP 5.3

                  •         a brand new foundation

                  •         more smart, more lazy

                  •         REALLY REALLY FAST



Saturday, October 2, 2010
PHP 5.3



Saturday, October 2, 2010
PHP 5.3


                  •         namespaces

                  •         closures




Saturday, October 2, 2010
Saturday, October 2, 2010
HTTPMessageRequest




Saturday, October 2, 2010
HTTPMessageRequest




Saturday, October 2, 2010
Saturday, October 2, 2010
Saturday, October 2, 2010
Saturday, October 2, 2010
HTTPClientRequest




Saturday, October 2, 2010
HTTPClientRequest




Saturday, October 2, 2010
Saturday, October 2, 2010
Saturday, October 2, 2010
Saturday, October 2, 2010
Saturday, October 2, 2010
Saturday, October 2, 2010
Saturday, October 2, 2010
Saturday, October 2, 2010
closures


                  •         anonymous functions

                  •         lambda functions




Saturday, October 2, 2010
Saturday, October 2, 2010
Saturday, October 2, 2010
Saturday, October 2, 2010
Saturday, October 2, 2010
Saturday, October 2, 2010
a new foundation




Saturday, October 2, 2010
anatomy of a Symfony2 request




Saturday, October 2, 2010
anatomy of a Symfony2 request
                  • Kernel




Saturday, October 2, 2010
anatomy of a Symfony2 request
                  • Kernel
                  • Request




Saturday, October 2, 2010
anatomy of a Symfony2 request
                  • Kernel
                  • Request
                  • Controller




Saturday, October 2, 2010
anatomy of a Symfony2 request
                  • Kernel
                  • Request
                  • Controller
                  • Response



Saturday, October 2, 2010
anatomy of a Symfony2 request




Saturday, October 2, 2010
anatomy of a Symfony2 request
                  •         index.php creates a Kernel




Saturday, October 2, 2010
anatomy of a Symfony2 request
                  •         index.php creates a Kernel

                  •         the kernel creates a Request




Saturday, October 2, 2010
anatomy of a Symfony2 request
                  •         index.php creates a Kernel

                  •         the kernel creates a Request

                  •         the kernel passes the Request to the ControllerResolver




Saturday, October 2, 2010
anatomy of a Symfony2 request
                  •         index.php creates a Kernel

                  •         the kernel creates a Request

                  •         the kernel passes the Request to the ControllerResolver

                  •         the ControllerResolver returns a callable




Saturday, October 2, 2010
anatomy of a Symfony2 request
                  •         index.php creates a Kernel

                  •         the kernel creates a Request

                  •         the kernel passes the Request to the ControllerResolver

                  •         the ControllerResolver returns a callable

                  •         the kernel calls the callable



Saturday, October 2, 2010
anatomy of a Symfony2 request
                  •         index.php creates a Kernel

                  •         the kernel creates a Request

                  •         the kernel passes the Request to the ControllerResolver

                  •         the ControllerResolver returns a callable

                  •         the kernel calls the callable

                  •         the callable returns a Response

Saturday, October 2, 2010
Silex
                            http://github.com/fabpot/Silex




Saturday, October 2, 2010
just enough, nothing more



Saturday, October 2, 2010
Saturday, October 2, 2010
switch ($_GET['pg'])
                            case 'edit':
                            // ...




Saturday, October 2, 2010
switch ($_GET['pg'])
                            case 'edit':
                            // ...




Saturday, October 2, 2010
Any volunteers to rewrite
                              WordPress in Silex?



Saturday, October 2, 2010
quick tour




Saturday, October 2, 2010
frontend/
                            src/
                            web/
Saturday, October 2, 2010
frontend/
                              FrontendKernel.php
                              cache/
                              config/
                              console
                              logs/
                              phpunit.xml
Saturday, October 2, 2010
src/
                              autoload.php
                              Application/
                              Bundle/
                              vendor/
                                 symfony/
                                 doctrine/
Saturday, October 2, 2010
web/
                              css/
                              images/
                              index.php
                              index_dev.php
                              js/
Saturday, October 2, 2010
../
                              MainBundle/
                                Controller/
                                MainBundle.php
                                Resources/
                                  config/
                                  views/
                                Tests/
Saturday, October 2, 2010
How do I use it?



Saturday, October 2, 2010
# frontend/config/routing.yml
          homepage:
            pattern: /
            defaults:
              _controller: MainBundle:Main:index
            requirements:
              _method: get


Saturday, October 2, 2010
// src/Application/MainBundle/Controller/MainController.php
          namespace ApplicationMainBundleController;

          class MainController extends Controller
          {
            public function indexAction()
            {
              return $this->render('MainBundle:Main:index.php');
            }
          }




Saturday, October 2, 2010
homepage:
            pattern: /
            defaults:
              _controller: MainBundle:Main:index
            requirements:
              _method: get


         namespace ApplicationMainBundleController;

         class MainController extends Controller
         {
           public function indexAction()
           {
             return $this->render('MainBundle:Main:index.php');
           }
         }
Saturday, October 2, 2010
homepage:
            pattern: /
            defaults:
              _controller: MainBundle:Main:index
            requirements:
              _method: get


         namespace ApplicationMainBundleController;

         class MainController extends Controller
         {
           public function indexAction()
           {
             return $this->render('MainBundle:Main:index.php');
           }
         }
Saturday, October 2, 2010
homepage:
            pattern: /
            defaults:
              _controller: MainBundle:Main:index
            requirements:
              _method: get


         namespace ApplicationMainBundleController;

         class MainController extends Controller
         {
           public function indexAction()
           {
             return $this->render('MainBundle:Main:index.php');
           }
         }
Saturday, October 2, 2010
homepage:
            pattern: /
            defaults:
              _controller: MainBundle:Main:index
            requirements:
              _method: get


         namespace ApplicationMainBundleController;

         class MainController extends Controller
         {
           public function indexAction()
           {
             return $this->render('MainBundle:Main:index.php');
           }
         }
Saturday, October 2, 2010
homepage:
            pattern: /
            defaults:
              _controller: MainBundle:Main:index
            requirements:
              _method: get


         namespace ApplicationMainBundleController;

         class MainController extends Controller
         {
           public function indexAction()
           {
             return $this->render('MainBundle:Main:index.php');
           }
         }
Saturday, October 2, 2010
homepage:
            pattern: /
            defaults:
              _controller: MainBundle:Main:index
            requirements:
              _method: get


         namespace ApplicationMainBundleController;

         class MainController extends Controller
         {
           public function indexAction()
           {
             return $this->render('MainBundle:Main:index.php');
           }
         }
Saturday, October 2, 2010
homepage:
            pattern: /:year/:slug
            defaults:
              _controller: MainBundle:Blog:showArticle
            requirements:
              year: d{4}


 namespace ApplicationMainBundleController;

 class BlogController extends Controller {
   public function showArticleAction($slug, $year) {
     // ...
     return $this->render('MainBundle:Blog:showArticle.php',
       array('article' => $article));
   }
 }
Saturday, October 2, 2010
homepage:
            pattern: /:year/:slug
            defaults:
              _controller: MainBundle:Blog:showArticle
            requirements:
              year: d{4}


 namespace ApplicationMainBundleController;

 class BlogController extends Controller {
   public function showArticleAction($slug, $year) {
     // ...
     return $this->render('MainBundle:Blog:showArticle.php',
       array('article' => $article));
   }
 }
Saturday, October 2, 2010
homepage:
            pattern: /:year/:slug
            defaults:
              _controller: MainBundle:Blog:showArticle
            requirements:
              year: d{4}


 namespace ApplicationMainBundleController;

 class BlogController extends Controller {
   public function showArticleAction($slug, $year) {
     // ...
     return $this->render('MainBundle:Blog:showArticle.php',
       array('article' => $article));
   }
 }
Saturday, October 2, 2010
homepage:
            pattern: /:year/:slug
            defaults:
              _controller: MainBundle:Blog:showArticle
            requirements:
              year: d{4}


 namespace ApplicationMainBundleController;

 class BlogController extends Controller {
   public function showArticleAction($slug, $year) {
     // ...
     return $this->render('MainBundle:Blog:showArticle.php',
       array('article' => $article));
   }
 }
Saturday, October 2, 2010
homepage:
            pattern: /:year/:slug
            defaults:
              _controller: MainBundle:Blog:showArticle
            requirements:
              year: d{4}


 namespace ApplicationMainBundleController;

 class BlogController extends Controller {
   public function showArticleAction($slug, $year) {
     // ...
     return $this->render('MainBundle:Blog:showArticle.php',
       array('article' => $article));
   }
 }
Saturday, October 2, 2010
MainBundle/Resources/
                              config/
                              views/
                                Blog/
                                  showArticle.php
                                Main/
                                  error404.php
                                  index.php
                                layout.php

Saturday, October 2, 2010
return $this->render('MainBundle:Blog:showArticle.php',
            array('article' => $article));


                            MainBundle/Resources/
                              config/
                              views/
                                Blog/
                                  showArticle.php
                                Main/
                                  error404.php
                                  index.php
                                layout.php
Saturday, October 2, 2010
return $this->render('MainBundle:Blog:showArticle.php',
            array('article' => $article));


                            MainBundle/Resources/
                              config/
                              views/
                                Blog/
                                  showArticle.php
                                Main/
                                  error404.php
                                  index.php
                                layout.php
Saturday, October 2, 2010
return $this->render('MainBundle:Blog:showArticle.php',
            array('article' => $article));


                            MainBundle/Resources/
                              config/
                              views/
                                Blog/
                                  showArticle.php
                                Main/
                                  error404.php
                                  index.php
                                layout.php
Saturday, October 2, 2010
return $this->render('MainBundle:Blog:showArticle.php',
            array('article' => $article));


                            MainBundle/Resources/
                              config/
                              views/
                                Blog/
                                  showArticle.php
                                Main/
                                  error404.php
                                  index.php
                                layout.php
Saturday, October 2, 2010
return $this->render('MainBundle:Blog:showArticle.php',
            array('article' => $article));


                            MainBundle/Resources/
                              config/
                              views/
                                Blog/
                                  showArticle.php
                                Main/
                                  error404.php
                                  index.php
                                layout.php
Saturday, October 2, 2010
return $this->render('MainBundle:Blog:showArticle.php',
            array('article' => $article));


                            MainBundle/Resources/
                              config/
                              views/
                                Blog/
                                  showArticle.php
                                Main/
                                  error404.php
                                  index.php
                                layout.php
Saturday, October 2, 2010
return $this->render('MainBundle:Blog:showArticle.twig',
   array('article' => $article));


                            MainBundle/Resources/
                              config/
                              views/
                                Blog/
                                  showArticle.twig
                                Main/
                                  error404.php
                                  index.php
                                layout.php
Saturday, October 2, 2010
return $this->render('MainBundle:Blog:showArticle.twig',
   array('article' => $article));


                            MainBundle/Resources/
                              config/
                              views/
                                Blog/
                                  showArticle.twig
                                Main/
                                  error404.php
                                  index.php
                                layout.php
Saturday, October 2, 2010
Twig
                            The flexible, fast, and secure template language for PHP
                                              http://twig-project.org




Saturday, October 2, 2010
symfony 1




Saturday, October 2, 2010
symfony 1
                  •         templates




Saturday, October 2, 2010
symfony 1
                  •         templates

                  •         layouts




Saturday, October 2, 2010
symfony 1
                  •         templates

                  •         layouts

                  •         slots




Saturday, October 2, 2010
symfony 1
                  •         templates

                  •         layouts

                  •         slots

                  •         components




Saturday, October 2, 2010
symfony 1
                  •         templates

                  •         layouts

                  •         slots

                  •         components

                  •         partials



Saturday, October 2, 2010
symfony 1
                  •         templates

                  •         layouts

                  •         slots

                  •         components

                  •         partials

                  •         component slots

Saturday, October 2, 2010
fewer concepts, more power



Saturday, October 2, 2010
Symfony2




Saturday, October 2, 2010
Symfony2


                  •         templates




Saturday, October 2, 2010
Symfony2


                  •         templates

                  •         slots




Saturday, October 2, 2010
Symfony2


                  •
                  •
                            templates

                            slots       }   fewer concepts, more power




Saturday, October 2, 2010
<?php $view->extend('MainBundle::layout.php') ?>

   <?php foreach ($people as $person): ?>

            <?php $view->render(
              'MainBundle:Person:thumbnail',
              array('person' => $person)
            ) ?>

   <?php endforeach; ?>


Saturday, October 2, 2010
<?php $view->extend('MainBundle::layout.php') ?>

   <?php foreach ($people as $person): ?>
                            decorate_with()
            <?php $view->render(
              'MainBundle:Person:thumbnail',
              array('person' => $person)
            ) ?>

   <?php endforeach; ?>


Saturday, October 2, 2010
<?php $view->extend('MainBundle::layout.php') ?>

   <?php foreach ($people as $person): ?>

            <?php $view->render(
              'MainBundle:Person:thumbnail',
              array('person' => $person)
            ) ?>

   <?php endforeach; ?>


Saturday, October 2, 2010
<?php $view->extend('MainBundle::layout.php') ?>

   <?php foreach ($people as $person): ?>

            <?php $view->render(
              'MainBundle:Person:thumbnail',
              array('person' => $person)
            ) ?>

   <?php endforeach; ?>


Saturday, October 2, 2010
<?php $view->extend('MainBundle::layout.php') ?>

   <?php foreach ($people as $person): ?>

            <?php $view->render(
              'MainBundle:Person:thumbnail',
              array('person' => $person)
            ) ?> include_partial()

   <?php endforeach; ?>


Saturday, October 2, 2010
<?php $view->extend('MainBundle::layout.php') ?>

   <?php foreach ($people as $person): ?>

            <?php $view->render(
              'MainBundle:Person:thumbnail',
              array('person' => $person)
            ) ?>

   <?php endforeach; ?>


Saturday, October 2, 2010
helpers



Saturday, October 2, 2010
<?php $view['slots']->set('title', 'Hi!') ?>



<?php $view['slots']->start('sidebar') ?>

         My awesome sidebar!

<?php $view['slots']->stop() ?>

Saturday, October 2, 2010
<?php $view['slots']->set('title', 'Hi!') ?>



<?php $view['slots']->start('sidebar') ?>

         My awesome sidebar!

<?php $view['slots']->stop() ?>

Saturday, October 2, 2010
helpers are objects



Saturday, October 2, 2010
$view['javascripts']->add('script.js');
             echo $view['javascripts'];

             echo $view['assets']->getUrl('logo.gif');
               use_javascript()
             echo $view['router']->generate(
                'person_show',
                array('username' => $username)
             );

             $view['actions']->output('MainBundle:Search:form');



Saturday, October 2, 2010
$view['javascripts']->add('script.js');
             echo $view['javascripts'];

             echo $view['assets']->getUrl('logo.gif');

                 include_javascripts()
             echo $view['router']->generate(
                'person_show',
                array('username' => $username)
             );

             $view['actions']->output('MainBundle:Search:form');



Saturday, October 2, 2010
$view['javascripts']->add('script.js');
             echo $view['javascripts'];

             echo $view['assets']->getUrl('logo.gif');

             echo $view['router']->generate(
                'person_show',
                        public_path()
                array('username' => $username)
             );

             $view['actions']->output('MainBundle:Search:form');



Saturday, October 2, 2010
$view['javascripts']->add('script.js');
             echo $view['javascripts'];

             echo $view['assets']->getUrl('logo.gif');

             echo $view['router']->generate(
                'person_show',
                array('username' => $username)
             );
                               url_for()
             $view['actions']->output('MainBundle:Search:form');



Saturday, October 2, 2010
$view['javascripts']->add('script.js');
             echo $view['javascripts'];

             echo $view['assets']->getUrl('logo.gif');

             echo $view['router']->generate(
                          include_component()
                'person_show',
                array('username' => $username)
             );

             $view['actions']->output('MainBundle:Search:form');



Saturday, October 2, 2010
dependency injection



Saturday, October 2, 2010
lazy objects




Saturday, October 2, 2010
“   if you want me to foo
                            you better give me the foo-er



Saturday, October 2, 2010
                                                     ”
class User
                    {
                      protected $session;

                            public function __construct(Session $session)
                            {
                              $this->session = $session;
                            }
                    }




Saturday, October 2, 2010
class User
                    {
                      protected $session;

                            public function __construct()
                            {
                              $this->session = Session::factory();
                            }
                    }




Saturday, October 2, 2010
class User
                    {
                      protected $session;

                            public function __construct()
                            {
                              $this->session = Session::factory();
                            }
                    }




Saturday, October 2, 2010
$session = $this->getMock('Session')
                              ->expects($this->any())
                              ->method('get')
                              ->with('foo')
                              ->will($this->returnValue('bar'))
                            ;

                            // inject the mock object!
                            $user = new User($session);

                            $this->assertEquals('bar',
                              $user->getSessionVar('foo'));
Saturday, October 2, 2010
dependency injection container

                  •         a configuration layer


                  •         creates a "container" that manages the
                            creation of objects


                  •         “teach” the container


                  •         using xml, yaml, php, ini
                            (or some combination)




Saturday, October 2, 2010
services:
                              session:
                                class: Session

                              user:
                                class: User
                                arguments:
                                  - @session
Saturday, October 2, 2010
public function getUserService()
                   {
                     if (isset($this->shared['user']))
                       return $this->shared['user'];

                            $user = new User(
                              $this->getSessionService()
                            );

                            $this->shared['user'] = $user;

                            return $user;
                   }
Saturday, October 2, 2010
// get one service by name
          $container->get('user');



Saturday, October 2, 2010
// find many services by "tag"
 $c->findTaggedServiceIds('my_tag');




Saturday, October 2, 2010
services:
                     foo_helper:
                       class: Foo
                       tags:
                         -
                           name: my_tag


Saturday, October 2, 2010
container parameters



Saturday, October 2, 2010
parameters:
                         foo.class: Foo

                       services:
                         foo:
                           class: %foo.class%
Saturday, October 2, 2010
parameters:
                         foo.class: Foo

                       services:
                         foo:
                           class: %foo.class%
Saturday, October 2, 2010
parameters:
                         foo.class: Foo

                       services:
                         foo:
                           class: %foo.class%
Saturday, October 2, 2010
dependency injection extensions
                                 semantic configuration




Saturday, October 2, 2010
doctrine.dbal:
                              dbname:   xxx
                              user:     xxx
                              password: xxx

                            doctrine.orm: ~
Saturday, October 2, 2010
awesome developer tools



Saturday, October 2, 2010
Web Debug Toolbar




Saturday, October 2, 2010
Web Debug Toolbar




Saturday, October 2, 2010
Web Debug Toolbar




Saturday, October 2, 2010
Web Profiler




Saturday, October 2, 2010
Web Profiler




Saturday, October 2, 2010
Web Profiler




Saturday, October 2, 2010
Web Profiler




Saturday, October 2, 2010
Web Profiler




Saturday, October 2, 2010
Questions?



Saturday, October 2, 2010
OpenSky is Hiring!
                              http://engineering.shopopensky.com

                             Please contact me if you're interested.




Saturday, October 2, 2010
OpenSky is Hiring!
                              http://engineering.shopopensky.com

                             Please contact me if you're interested.




Saturday, October 2, 2010
symfony-reloaded.org




Saturday, October 2, 2010

More Related Content

Viewers also liked

Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2Sumy PHP User Grpoup
 
Effective Doctrine2: Performance Tips for Symfony2 Developers
Effective Doctrine2: Performance Tips for Symfony2 DevelopersEffective Doctrine2: Performance Tips for Symfony2 Developers
Effective Doctrine2: Performance Tips for Symfony2 DevelopersMarcin Chwedziak
 
Introduzione al linguaggio PHP
Introduzione al linguaggio PHPIntroduzione al linguaggio PHP
Introduzione al linguaggio PHPextrategy
 
PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015Colin O'Dell
 
Last train to php 7
Last train to php 7Last train to php 7
Last train to php 7Damien Seguy
 
Symfony Best Practices
Symfony Best Practices Symfony Best Practices
Symfony Best Practices Tigran Azatyan
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHPBradley Holt
 
Symfony2 and MongoDB
Symfony2 and MongoDBSymfony2 and MongoDB
Symfony2 and MongoDBPablo Godel
 
Creating Mobile Apps With PHP & Symfony2
Creating Mobile Apps With PHP & Symfony2Creating Mobile Apps With PHP & Symfony2
Creating Mobile Apps With PHP & Symfony2Pablo Godel
 

Viewers also liked (13)

From * to Symfony2
From * to Symfony2From * to Symfony2
From * to Symfony2
 
Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2
 
Effective Doctrine2: Performance Tips for Symfony2 Developers
Effective Doctrine2: Performance Tips for Symfony2 DevelopersEffective Doctrine2: Performance Tips for Symfony2 Developers
Effective Doctrine2: Performance Tips for Symfony2 Developers
 
Doctrine for Dummies
Doctrine for DummiesDoctrine for Dummies
Doctrine for Dummies
 
Introduzione al linguaggio PHP
Introduzione al linguaggio PHPIntroduzione al linguaggio PHP
Introduzione al linguaggio PHP
 
PHP 7
PHP 7PHP 7
PHP 7
 
PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015
 
Last train to php 7
Last train to php 7Last train to php 7
Last train to php 7
 
Symfony Best Practices
Symfony Best Practices Symfony Best Practices
Symfony Best Practices
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Symfony2 and MongoDB
Symfony2 and MongoDBSymfony2 and MongoDB
Symfony2 and MongoDB
 
Creating Mobile Apps With PHP & Symfony2
Creating Mobile Apps With PHP & Symfony2Creating Mobile Apps With PHP & Symfony2
Creating Mobile Apps With PHP & Symfony2
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 

More from Kris Wallsmith

How kris-writes-symfony-apps-london
How kris-writes-symfony-apps-londonHow kris-writes-symfony-apps-london
How kris-writes-symfony-apps-londonKris Wallsmith
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony AppsKris Wallsmith
 
Love and Loss: A Symfony Security Play
Love and Loss: A Symfony Security PlayLove and Loss: A Symfony Security Play
Love and Loss: A Symfony Security PlayKris Wallsmith
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony AppsKris Wallsmith
 
Assetic (Symfony Live Paris)
Assetic (Symfony Live Paris)Assetic (Symfony Live Paris)
Assetic (Symfony Live Paris)Kris Wallsmith
 
Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Kris Wallsmith
 
Introducing Assetic: Asset Management for PHP 5.3
Introducing Assetic: Asset Management for PHP 5.3Introducing Assetic: Asset Management for PHP 5.3
Introducing Assetic: Asset Management for PHP 5.3Kris Wallsmith
 
Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Kris Wallsmith
 
Advanced symfony Techniques
Advanced symfony TechniquesAdvanced symfony Techniques
Advanced symfony TechniquesKris Wallsmith
 

More from Kris Wallsmith (16)

Matters of State
Matters of StateMatters of State
Matters of State
 
The View From Inside
The View From InsideThe View From Inside
The View From Inside
 
How kris-writes-symfony-apps-london
How kris-writes-symfony-apps-londonHow kris-writes-symfony-apps-london
How kris-writes-symfony-apps-london
 
Drupal, meet Assetic
Drupal, meet AsseticDrupal, meet Assetic
Drupal, meet Assetic
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony Apps
 
Love and Loss: A Symfony Security Play
Love and Loss: A Symfony Security PlayLove and Loss: A Symfony Security Play
Love and Loss: A Symfony Security Play
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony Apps
 
Assetic (Zendcon)
Assetic (Zendcon)Assetic (Zendcon)
Assetic (Zendcon)
 
Assetic (OSCON)
Assetic (OSCON)Assetic (OSCON)
Assetic (OSCON)
 
Assetic (Symfony Live Paris)
Assetic (Symfony Live Paris)Assetic (Symfony Live Paris)
Assetic (Symfony Live Paris)
 
Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)
 
Introducing Assetic: Asset Management for PHP 5.3
Introducing Assetic: Asset Management for PHP 5.3Introducing Assetic: Asset Management for PHP 5.3
Introducing Assetic: Asset Management for PHP 5.3
 
Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)
 
Advanced symfony Techniques
Advanced symfony TechniquesAdvanced symfony Techniques
Advanced symfony Techniques
 
Symfony 2
Symfony 2Symfony 2
Symfony 2
 
Symfony in the Cloud
Symfony in the CloudSymfony in the Cloud
Symfony in the Cloud
 

Recently uploaded

Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxMatsuo Lab
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxGDSC PJATK
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationIES VE
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioChristian Posta
 
99.99% of Your Traces Are (Probably) Trash (SRECon NA 2024).pdf
99.99% of Your Traces  Are (Probably) Trash (SRECon NA 2024).pdf99.99% of Your Traces  Are (Probably) Trash (SRECon NA 2024).pdf
99.99% of Your Traces Are (Probably) Trash (SRECon NA 2024).pdfPaige Cruz
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureEric D. Schabell
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaborationbruanjhuli
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...Aggregage
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Commit University
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfAijun Zhang
 
20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-pyJamie (Taka) Wang
 
The Kubernetes Gateway API and its role in Cloud Native API Management
The Kubernetes Gateway API and its role in Cloud Native API ManagementThe Kubernetes Gateway API and its role in Cloud Native API Management
The Kubernetes Gateway API and its role in Cloud Native API ManagementNuwan Dias
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Brian Pichman
 
UiPath Studio Web workshop series - Day 5
UiPath Studio Web workshop series - Day 5UiPath Studio Web workshop series - Day 5
UiPath Studio Web workshop series - Day 5DianaGray10
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?IES VE
 
UiPath Clipboard AI: "A TIME Magazine Best Invention of 2023 Unveiled"
UiPath Clipboard AI: "A TIME Magazine Best Invention of 2023 Unveiled"UiPath Clipboard AI: "A TIME Magazine Best Invention of 2023 Unveiled"
UiPath Clipboard AI: "A TIME Magazine Best Invention of 2023 Unveiled"DianaGray10
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdfPedro Manuel
 
All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...
All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...
All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...Daniel Zivkovic
 
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfJamie (Taka) Wang
 

Recently uploaded (20)

Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptx
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptx
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and Istio
 
99.99% of Your Traces Are (Probably) Trash (SRECon NA 2024).pdf
99.99% of Your Traces  Are (Probably) Trash (SRECon NA 2024).pdf99.99% of Your Traces  Are (Probably) Trash (SRECon NA 2024).pdf
99.99% of Your Traces Are (Probably) Trash (SRECon NA 2024).pdf
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability Adventure
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdf
 
20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-py
 
The Kubernetes Gateway API and its role in Cloud Native API Management
The Kubernetes Gateway API and its role in Cloud Native API ManagementThe Kubernetes Gateway API and its role in Cloud Native API Management
The Kubernetes Gateway API and its role in Cloud Native API Management
 
20230104 - machine vision
20230104 - machine vision20230104 - machine vision
20230104 - machine vision
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )
 
UiPath Studio Web workshop series - Day 5
UiPath Studio Web workshop series - Day 5UiPath Studio Web workshop series - Day 5
UiPath Studio Web workshop series - Day 5
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?
 
UiPath Clipboard AI: "A TIME Magazine Best Invention of 2023 Unveiled"
UiPath Clipboard AI: "A TIME Magazine Best Invention of 2023 Unveiled"UiPath Clipboard AI: "A TIME Magazine Best Invention of 2023 Unveiled"
UiPath Clipboard AI: "A TIME Magazine Best Invention of 2023 Unveiled"
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdf
 
All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...
All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...
All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...
 
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
 

A Practical Introduction to Symfony2

  • 1. A Practical Introduction to Symfony2 Kris Wallsmith PHP Matsuri • October 2, 2010 Saturday, October 2, 2010
  • 2. @kriswallsmith • Release Manager for symfony 1.3 & 1.4 • Doctrine contributor • Senior Software Engineer at • 10 years experience in web development • Open source evangelist and international speaker Saturday, October 2, 2010
  • 3. the evolution of symfony • Mojavi 3 • symfony (2007) • Symfony2 (2011) Saturday, October 2, 2010
  • 4. a quick note for the case-sensitive among us Saturday, October 2, 2010
  • 6. talk about “symfony 1” Saturday, October 2, 2010
  • 8. there is no “Symfony 1” Saturday, October 2, 2010
  • 9. there is no “symfony 2” Saturday, October 2, 2010
  • 10. there is no “Symfony 2” Saturday, October 2, 2010
  • 11. there is no “Symfony 2” { less search-friendly Saturday, October 2, 2010
  • 14. the evolution of symfony • Mojavi 3 • symfony (2007) • Symfony2 (2011) Saturday, October 2, 2010
  • 16. what’s old? • same philosophy as symfony 1 Saturday, October 2, 2010
  • 17. what’s old? • same philosophy as symfony 1 • don’t reinvent the wheel Saturday, October 2, 2010
  • 18. what’s old? • same philosophy as symfony 1 • don’t reinvent the wheel • loosely-coupled components Saturday, October 2, 2010
  • 19. what’s old? • same philosophy as symfony 1 • don’t reinvent the wheel • loosely-coupled components • predictable conventions Saturday, October 2, 2010
  • 20. what’s old? • same philosophy as symfony 1 • don’t reinvent the wheel • loosely-coupled components • predictable conventions • highly configurable Saturday, October 2, 2010
  • 21. what’s old? • same philosophy as symfony 1 • don’t reinvent the wheel • loosely-coupled components • predictable conventions • highly configurable • testable Saturday, October 2, 2010
  • 22. what’s old? • same philosophy as symfony 1 • don’t reinvent the wheel • loosely-coupled components • predictable conventions • highly configurable • testable • awesome developer tools Saturday, October 2, 2010
  • 24. what’s new? • PHP 5.3 • a brand new foundation Saturday, October 2, 2010
  • 25. what’s new? • PHP 5.3 • a brand new foundation • more smart, more lazy Saturday, October 2, 2010
  • 26. what’s new? • PHP 5.3 • a brand new foundation • more smart, more lazy • REALLY REALLY FAST Saturday, October 2, 2010
  • 27. what’s new? • PHP 5.3 • a brand new foundation • more smart, more lazy • REALLY REALLY FAST Saturday, October 2, 2010
  • 29. PHP 5.3 • namespaces • closures Saturday, October 2, 2010
  • 45. closures • anonymous functions • lambda functions Saturday, October 2, 2010
  • 51. a new foundation Saturday, October 2, 2010
  • 52. anatomy of a Symfony2 request Saturday, October 2, 2010
  • 53. anatomy of a Symfony2 request • Kernel Saturday, October 2, 2010
  • 54. anatomy of a Symfony2 request • Kernel • Request Saturday, October 2, 2010
  • 55. anatomy of a Symfony2 request • Kernel • Request • Controller Saturday, October 2, 2010
  • 56. anatomy of a Symfony2 request • Kernel • Request • Controller • Response Saturday, October 2, 2010
  • 57. anatomy of a Symfony2 request Saturday, October 2, 2010
  • 58. anatomy of a Symfony2 request • index.php creates a Kernel Saturday, October 2, 2010
  • 59. anatomy of a Symfony2 request • index.php creates a Kernel • the kernel creates a Request Saturday, October 2, 2010
  • 60. anatomy of a Symfony2 request • index.php creates a Kernel • the kernel creates a Request • the kernel passes the Request to the ControllerResolver Saturday, October 2, 2010
  • 61. anatomy of a Symfony2 request • index.php creates a Kernel • the kernel creates a Request • the kernel passes the Request to the ControllerResolver • the ControllerResolver returns a callable Saturday, October 2, 2010
  • 62. anatomy of a Symfony2 request • index.php creates a Kernel • the kernel creates a Request • the kernel passes the Request to the ControllerResolver • the ControllerResolver returns a callable • the kernel calls the callable Saturday, October 2, 2010
  • 63. anatomy of a Symfony2 request • index.php creates a Kernel • the kernel creates a Request • the kernel passes the Request to the ControllerResolver • the ControllerResolver returns a callable • the kernel calls the callable • the callable returns a Response Saturday, October 2, 2010
  • 64. Silex http://github.com/fabpot/Silex Saturday, October 2, 2010
  • 65. just enough, nothing more Saturday, October 2, 2010
  • 67. switch ($_GET['pg']) case 'edit': // ... Saturday, October 2, 2010
  • 68. switch ($_GET['pg']) case 'edit': // ... Saturday, October 2, 2010
  • 69. Any volunteers to rewrite WordPress in Silex? Saturday, October 2, 2010
  • 71. frontend/ src/ web/ Saturday, October 2, 2010
  • 72. frontend/ FrontendKernel.php cache/ config/ console logs/ phpunit.xml Saturday, October 2, 2010
  • 73. src/ autoload.php Application/ Bundle/ vendor/ symfony/ doctrine/ Saturday, October 2, 2010
  • 74. web/ css/ images/ index.php index_dev.php js/ Saturday, October 2, 2010
  • 75. ../ MainBundle/ Controller/ MainBundle.php Resources/ config/ views/ Tests/ Saturday, October 2, 2010
  • 76. How do I use it? Saturday, October 2, 2010
  • 77. # frontend/config/routing.yml homepage: pattern: / defaults: _controller: MainBundle:Main:index requirements: _method: get Saturday, October 2, 2010
  • 78. // src/Application/MainBundle/Controller/MainController.php namespace ApplicationMainBundleController; class MainController extends Controller { public function indexAction() { return $this->render('MainBundle:Main:index.php'); } } Saturday, October 2, 2010
  • 79. homepage: pattern: / defaults: _controller: MainBundle:Main:index requirements: _method: get namespace ApplicationMainBundleController; class MainController extends Controller { public function indexAction() { return $this->render('MainBundle:Main:index.php'); } } Saturday, October 2, 2010
  • 80. homepage: pattern: / defaults: _controller: MainBundle:Main:index requirements: _method: get namespace ApplicationMainBundleController; class MainController extends Controller { public function indexAction() { return $this->render('MainBundle:Main:index.php'); } } Saturday, October 2, 2010
  • 81. homepage: pattern: / defaults: _controller: MainBundle:Main:index requirements: _method: get namespace ApplicationMainBundleController; class MainController extends Controller { public function indexAction() { return $this->render('MainBundle:Main:index.php'); } } Saturday, October 2, 2010
  • 82. homepage: pattern: / defaults: _controller: MainBundle:Main:index requirements: _method: get namespace ApplicationMainBundleController; class MainController extends Controller { public function indexAction() { return $this->render('MainBundle:Main:index.php'); } } Saturday, October 2, 2010
  • 83. homepage: pattern: / defaults: _controller: MainBundle:Main:index requirements: _method: get namespace ApplicationMainBundleController; class MainController extends Controller { public function indexAction() { return $this->render('MainBundle:Main:index.php'); } } Saturday, October 2, 2010
  • 84. homepage: pattern: / defaults: _controller: MainBundle:Main:index requirements: _method: get namespace ApplicationMainBundleController; class MainController extends Controller { public function indexAction() { return $this->render('MainBundle:Main:index.php'); } } Saturday, October 2, 2010
  • 85. homepage: pattern: /:year/:slug defaults: _controller: MainBundle:Blog:showArticle requirements: year: d{4} namespace ApplicationMainBundleController; class BlogController extends Controller { public function showArticleAction($slug, $year) { // ... return $this->render('MainBundle:Blog:showArticle.php', array('article' => $article)); } } Saturday, October 2, 2010
  • 86. homepage: pattern: /:year/:slug defaults: _controller: MainBundle:Blog:showArticle requirements: year: d{4} namespace ApplicationMainBundleController; class BlogController extends Controller { public function showArticleAction($slug, $year) { // ... return $this->render('MainBundle:Blog:showArticle.php', array('article' => $article)); } } Saturday, October 2, 2010
  • 87. homepage: pattern: /:year/:slug defaults: _controller: MainBundle:Blog:showArticle requirements: year: d{4} namespace ApplicationMainBundleController; class BlogController extends Controller { public function showArticleAction($slug, $year) { // ... return $this->render('MainBundle:Blog:showArticle.php', array('article' => $article)); } } Saturday, October 2, 2010
  • 88. homepage: pattern: /:year/:slug defaults: _controller: MainBundle:Blog:showArticle requirements: year: d{4} namespace ApplicationMainBundleController; class BlogController extends Controller { public function showArticleAction($slug, $year) { // ... return $this->render('MainBundle:Blog:showArticle.php', array('article' => $article)); } } Saturday, October 2, 2010
  • 89. homepage: pattern: /:year/:slug defaults: _controller: MainBundle:Blog:showArticle requirements: year: d{4} namespace ApplicationMainBundleController; class BlogController extends Controller { public function showArticleAction($slug, $year) { // ... return $this->render('MainBundle:Blog:showArticle.php', array('article' => $article)); } } Saturday, October 2, 2010
  • 90. MainBundle/Resources/ config/ views/ Blog/ showArticle.php Main/ error404.php index.php layout.php Saturday, October 2, 2010
  • 91. return $this->render('MainBundle:Blog:showArticle.php', array('article' => $article)); MainBundle/Resources/ config/ views/ Blog/ showArticle.php Main/ error404.php index.php layout.php Saturday, October 2, 2010
  • 92. return $this->render('MainBundle:Blog:showArticle.php', array('article' => $article)); MainBundle/Resources/ config/ views/ Blog/ showArticle.php Main/ error404.php index.php layout.php Saturday, October 2, 2010
  • 93. return $this->render('MainBundle:Blog:showArticle.php', array('article' => $article)); MainBundle/Resources/ config/ views/ Blog/ showArticle.php Main/ error404.php index.php layout.php Saturday, October 2, 2010
  • 94. return $this->render('MainBundle:Blog:showArticle.php', array('article' => $article)); MainBundle/Resources/ config/ views/ Blog/ showArticle.php Main/ error404.php index.php layout.php Saturday, October 2, 2010
  • 95. return $this->render('MainBundle:Blog:showArticle.php', array('article' => $article)); MainBundle/Resources/ config/ views/ Blog/ showArticle.php Main/ error404.php index.php layout.php Saturday, October 2, 2010
  • 96. return $this->render('MainBundle:Blog:showArticle.php', array('article' => $article)); MainBundle/Resources/ config/ views/ Blog/ showArticle.php Main/ error404.php index.php layout.php Saturday, October 2, 2010
  • 97. return $this->render('MainBundle:Blog:showArticle.twig', array('article' => $article)); MainBundle/Resources/ config/ views/ Blog/ showArticle.twig Main/ error404.php index.php layout.php Saturday, October 2, 2010
  • 98. return $this->render('MainBundle:Blog:showArticle.twig', array('article' => $article)); MainBundle/Resources/ config/ views/ Blog/ showArticle.twig Main/ error404.php index.php layout.php Saturday, October 2, 2010
  • 99. Twig The flexible, fast, and secure template language for PHP http://twig-project.org Saturday, October 2, 2010
  • 101. symfony 1 • templates Saturday, October 2, 2010
  • 102. symfony 1 • templates • layouts Saturday, October 2, 2010
  • 103. symfony 1 • templates • layouts • slots Saturday, October 2, 2010
  • 104. symfony 1 • templates • layouts • slots • components Saturday, October 2, 2010
  • 105. symfony 1 • templates • layouts • slots • components • partials Saturday, October 2, 2010
  • 106. symfony 1 • templates • layouts • slots • components • partials • component slots Saturday, October 2, 2010
  • 107. fewer concepts, more power Saturday, October 2, 2010
  • 109. Symfony2 • templates Saturday, October 2, 2010
  • 110. Symfony2 • templates • slots Saturday, October 2, 2010
  • 111. Symfony2 • • templates slots } fewer concepts, more power Saturday, October 2, 2010
  • 112. <?php $view->extend('MainBundle::layout.php') ?> <?php foreach ($people as $person): ?> <?php $view->render( 'MainBundle:Person:thumbnail', array('person' => $person) ) ?> <?php endforeach; ?> Saturday, October 2, 2010
  • 113. <?php $view->extend('MainBundle::layout.php') ?> <?php foreach ($people as $person): ?> decorate_with() <?php $view->render( 'MainBundle:Person:thumbnail', array('person' => $person) ) ?> <?php endforeach; ?> Saturday, October 2, 2010
  • 114. <?php $view->extend('MainBundle::layout.php') ?> <?php foreach ($people as $person): ?> <?php $view->render( 'MainBundle:Person:thumbnail', array('person' => $person) ) ?> <?php endforeach; ?> Saturday, October 2, 2010
  • 115. <?php $view->extend('MainBundle::layout.php') ?> <?php foreach ($people as $person): ?> <?php $view->render( 'MainBundle:Person:thumbnail', array('person' => $person) ) ?> <?php endforeach; ?> Saturday, October 2, 2010
  • 116. <?php $view->extend('MainBundle::layout.php') ?> <?php foreach ($people as $person): ?> <?php $view->render( 'MainBundle:Person:thumbnail', array('person' => $person) ) ?> include_partial() <?php endforeach; ?> Saturday, October 2, 2010
  • 117. <?php $view->extend('MainBundle::layout.php') ?> <?php foreach ($people as $person): ?> <?php $view->render( 'MainBundle:Person:thumbnail', array('person' => $person) ) ?> <?php endforeach; ?> Saturday, October 2, 2010
  • 119. <?php $view['slots']->set('title', 'Hi!') ?> <?php $view['slots']->start('sidebar') ?> My awesome sidebar! <?php $view['slots']->stop() ?> Saturday, October 2, 2010
  • 120. <?php $view['slots']->set('title', 'Hi!') ?> <?php $view['slots']->start('sidebar') ?> My awesome sidebar! <?php $view['slots']->stop() ?> Saturday, October 2, 2010
  • 121. helpers are objects Saturday, October 2, 2010
  • 122. $view['javascripts']->add('script.js'); echo $view['javascripts']; echo $view['assets']->getUrl('logo.gif'); use_javascript() echo $view['router']->generate( 'person_show', array('username' => $username) ); $view['actions']->output('MainBundle:Search:form'); Saturday, October 2, 2010
  • 123. $view['javascripts']->add('script.js'); echo $view['javascripts']; echo $view['assets']->getUrl('logo.gif'); include_javascripts() echo $view['router']->generate( 'person_show', array('username' => $username) ); $view['actions']->output('MainBundle:Search:form'); Saturday, October 2, 2010
  • 124. $view['javascripts']->add('script.js'); echo $view['javascripts']; echo $view['assets']->getUrl('logo.gif'); echo $view['router']->generate( 'person_show', public_path() array('username' => $username) ); $view['actions']->output('MainBundle:Search:form'); Saturday, October 2, 2010
  • 125. $view['javascripts']->add('script.js'); echo $view['javascripts']; echo $view['assets']->getUrl('logo.gif'); echo $view['router']->generate( 'person_show', array('username' => $username) ); url_for() $view['actions']->output('MainBundle:Search:form'); Saturday, October 2, 2010
  • 126. $view['javascripts']->add('script.js'); echo $view['javascripts']; echo $view['assets']->getUrl('logo.gif'); echo $view['router']->generate( include_component() 'person_show', array('username' => $username) ); $view['actions']->output('MainBundle:Search:form'); Saturday, October 2, 2010
  • 129. if you want me to foo you better give me the foo-er Saturday, October 2, 2010 ”
  • 130. class User { protected $session; public function __construct(Session $session) { $this->session = $session; } } Saturday, October 2, 2010
  • 131. class User { protected $session; public function __construct() { $this->session = Session::factory(); } } Saturday, October 2, 2010
  • 132. class User { protected $session; public function __construct() { $this->session = Session::factory(); } } Saturday, October 2, 2010
  • 133. $session = $this->getMock('Session') ->expects($this->any()) ->method('get') ->with('foo') ->will($this->returnValue('bar')) ; // inject the mock object! $user = new User($session); $this->assertEquals('bar', $user->getSessionVar('foo')); Saturday, October 2, 2010
  • 134. dependency injection container • a configuration layer • creates a "container" that manages the creation of objects • “teach” the container • using xml, yaml, php, ini (or some combination) Saturday, October 2, 2010
  • 135. services: session: class: Session user: class: User arguments: - @session Saturday, October 2, 2010
  • 136. public function getUserService() { if (isset($this->shared['user'])) return $this->shared['user']; $user = new User( $this->getSessionService() ); $this->shared['user'] = $user; return $user; } Saturday, October 2, 2010
  • 137. // get one service by name $container->get('user'); Saturday, October 2, 2010
  • 138. // find many services by "tag" $c->findTaggedServiceIds('my_tag'); Saturday, October 2, 2010
  • 139. services: foo_helper: class: Foo tags: - name: my_tag Saturday, October 2, 2010
  • 141. parameters: foo.class: Foo services: foo: class: %foo.class% Saturday, October 2, 2010
  • 142. parameters: foo.class: Foo services: foo: class: %foo.class% Saturday, October 2, 2010
  • 143. parameters: foo.class: Foo services: foo: class: %foo.class% Saturday, October 2, 2010
  • 144. dependency injection extensions semantic configuration Saturday, October 2, 2010
  • 145. doctrine.dbal: dbname: xxx user: xxx password: xxx doctrine.orm: ~ Saturday, October 2, 2010
  • 147. Web Debug Toolbar Saturday, October 2, 2010
  • 148. Web Debug Toolbar Saturday, October 2, 2010
  • 149. Web Debug Toolbar Saturday, October 2, 2010
  • 156. OpenSky is Hiring! http://engineering.shopopensky.com Please contact me if you're interested. Saturday, October 2, 2010
  • 157. OpenSky is Hiring! http://engineering.shopopensky.com Please contact me if you're interested. Saturday, October 2, 2010