SlideShare a Scribd company logo
1 of 58
Download to read offline
Beyond symfony 1.2

     Fabien Potencier
Work on symfony 2
    started 2 years ago
with a brand new code base
symfony 2 goals

   Learn from our mistakes

Take user feedback into account
But then, I realized that
     Starting from scratch is a lot of work!

We loose all the debugging we have already done

 I didn’t want symfony 2 to be the next Perl 6 ;)
But I learned a lot with this new code

        I used it to test new ideas…
…that were later incorporated into symfony 1


              Event dispatcher
              Form framework
symfony 2
•  symfony 2 will be an evolution of symfony 1, not a
   revolution
•  A lot of changes in symfony 1.1 and 1.2 are done
   to support symfony 2
•  symfony 1.1 decoupling was to support symfony 2

•  There will be a symfony 1.3
symfony 2
•  Based on the same symfony platform




•  New libraries / sub-frameworks
  –  Dependency injection container
  –  Real template layer
  –  New controller layer
Dependency Injection
The world of programming
  is evolving fast… very fast

But the ultimate goal of these
      changes is the same
Build better tools
    to avoid reinventing
         the wheel
Build on existing code / work / librairies
Specialize for your specific needs
That’s why Open-Source wins
Better tools are possible because
we base our work on existing work

  We learn from other projects

    We can adopt their ideas

    We can make them better

 This is the process of evolution
symfony
•  PHP
  –  Mojavi : Controller
  –  Propel : ORM
  –  Doctrine : ORM
•  Ruby
  –  Rails : Helpers, routing
•  Java
  –  Spring : Dependency injection container
•  Python
  –  Django : request / response paradigm, controller
     philosophy
•  … and much more
Read code to learn
This is why Open-Source wins
Open-Source drives

     Creativity
    Innovation
Create a website
•  Assembly code
•  C code
•  Operating system
•  MySQL, Apache
•  PHP
•  …
•  Your code
Create a website
•  You really need a framework nowadays
•  But you want it to be flexible and customizable
•  The framework needs to find the sweet spot
  –  Features / Complexity
  –  Easyness / Extensibility
•  Each version of symfony tries to be closer to this
    sweet spot
•  I hope symfony 2 will be the one
•  A framework is all about reusability
Reusability

Customization / Extension
     Configuration

Documentation / Support
Dependency Injection
A symfony example
In symfony, you manipulate a User object
  –  To manage the user culture
  –  To authenticate the user
  –  To manage her credentials
  –  …

  –  setCulture(), getCulture()
  –  isAuthenticated()
  –  addCredential()
  –  …
The User information need to be persisted
        between HTTP requests

 We use the PHP session for the Storage
<?php

class User
{
  protected $storage;

    function __construct()
    {
      $this->storage = new SessionStorage();
    }
}

$user = new User();
I want to change the session cookie name
<?php

class User
{
  protected $storage;                      Add a global
                                          Configuration?
    function __construct()
    {
      $this->storage = new SessionStorage();
    }
}



sfConfig::set('storage_session_name', 'SESSION_ID');

$user = new User();
<?php
                                        Configure via
class User                                 User?
{
  protected $storage;

    function __construct($sessionName)
    {
      $this->storage = new SessionStorage($sessionName);
    }
}

$user = new User('SESSION_ID');
<?php
                                        Configure with
class User                                 an array
{
  protected $storage;

    function __construct($options)
    {
      $this->storage = new SessionStorage($options);
    }
}

$user = new User(
   array('session_name' => 'SESSION_ID')
);
I want to change the session storage engine

                Filesystem
                  MySQL
                  SQLite
                     …
<?php

class User                              Use a global
{                                      context object?
  protected $storage;

    function __construct()
    {
      $this->storage = Context::get('session_storage');
    }
}

$user = new User();
The User now depends on the Context
Instead of harcoding
  the Storage dependency
      in the User class

Inject the storage dependency
       in the User object
<?php

class User
{
  protected $storage;

    function __construct(StorageInterface $storage)
    {
      $this->storage = $storage;
    }
}

$storage = new Storage(
   array('session_name' => 'SESSION_ID')
);
$user = new User($storage);
Use built-in Storage strategies
     Configuration becomes natural
    Wrap third-party classes (Adapter)
    Mock the Storage object (for test)


Easy without changing the User class
That’s Dependency Injection

      Nothing more
« Dependency Injection is
    where components are given
     their dependencies through
    their constructors, methods,
       or directly into fields. »
http://www.picocontainer.org/injection.html
Configurable
 Extensible
 Decoupled
 Reusable
symfony platform
<?php

$dispatcher = new sfEventDispatcher();

$request = new sfWebRequest($dispatcher);
$response = new sfWebResponse($dispatcher);

$storage = new sfSessionStorage(
   array('session_name' => 'symfony')
);
$user = new sfUser($dispatcher, $storage);

$cache = new sfFileCache(
   array('dir' => dirname(__FILE__).'/cache')
);
$routing = new sfPatternRouting($dispatcher, $cache);
<?php

class Application
{
  function __construct()
  {
    $this->dispatcher = new sfEventDispatcher();
    $this->request = new sfWebRequest($this->dispatcher);
    $this->response = new sfWebResponse($this->dispatcher);

    $this->storage = new sfSessionStorage(
       array('session_name' => 'symfony')
    );
    $this->user = new sfUser($this->disptacher, $this->storage);

    $this->cache = new sfFileCache(
       array('dir' => dirname(__FILE__).'/cache')
    );
    $this->routing = new sfPatternRouting($this->disptacher,
 $this->cache);
  }
}

$application = new Application();
Back to square 1
We need a Container
    Describe objects
  and their relationships

     Configure them

     Instantiate them
Dependency Injection
    in symfony 2

 sfServiceContainer
<?php

$container = new sfServiceContainer(array(
  'dispatcher' => new sfServiceDefinition('sfEventDispatcher'),
));

$dispatcher = $container->getService('dispatcher');




                                         It is a just a
                                       Service Locator?
<?php

$dispatcherDef = new sfServiceDefinition('sfEventDispatcher');

$requestDef = new sfServiceDefinition('sfWebRequest',
   array(new sfServiceReference('dispatcher'))
);

$container = new sfServiceContainer(array(
  'dispatcher' => $dispatcherDef,
  'request'    => $requestDef,
));

$request = $container->getService('request');
$request = $container->getService('request');




           Get the configuration for the request service

 The sfWebRequest constructor must be given a dispatcher service

           Get the dispatcher object from the container

Create a sfWebRequest object by passing the constructor arguments
$request = $container->getService('request');



          is roughly equivalent to

    $dispatcher = new sfEventDispatcher();
  $request = new sfWebRequest($dispatcher);
<?php

$container = new sfServiceContainer(array(
  'dispatcher' => new sfServiceDefinition('sfEventDispatcher’),
  'request'    => new sfServiceDefinition('sfWebRequest',          PHP
                     array(new sfServiceReference('dispatcher'))




                                    =
                  ),
));



<service id="dispatcher" class="sfEventDispatcher" />

<service id="request" class="sfWebRequest">
  <constructor_arg type="service" id="dispatcher" />
                                                                   XML


                                    =
</service>


dispatcher:
  class: sfEventDispatcher

request:
  class: sfWebRequest                                              YAML
  constructor_args: [@dispatcher]
<?php

$container = new sfServiceContainer(array(
  'dispatcher' => new sfServiceDefinition('sfEventDispatcher'),
));



<parameter key="dispatcher.class">sfEventDispatcher</parameter>

<service id="dispatcher" class="%dispatcher.class%" />



parameters:
  dispatcher.class: sfEventDispatcher

services:
  dispatcher:
    class: %dispatcher.class%
<parameter key="core.with_logging">true</parameter>
<parameter key="core.charset">UTF-8</parameter>
<parameter key="response.class">sfWebResponse</parameter>

<service id="response" class="%response.class%" global="false">
  <constructor_arg type="service" id="event_dispatcher" />
  <constructor_arg type="collection">
    <arg key="logging">%core.with_logging%</arg>
    <arg key="charset">%core.charset%</arg>
  </constructor_arg>
</service>

parameters:
  core.with_logging: true
  core.charset:      UTF-8
  response.class:    sfWebResponse

services:
  response:
    class: %response.class%
    global: false
    constructor_args:
      - @event_dispatcher
      - [logging: %core.with_logging%, charset: %core.charset%]
// YML

$loader = new sfServiceLoaderYml(array('/paths/to/config/dir'));

list($definitions, $parameters) = $loader->load('/paths/to/yml');


// XML

$loader = new sfServiceLoaderXml(array('/paths/to/config/dir'));

list($definitions, $parameters) = $loader->load('/paths/to/xml');



// Create the container

$container = new sfServiceContainer($definitions, $parameters);
// Access parameters

$withLogging = $container['core.with_logging'];



// Access services

$response = $container->response;
<import resource="core.xml" />

<parameter key="dispatcher.class">sfEventDispatcher</parameter>

<service id="dispatcher" class="%disaptcher.class%" />

<import resource="app_dev.xml" />




imports_1: core.xml

parameters:
  dispatcher.class: sfEventDispatcher

services:
  dispatcher:
    class: %dispatcher.class%

imports_2: app_dev.xml
sfServiceContainer replaces several symfony 1.X concepts


  – sfContext

  – sfConfiguration

  – sfConfig

  – factories.yml

  – settings.yml / logging.yml / i18n.yml




Into one integrated system
services:
  response:
    class: %response.class%
    global: false



Each time you ask for a response object,
           you get a new one
services:
  user:
    class: %user.class%
    lazy: true



 By default, the services are created on
      startup except if lazy is true
Does it scale?


sfServiceContainerApplication
 caches the service definition
Questions?
Sensio S.A.
                     92-98, boulevard Victor Hugo
                         92 115 Clichy Cedex
                               FRANCE
                        Tél. : +33 1 40 99 80 80

                                Contact
                           Fabien Potencier
                     fabien.potencier@sensio.com




http://www.sensiolabs.com/                http://www.symfony-project.org/

More Related Content

What's hot

Dependency Injection IPC 201
Dependency Injection IPC 201Dependency Injection IPC 201
Dependency Injection IPC 201
Fabien Potencier
 
Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4
Fabien Potencier
 
Doctrine fixtures
Doctrine fixturesDoctrine fixtures
Doctrine fixtures
Bill Chang
 
Dependency injection-zendcon-2010
Dependency injection-zendcon-2010Dependency injection-zendcon-2010
Dependency injection-zendcon-2010
Fabien Potencier
 

What's hot (20)

Symfony components in the wild, PHPNW12
Symfony components in the wild, PHPNW12Symfony components in the wild, PHPNW12
Symfony components in the wild, PHPNW12
 
Decoupling with Design Patterns and Symfony2 DIC
Decoupling with Design Patterns and Symfony2 DICDecoupling with Design Patterns and Symfony2 DIC
Decoupling with Design Patterns and Symfony2 DIC
 
Symfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il clienteSymfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il cliente
 
Silex meets SOAP & REST
Silex meets SOAP & RESTSilex meets SOAP & REST
Silex meets SOAP & REST
 
Database Design Patterns
Database Design PatternsDatabase Design Patterns
Database Design Patterns
 
New Symfony Tips & Tricks (SymfonyCon Paris 2015)
New Symfony Tips & Tricks (SymfonyCon Paris 2015)New Symfony Tips & Tricks (SymfonyCon Paris 2015)
New Symfony Tips & Tricks (SymfonyCon Paris 2015)
 
Advanced symfony Techniques
Advanced symfony TechniquesAdvanced symfony Techniques
Advanced symfony Techniques
 
Symfony War Stories
Symfony War StoriesSymfony War Stories
Symfony War Stories
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistence
 
The Zen of Lithium
The Zen of LithiumThe Zen of Lithium
The Zen of Lithium
 
Rich Model And Layered Architecture in SF2 Application
Rich Model And Layered Architecture in SF2 ApplicationRich Model And Layered Architecture in SF2 Application
Rich Model And Layered Architecture in SF2 Application
 
Dependency Injection IPC 201
Dependency Injection IPC 201Dependency Injection IPC 201
Dependency Injection IPC 201
 
Decoupling the Ulabox.com monolith. From CRUD to DDD
Decoupling the Ulabox.com monolith. From CRUD to DDDDecoupling the Ulabox.com monolith. From CRUD to DDD
Decoupling the Ulabox.com monolith. From CRUD to DDD
 
Dependency Injection with PHP 5.3
Dependency Injection with PHP 5.3Dependency Injection with PHP 5.3
Dependency Injection with PHP 5.3
 
Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4
 
Dependency Injection in PHP
Dependency Injection in PHPDependency Injection in PHP
Dependency Injection in PHP
 
Symfony2 revealed
Symfony2 revealedSymfony2 revealed
Symfony2 revealed
 
Doctrine fixtures
Doctrine fixturesDoctrine fixtures
Doctrine fixtures
 
Dependency injection-zendcon-2010
Dependency injection-zendcon-2010Dependency injection-zendcon-2010
Dependency injection-zendcon-2010
 
Lithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate FrameworksLithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate Frameworks
 

Viewers also liked

Netbeans 6.7: a única IDE que você precisa!
Netbeans 6.7: a única IDE que você precisa!Netbeans 6.7: a única IDE que você precisa!
Netbeans 6.7: a única IDE que você precisa!
João Longo
 

Viewers also liked (8)

Web Security 101
Web Security 101Web Security 101
Web Security 101
 
Diigo ISTE
Diigo ISTEDiigo ISTE
Diigo ISTE
 
Netbeans 6.7: a única IDE que você precisa!
Netbeans 6.7: a única IDE que você precisa!Netbeans 6.7: a única IDE que você precisa!
Netbeans 6.7: a única IDE que você precisa!
 
Pocket guidebook elections in ukraine ukr crisimediacentre-052014
Pocket guidebook elections in ukraine ukr crisimediacentre-052014Pocket guidebook elections in ukraine ukr crisimediacentre-052014
Pocket guidebook elections in ukraine ukr crisimediacentre-052014
 
Nashvile Symfony Routes Presentation
Nashvile Symfony Routes PresentationNashvile Symfony Routes Presentation
Nashvile Symfony Routes Presentation
 
Nashville Php Symfony Presentation
Nashville Php Symfony PresentationNashville Php Symfony Presentation
Nashville Php Symfony Presentation
 
In The Future We All Use Symfony2
In The Future We All Use Symfony2In The Future We All Use Symfony2
In The Future We All Use Symfony2
 
Symfony2 your way
Symfony2   your waySymfony2   your way
Symfony2 your way
 

Similar to Beyond symfony 1.2 (Symfony Camp 2008)

Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Fabien Potencier
 
The symfony platform: Create your very own framework (PHP Quebec 2008)
The symfony platform: Create your very own framework (PHP Quebec 2008)The symfony platform: Create your very own framework (PHP Quebec 2008)
The symfony platform: Create your very own framework (PHP Quebec 2008)
Fabien Potencier
 
Dependency injection in Drupal 8
Dependency injection in Drupal 8Dependency injection in Drupal 8
Dependency injection in Drupal 8
Alexei Gorobets
 
Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friends
Michael Peacock
 
Dependency Injection with PHP and PHP 5.3
Dependency Injection with PHP and PHP 5.3Dependency Injection with PHP and PHP 5.3
Dependency Injection with PHP and PHP 5.3
Fabien Potencier
 
symfony on action - WebTech 207
symfony on action - WebTech 207symfony on action - WebTech 207
symfony on action - WebTech 207
patter
 
Symfony As A Platform (Symfony Camp 2007)
Symfony As A Platform (Symfony Camp 2007)Symfony As A Platform (Symfony Camp 2007)
Symfony As A Platform (Symfony Camp 2007)
Fabien Potencier
 
Dependency Injection - ConFoo 2010
Dependency Injection - ConFoo 2010Dependency Injection - ConFoo 2010
Dependency Injection - ConFoo 2010
Fabien Potencier
 
Dependency injection - phpday 2010
Dependency injection - phpday 2010Dependency injection - phpday 2010
Dependency injection - phpday 2010
Fabien Potencier
 
Symfony 2 (PHP Quebec 2009)
Symfony 2 (PHP Quebec 2009)Symfony 2 (PHP Quebec 2009)
Symfony 2 (PHP Quebec 2009)
Fabien Potencier
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
arcware
 
EPHPC Webinar Slides: Unit Testing by Arthur Purnama
EPHPC Webinar Slides: Unit Testing by Arthur PurnamaEPHPC Webinar Slides: Unit Testing by Arthur Purnama
EPHPC Webinar Slides: Unit Testing by Arthur Purnama
Enterprise PHP Center
 

Similar to Beyond symfony 1.2 (Symfony Camp 2008) (20)

Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
 
The symfony platform: Create your very own framework (PHP Quebec 2008)
The symfony platform: Create your very own framework (PHP Quebec 2008)The symfony platform: Create your very own framework (PHP Quebec 2008)
The symfony platform: Create your very own framework (PHP Quebec 2008)
 
Dependency injection in Drupal 8
Dependency injection in Drupal 8Dependency injection in Drupal 8
Dependency injection in Drupal 8
 
Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friends
 
Dependency Injection with PHP and PHP 5.3
Dependency Injection with PHP and PHP 5.3Dependency Injection with PHP and PHP 5.3
Dependency Injection with PHP and PHP 5.3
 
symfony on action - WebTech 207
symfony on action - WebTech 207symfony on action - WebTech 207
symfony on action - WebTech 207
 
Symfony As A Platform (Symfony Camp 2007)
Symfony As A Platform (Symfony Camp 2007)Symfony As A Platform (Symfony Camp 2007)
Symfony As A Platform (Symfony Camp 2007)
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
Dependency Injection - ConFoo 2010
Dependency Injection - ConFoo 2010Dependency Injection - ConFoo 2010
Dependency Injection - ConFoo 2010
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
Dependency injection - phpday 2010
Dependency injection - phpday 2010Dependency injection - phpday 2010
Dependency injection - phpday 2010
 
Symfony 2 (PHP Quebec 2009)
Symfony 2 (PHP Quebec 2009)Symfony 2 (PHP Quebec 2009)
Symfony 2 (PHP Quebec 2009)
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
Osiąganie mądrej architektury z Symfony2
Osiąganie mądrej architektury z Symfony2 Osiąganie mądrej architektury z Symfony2
Osiąganie mądrej architektury z Symfony2
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
 
Symfony internals [english]
Symfony internals [english]Symfony internals [english]
Symfony internals [english]
 
PHP: 4 Design Patterns to Make Better Code
PHP: 4 Design Patterns to Make Better CodePHP: 4 Design Patterns to Make Better Code
PHP: 4 Design Patterns to Make Better Code
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the Trenches
 
EPHPC Webinar Slides: Unit Testing by Arthur Purnama
EPHPC Webinar Slides: Unit Testing by Arthur PurnamaEPHPC Webinar Slides: Unit Testing by Arthur Purnama
EPHPC Webinar Slides: Unit Testing by Arthur Purnama
 
Yii Introduction
Yii IntroductionYii Introduction
Yii Introduction
 

More from Fabien Potencier

Design patterns revisited with PHP 5.3
Design patterns revisited with PHP 5.3Design patterns revisited with PHP 5.3
Design patterns revisited with PHP 5.3
Fabien Potencier
 
The state of Symfony2 - SymfonyDay 2010
The state of Symfony2 - SymfonyDay 2010The state of Symfony2 - SymfonyDay 2010
The state of Symfony2 - SymfonyDay 2010
Fabien Potencier
 
Caching on the Edge with Symfony2
Caching on the Edge with Symfony2Caching on the Edge with Symfony2
Caching on the Edge with Symfony2
Fabien Potencier
 
Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2
Fabien Potencier
 
News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 World
Fabien Potencier
 
Symfony Components 2.0 on PHP 5.3
Symfony Components 2.0 on PHP 5.3Symfony Components 2.0 on PHP 5.3
Symfony Components 2.0 on PHP 5.3
Fabien Potencier
 
Symfony2 San Francisco Meetup 2009
Symfony2 San Francisco Meetup 2009Symfony2 San Francisco Meetup 2009
Symfony2 San Francisco Meetup 2009
Fabien Potencier
 
Symfony And Zend Framework Together 2009
Symfony And Zend Framework Together 2009Symfony And Zend Framework Together 2009
Symfony And Zend Framework Together 2009
Fabien Potencier
 
Twig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHPTwig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHP
Fabien Potencier
 

More from Fabien Potencier (20)

Varnish
VarnishVarnish
Varnish
 
Look beyond PHP
Look beyond PHPLook beyond PHP
Look beyond PHP
 
Caching on the Edge
Caching on the EdgeCaching on the Edge
Caching on the Edge
 
Design patterns revisited with PHP 5.3
Design patterns revisited with PHP 5.3Design patterns revisited with PHP 5.3
Design patterns revisited with PHP 5.3
 
The state of Symfony2 - SymfonyDay 2010
The state of Symfony2 - SymfonyDay 2010The state of Symfony2 - SymfonyDay 2010
The state of Symfony2 - SymfonyDay 2010
 
PhpBB meets Symfony2
PhpBB meets Symfony2PhpBB meets Symfony2
PhpBB meets Symfony2
 
Symfony2 - WebExpo 2010
Symfony2 - WebExpo 2010Symfony2 - WebExpo 2010
Symfony2 - WebExpo 2010
 
Symfony2 - WebExpo 2010
Symfony2 - WebExpo 2010Symfony2 - WebExpo 2010
Symfony2 - WebExpo 2010
 
Symfony2 - OSIDays 2010
Symfony2 - OSIDays 2010Symfony2 - OSIDays 2010
Symfony2 - OSIDays 2010
 
Caching on the Edge with Symfony2
Caching on the Edge with Symfony2Caching on the Edge with Symfony2
Caching on the Edge with Symfony2
 
Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2
 
News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 World
 
Symfony Components
Symfony ComponentsSymfony Components
Symfony Components
 
PHP 5.3 in practice
PHP 5.3 in practicePHP 5.3 in practice
PHP 5.3 in practice
 
Symfony Components 2.0 on PHP 5.3
Symfony Components 2.0 on PHP 5.3Symfony Components 2.0 on PHP 5.3
Symfony Components 2.0 on PHP 5.3
 
Playing With PHP 5.3
Playing With PHP 5.3Playing With PHP 5.3
Playing With PHP 5.3
 
Symfony 2.0 on PHP 5.3
Symfony 2.0 on PHP 5.3Symfony 2.0 on PHP 5.3
Symfony 2.0 on PHP 5.3
 
Symfony2 San Francisco Meetup 2009
Symfony2 San Francisco Meetup 2009Symfony2 San Francisco Meetup 2009
Symfony2 San Francisco Meetup 2009
 
Symfony And Zend Framework Together 2009
Symfony And Zend Framework Together 2009Symfony And Zend Framework Together 2009
Symfony And Zend Framework Together 2009
 
Twig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHPTwig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHP
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 

Beyond symfony 1.2 (Symfony Camp 2008)

  • 1. Beyond symfony 1.2 Fabien Potencier
  • 2. Work on symfony 2 started 2 years ago with a brand new code base
  • 3. symfony 2 goals Learn from our mistakes Take user feedback into account
  • 4. But then, I realized that Starting from scratch is a lot of work! We loose all the debugging we have already done I didn’t want symfony 2 to be the next Perl 6 ;)
  • 5. But I learned a lot with this new code I used it to test new ideas… …that were later incorporated into symfony 1 Event dispatcher Form framework
  • 6. symfony 2 •  symfony 2 will be an evolution of symfony 1, not a revolution •  A lot of changes in symfony 1.1 and 1.2 are done to support symfony 2 •  symfony 1.1 decoupling was to support symfony 2 •  There will be a symfony 1.3
  • 7. symfony 2 •  Based on the same symfony platform •  New libraries / sub-frameworks –  Dependency injection container –  Real template layer –  New controller layer
  • 9. The world of programming is evolving fast… very fast But the ultimate goal of these changes is the same
  • 10. Build better tools to avoid reinventing the wheel Build on existing code / work / librairies Specialize for your specific needs That’s why Open-Source wins
  • 11. Better tools are possible because we base our work on existing work We learn from other projects We can adopt their ideas We can make them better This is the process of evolution
  • 12. symfony •  PHP –  Mojavi : Controller –  Propel : ORM –  Doctrine : ORM •  Ruby –  Rails : Helpers, routing •  Java –  Spring : Dependency injection container •  Python –  Django : request / response paradigm, controller philosophy •  … and much more
  • 13. Read code to learn
  • 14. This is why Open-Source wins
  • 15. Open-Source drives Creativity Innovation
  • 16. Create a website •  Assembly code •  C code •  Operating system •  MySQL, Apache •  PHP •  … •  Your code
  • 17. Create a website •  You really need a framework nowadays •  But you want it to be flexible and customizable •  The framework needs to find the sweet spot –  Features / Complexity –  Easyness / Extensibility •  Each version of symfony tries to be closer to this sweet spot •  I hope symfony 2 will be the one •  A framework is all about reusability
  • 18. Reusability Customization / Extension Configuration Documentation / Support
  • 21. In symfony, you manipulate a User object –  To manage the user culture –  To authenticate the user –  To manage her credentials –  … –  setCulture(), getCulture() –  isAuthenticated() –  addCredential() –  …
  • 22. The User information need to be persisted between HTTP requests We use the PHP session for the Storage
  • 23. <?php class User { protected $storage; function __construct() { $this->storage = new SessionStorage(); } } $user = new User();
  • 24. I want to change the session cookie name
  • 25. <?php class User { protected $storage; Add a global Configuration? function __construct() { $this->storage = new SessionStorage(); } } sfConfig::set('storage_session_name', 'SESSION_ID'); $user = new User();
  • 26. <?php Configure via class User User? { protected $storage; function __construct($sessionName) { $this->storage = new SessionStorage($sessionName); } } $user = new User('SESSION_ID');
  • 27. <?php Configure with class User an array { protected $storage; function __construct($options) { $this->storage = new SessionStorage($options); } } $user = new User( array('session_name' => 'SESSION_ID') );
  • 28. I want to change the session storage engine Filesystem MySQL SQLite …
  • 29. <?php class User Use a global { context object? protected $storage; function __construct() { $this->storage = Context::get('session_storage'); } } $user = new User();
  • 30. The User now depends on the Context
  • 31. Instead of harcoding the Storage dependency in the User class Inject the storage dependency in the User object
  • 32. <?php class User { protected $storage; function __construct(StorageInterface $storage) { $this->storage = $storage; } } $storage = new Storage( array('session_name' => 'SESSION_ID') ); $user = new User($storage);
  • 33. Use built-in Storage strategies Configuration becomes natural Wrap third-party classes (Adapter) Mock the Storage object (for test) Easy without changing the User class
  • 35. « Dependency Injection is where components are given their dependencies through their constructors, methods, or directly into fields. » http://www.picocontainer.org/injection.html
  • 38. <?php $dispatcher = new sfEventDispatcher(); $request = new sfWebRequest($dispatcher); $response = new sfWebResponse($dispatcher); $storage = new sfSessionStorage( array('session_name' => 'symfony') ); $user = new sfUser($dispatcher, $storage); $cache = new sfFileCache( array('dir' => dirname(__FILE__).'/cache') ); $routing = new sfPatternRouting($dispatcher, $cache);
  • 39. <?php class Application { function __construct() { $this->dispatcher = new sfEventDispatcher(); $this->request = new sfWebRequest($this->dispatcher); $this->response = new sfWebResponse($this->dispatcher); $this->storage = new sfSessionStorage( array('session_name' => 'symfony') ); $this->user = new sfUser($this->disptacher, $this->storage); $this->cache = new sfFileCache( array('dir' => dirname(__FILE__).'/cache') ); $this->routing = new sfPatternRouting($this->disptacher, $this->cache); } } $application = new Application();
  • 41. We need a Container Describe objects and their relationships Configure them Instantiate them
  • 42. Dependency Injection in symfony 2 sfServiceContainer
  • 43. <?php $container = new sfServiceContainer(array( 'dispatcher' => new sfServiceDefinition('sfEventDispatcher'), )); $dispatcher = $container->getService('dispatcher'); It is a just a Service Locator?
  • 44. <?php $dispatcherDef = new sfServiceDefinition('sfEventDispatcher'); $requestDef = new sfServiceDefinition('sfWebRequest', array(new sfServiceReference('dispatcher')) ); $container = new sfServiceContainer(array( 'dispatcher' => $dispatcherDef, 'request' => $requestDef, )); $request = $container->getService('request');
  • 45. $request = $container->getService('request'); Get the configuration for the request service The sfWebRequest constructor must be given a dispatcher service Get the dispatcher object from the container Create a sfWebRequest object by passing the constructor arguments
  • 46. $request = $container->getService('request'); is roughly equivalent to $dispatcher = new sfEventDispatcher(); $request = new sfWebRequest($dispatcher);
  • 47. <?php $container = new sfServiceContainer(array( 'dispatcher' => new sfServiceDefinition('sfEventDispatcher’), 'request' => new sfServiceDefinition('sfWebRequest', PHP array(new sfServiceReference('dispatcher')) = ), )); <service id="dispatcher" class="sfEventDispatcher" /> <service id="request" class="sfWebRequest"> <constructor_arg type="service" id="dispatcher" /> XML = </service> dispatcher: class: sfEventDispatcher request: class: sfWebRequest YAML constructor_args: [@dispatcher]
  • 48. <?php $container = new sfServiceContainer(array( 'dispatcher' => new sfServiceDefinition('sfEventDispatcher'), )); <parameter key="dispatcher.class">sfEventDispatcher</parameter> <service id="dispatcher" class="%dispatcher.class%" /> parameters: dispatcher.class: sfEventDispatcher services: dispatcher: class: %dispatcher.class%
  • 49. <parameter key="core.with_logging">true</parameter> <parameter key="core.charset">UTF-8</parameter> <parameter key="response.class">sfWebResponse</parameter> <service id="response" class="%response.class%" global="false"> <constructor_arg type="service" id="event_dispatcher" /> <constructor_arg type="collection"> <arg key="logging">%core.with_logging%</arg> <arg key="charset">%core.charset%</arg> </constructor_arg> </service> parameters: core.with_logging: true core.charset: UTF-8 response.class: sfWebResponse services: response: class: %response.class% global: false constructor_args: - @event_dispatcher - [logging: %core.with_logging%, charset: %core.charset%]
  • 50. // YML $loader = new sfServiceLoaderYml(array('/paths/to/config/dir')); list($definitions, $parameters) = $loader->load('/paths/to/yml'); // XML $loader = new sfServiceLoaderXml(array('/paths/to/config/dir')); list($definitions, $parameters) = $loader->load('/paths/to/xml'); // Create the container $container = new sfServiceContainer($definitions, $parameters);
  • 51. // Access parameters $withLogging = $container['core.with_logging']; // Access services $response = $container->response;
  • 52. <import resource="core.xml" /> <parameter key="dispatcher.class">sfEventDispatcher</parameter> <service id="dispatcher" class="%disaptcher.class%" /> <import resource="app_dev.xml" /> imports_1: core.xml parameters: dispatcher.class: sfEventDispatcher services: dispatcher: class: %dispatcher.class% imports_2: app_dev.xml
  • 53. sfServiceContainer replaces several symfony 1.X concepts – sfContext – sfConfiguration – sfConfig – factories.yml – settings.yml / logging.yml / i18n.yml Into one integrated system
  • 54. services: response: class: %response.class% global: false Each time you ask for a response object, you get a new one
  • 55. services: user: class: %user.class% lazy: true By default, the services are created on startup except if lazy is true
  • 56. Does it scale? sfServiceContainerApplication caches the service definition
  • 58. Sensio S.A. 92-98, boulevard Victor Hugo 92 115 Clichy Cedex FRANCE Tél. : +33 1 40 99 80 80 Contact Fabien Potencier fabien.potencier@sensio.com http://www.sensiolabs.com/ http://www.symfony-project.org/