SlideShare a Scribd company logo
1 of 66
Download to read offline
Using symfony and Zend
Framework together

Fabien Potencier
Fabien Potencier
•  Serial entrepreneur and developer by passion
•  Founder of Sensio
   –  Web Agency (France and USA)
   –  Since 1998
   –  70 people
   –  Open-Source Specialists
   –  Big corporate customers
   –  Consulting, training, development, web design, … and more

   –  Sponsor of a lot of Open-Source projects
      like symfony and Doctrine
Fabien Potencier
•  Creator and lead developer of symfony…
•  and creator and lead developer of some more:
   –  symfony components
   –  Swift Mailer : Powerful component based mailing library for PHP
   –  Twig : Fexible, fast, and secure template language for PHP
   –  Pirum : Simple PEAR Channel Server Manager
   –  Sismo : PHP continuous integration server
   –  Lime : Easy to use unit testing library for PHP
   –  Twitto : A web framework in a tweet
   –  Twittee : A Dependency Injection Container in a tweet
   –  Pimple : A small PHP 5.3 dependency injection container
Fabien Potencier

•  Read my technical blog: http://fabien.potencier.org/

•  Follow me on Twitter: @fabpot

•  Fork my code on Github: http://github.com/fabpot/
symfony
•  Full-stack framework (MVC architecture)
•  symfony provides the infrastructure/tools needed for 95% of the web
   projects
•  Open-Source (MIT License) since 2005
•  Based on
   –  11 years of Sensio experience building websites
   –  Existing Open-Source projects
Documentation
•  Books in several languages                                                                                                                                                                                                                                                                                                      2ND EDITION




                                                                                                                                                                                                                                                                               2ND EDITION




                                                                                                                                                                                                                                                                                                                                                           The symfony 1.2 Reference Guide
•  All the official documentation is released




                                                                                                                                                                                                                                                                            Practical symfony
                                                                                                                                                                                                                                                                                                Practical                                                                                    The symfony 1.2
   under an Open-Source license, and also                                                                                                                                                                                                                                                       symfony                                                                                      Reference Guide
                                                                                                                                                                                                                                                                                                Create professional web applications

   available as printed books                                                                                                                                                                                                                                                                   with PHP and symfony 1.2




                                                                                                                                                                                                                                                                            Doctrine
                                                                                                                                                                                                                                                                            symfony 1.2




                                                                                                                                                                                                                                                                                                                                                           Fabien Potencier
                                                                                                                                                                                                                                                                                                                                            !"#$%&'(




                                                                                                                                                                                                                                                                               F. Potencier
                                                                                                                                                                                                                                              *+,-)"%&.'."(&!"#.#$.#
                                                                                                                                                                                                                                                                  "#### /                                                   *+,-)"%&.'."(&!"#.#$.!
                                                                                                                                                                                                                                                                                                                                                "#### /




                                                                                                                                                                                                                                                                                                                                        Fabien Potencier
                                                                                                                                                                                                                                                    " %&'"(& !"##$#
                                                                                                                                                                                                                                                                      )
                                                                                                                                                                                                                                                                                                                                                )
                                                                                                                                                                                                                                                                                                                                                                                                        Fabien Potencier
                                                                                                                                                                                                                                                                                                                              " %&'"(& !"##$!




                                                                                  9:;
                                                                                                                                                        les Cahiers
                                             9:;




                                                                                                                                                      du
                                                                                                                                                                Programmeur
                                                            !"!"#$%&"
                                            !"!"#$%&"




                                                            '('#!"#$%&"$%&'()*+,-./)*+                                                                                                 Mieux développer en PHP
                                                            0&123+,45678
                                                                                                                                                                                       avec Symfony et Doctrine
                                           Doctrine
                                           symfony 1.2




                                                                                                                                                 Fabien Potencier
                                                                                                                                                Avec la contribution

                                                                                    !"#$%&'(                                                    de Hugo Hamon
                                             F. Potencier




                                                                                                                                                          Le tutoriel
                                                                                                                                                                       i
             *+,-)"&'.(."$'!"#.$$.%
                                 "#### /                                                                                                                Jobeet enrich
                                                                                                                                                         et mis à jour
                                                                                                                                                                     eur
                                                                                                                                                        par le créat
                                                                                Fabien Potencier                                                                      !
               " &'("$' !"#$$%
                                 )
                                                                                                                                                          de Symfony
                                                                                                              The symfony 1.2 symfony!"#$%&
                                                                                                                              Reference Guide




                                                                                              symfony
                                                                                      The symfony 1.2
                                                                                             !"#$%&
                                                                                                                                                                                                                                        9:;
                                                                                                                                                                                                    9:;




                                                                                      Reference Guide
                                                                                                                                                                                                                   !"!"#$%&"
                                                                                                                                                                                                   !"!"#$%&"
                                                                                                              Fabien Potencier
                                                                                                                      Fabien Potencier




                                                                                                                                                                                                                   '('#!"#$%&"$%&'()*+,-./)*+
                                                                                                                                                                                                                   0&123+,45678
                                                                                                                                                                                                  Propel
                                                                                                                                                                                                  symfony 1.2




                                                                                )*+,("&%-'-"$%!"#-$!-%
                                                                                                                                                                                                    F. Potencier




                                                                                                    "#### .


                                                                                                                                                                                        Fabien Potencier
                                                                                                                                                                                                Fabien Potencier
                                                                                                    (
                                                                                  " &%'"$% !"#$!%




                                                                                                                                                              )*+,("&'-%-"$'!"#-$%-$
                                                                                                                                                                                  "#### .




                                                                                                                                                                                   (
                                                                                                                                                                                                                                       Fabien Potencier
                                                                                                                                                                 " &'%"$' !"#$%$
books.sensiolabs.com
Very active community
Mailing-lists / forum / IRC

More than 750 plugins with about 1-2 new plugins a day

700 000 visitors per month on symfony-project.org
Used to build the largest websites
•  Yahoo! Bookmarks       sf-to.org/bookmarks

•  Yahoo! Answers         sf-to.org/answers

•  delicious.com          sf-to.org/delicious

•  Dailymotion            sf-to.org/dailymotion
Dailymotion is the second
  most popular video sharing website
One of the top 30 websites in the world
   59 million unique users in July 2009
…and of course
many other smaller websites…
Roadmap
•  1.0 – January 2007
•  1.1 – June 2008
•  1.2 – November 2008
•  1.3 – November 2009
•  1.4 – Last 1.X version
   – same as 1.3 but with all deprecated features removed
•  Version 2.0 – First alpha early 2010
“Enterprise” version
Version 1.0 LTS: Maintained for 3 years
Version 1.1, 1.2, 1.3: Maintained for 1 year
Version 1.4 LTS: Maintained for 3 years
 Regular releases
   – Bug and security fixes, compatibility with newer PHP versions
   – No new feature (even small ones)
   – Upgrading is simple and safe
How many of you use
symfony?
T-shirt time
Zend Framework
•  Library of components with a MVC layer
•  New BSD license
•  Open-Source since 2007




How many of you use Zend Framework?
How many of you use
Zend Framework in
symfony projects?
How many of you use
symfony in
Zend Framework
projects?
Using symfony and Zend Framework together?
•  Both are plain PHP projects
•  Both use Subversion
•  Both use a PHP autoloader

•  So, using both in a project is, well, trivial
Using symfony and Zend Framework together?
•  Of course, people find it weird because both are MVC frameworks
•  But both have more than just the MVC part

•  Using them both in a project means
   –  Choosing one for the structure (controller, project organization, structure, and
      configuration)
   –  Choosing the components/libraries, based on your needs and their strengths
Using symfony and Zend Framework together?
•  I like this approach a lot because:
   –  I don't like to reinvent the wheel
   –  symfony itself started its life as a glue between existing components
   –  and symfony is still based on some third-party libraries
       •    Propel
       •    Doctrine
       •    Swift Mailer
       •    …
•  Of course, I like it even more
   if you use Zend Framework within a symfony project ;)
Zend Framework
in symfony projects
Install ZF into symfony
Put library/Zend/ files into lib/vendor/Zend
Setup autoloading
// config/ProjectConfiguration.class.php
class ProjectConfiguration extends sfProjectConfiguration
{
  public function setup()
  {
    $this->enablePlugins(array('sfDoctrinePlugin'));

    set_include_path(sfConfig::get('sf_lib_dir').'/
vendor'.PATH_SEPARATOR.get_include_path());
    require_once sfConfig::get('sf_lib_dir').'/vendor/Zend/
Loader/Autoloader.php';
    Zend_Loader_Autoloader::getInstance();
  }
}
What people use?
•  Pretty much everything except the MVC part:
   –  Zend_Search_Lucene
   –  Zend_OpenId
   –  Zend_Amf
   –  Zend_Feed
   –  Zend_Ldap
   –  Zend_Pdf
   –  Zend_Service
   –  Zend_Soap
Already well documented
                                                                                                                     2ND EDITION




                                                                    2ND EDITION
•  In the Jobeet tutorial




                                                                 Practical symfony
•  and Practical symfony book                                                        Practical
                                                                                     symfony
•  Chapter 17 (symfony 1.3) explains                                                 Create professional web applications
                                                                                     with PHP and symfony 1.2




                                                                 Doctrine
                                                                 symfony 1.2
   the configuration and how to use                                                                                          !"#$%&'(




                                                                    F. Potencier
  Zend_Search_Lucene
                                   *+,-)"%&.'."(&!"#.#$.#
                                                       "#### /




                                                         )                                                              Fabien Potencier
                                       " %&'"(& !"##$#




http://www.symfony-project.org/jobeet/1_3/Doctrine/en/17
symfony
in Zend Framework projects
But wait,
symfony is a monolithic
framework, right?
A bit of history
symfony 1.0 (January 2007) started as a glue between existing
  Open-Source libraries
A bit of history
symfony 1.1 (June 2008) was a big refactoring of the code base
   –  Decoupled but cohesive components: the symfony component like Forms,
     Routing, Cache, YAML, ORMs, …
       sfRequest   sfRouting     sfLogger   sfI18N    sfUser      sfResponse




  sfYAML   sfDatabase   sfForm    sfEventDispatcher   sfStorage     sfCache    sfOutputEscaper



               sfValidator     sfWidget                            sfCoreAutoload
                                                                                     platform
The symfony MVC framework is
based on a set of cohesive but
decoupled classes, the symfony
components
Symfony Components




•  Standalone components
•  Packaged individually
•  Dedicated website for each component (with code and documentation)
    –  http://components.symfony-project.org/
•  Dedicated Subversion and Git repository
    –  http://svn.symfony-project.com/components/
    –  http://github.com/fabpot
symfony components
•  Extracted from symfony
   –  Event dispatcher
   –  YAML
   –  Output Escaping
•  Written from scratch for Symfony 2
   –  Dependency Injection Container
   –  Request Handler
•  We won’t duplicate effort with ZF
Published Components
•  Already published components:
   –  YAML
   –  Dependency Injection
   –  Event Dispatcher
   –  Templating
•  Upcoming
   –  Request Handler
   –  Output Escaper
symfony components in a ZF project
•  symfony components can make your ZF application better
   –  More configurable: symfony YAML
   –  More flexible: symfony Event Dispatcher
   –  Faster: symfony Dependency Injection
   –  More secure: symfony Output Escaper
•  … and more fun of course
symfony components in a ZF project
•  The examples in this presentation are just to get you started faster

•  So, be creative with them. They open all kind of opportunities for your
   next Zend Framework project

•  And please, give me feedback, and tell me what you do with the
   symfony components
YAML
•  YAML is a human friendly data serialization standard for all
   programming languages (implementations exist in Perl, Ruby, Python,
   Java, …)
•  YAML is a great format for your configuration files
•  YAML files are as expressive as XML files and as readable as INI files
YAML
•  Used in symfony for all configuration files
•  Used in Doctrine for schema and fixtures
•  Can be used in Zend Framework for the same purposes
require_once '/path/to/sfYaml.php';

// Parse YAML
$config = sfYaml::load(<<<EOF
config:
   key: value
   foo: [foo, bar]
   bar: { foo: bar }
   foobar: { foo: [foo, bar] }
EOF
);

// Dump YAML
sfYaml::dump($config);
Event Dispatcher
•  Symfony Event Dispatcher is a PHP library that provides a lightweight
   implementation of the Observer design pattern
•  Based on the Cocoa Notification Center
•  Used in symfony to provide hooks and allow customizations of default
   behaviors                                     sfRequest    sfRouting     sfLogger   sfI18N    sfUser      sfResponse




   –  Inject the Web Debug Toolbar           sfYAML   sfDatabase   sfForm    sfEventDispatcher   sfStorage     sfCache    sfOutputEscaper




   –  Inject methods into core Objects                    sfValidator     sfWidget                            sfCoreAutoload
                                                                                                                                platform



   –  I18n management
   –  …
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
  public function run()
  {
    require_once '/path/to/sfEventDispatcher.php';
    $dispatcher = new sfEventDispatcher();

        $event = new sfEvent(null, 'bootstrap.prerun');
        $dispatcher->notify($event);

        parent::run();

        $event = new sfevent(null, 'bootstrap.postrun');
        $dispatcher->notify($event);
    }
}
// register a listener
$dispatcher->connect('event_name', array($this, 'callback'));

// notify an event
$event = new sfEvent($this, 'event_name', $parameters);
$dispatcher->notify($event);

$dispatcher->notifyUntil($event);
if (!$event->isProcessed())
{
  // ...
}

$dispatcher->filter($event, $value);
$value = $event->getReturnValue();
Dependency Injection Container
•  Symfony Dependency Injection is a PHP library that provides a
   lightweight Dependency Injection Container
•  … for classes that implement the Dependency Injection pattern
   –  This is the case for symfony classes
   –  This is mostly the case for Zend Framework classes
•  Based on the Java Spring framework
•  Configuration with PHP, YAML, or XML
« Dependency Injection is where components
 are given their dependencies through their
constructors, methods, or directly into fields. »


http://www.picocontainer.org/injection.html
DI Hello World example
class Message
{
  public function __construct(OutputInterface $output, array $options)
  {
    $this->output = $output;
    $this->options = array_merge(array('with_newline' => false), $options);
  }

    public function say($msg)
    {
       $this->output->render($msg.($this->options['with_newline'] ? "n" : ''));
    }
}
DI Hello World example
interface OutputInterface
{
  public function render($msg);
}

class Output implements OutputInterface
{
  public function render($msg)
  {
    echo $msg;
  }
}

class FancyOutput implements OutputInterface
{
  public function render($msg)
  {
    echo sprintf("033[33m%s033[0m", $msg);
  }
}
DI Hello World example



$output = new FancyOutput();
$message = new Message($output, array('with_newline' => true));
$message->say('Hello World');
A DI container facilitates
objects description and object relationships,
    configures and instantiates objects
DI Container Hello World example


$container = new sfServiceContainerBuilder();

$container->register('output', 'FancyOutput');

$container->
  register('message', 'Message')->
  setArguments(array(new sfServiceReference('output'), array('with_newline' => true)))
;

$container->message->say('Hello World!');
$message = $container->message;
          Get the configuration for the message service

    The Message constructor must be given an output service
            Get the output object from the container
  Create a Message object by passing the constructor arguments
$message = $container->message;


                    is roughly equivalent to

                  $output = new FancyOutput();
$message = new Message($output, array('with_newline' => true));!
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
  public function getContainer()
  {
    if (null === $this->_container)
    {
      $this->setContainer($this->_initContainer());
    }

        return $this->_container;
    }

    protected function _initContainer()
    {
      require_once '/path/to/sfServiceContainerAutoloader.php';
      sfServiceContainerAutoloader::register();
                     Example from Ben Eberlei (he rocks!): http://www.whitewashing.de/blog/articles/118

        $container = new sfServiceContainerBuilder();

        $loader = new sfServiceContainerLoaderFileXml($container);
        $loader->load(dirname(__FILE__).'/configs/resources.xml');

        return $container;
    }
}
<?xml version="1.0" ?>

<container xmlns="http://symfony-project.org/2.0/container">
  <parameters>
    <parameter key="mailer.username">foo</parameter>
    <parameter key="mailer.password">bar</parameter>
    <parameter key="mailer.class">Zend_Mail</parameter>
  </parameters>
  <services>
    <service id="mail.transport" class="Zend_Mail_Transport_Smtp" shared="false">
      <argument>smtp.gmail.com</argument>
      <argument type="collection">
        <argument key="auth">login</argument>
        <argument key="username">%mailer.username%</argument>
        <argument key="password">%mailer.password%</argument>
        <argument key="ssl">ssl</argument>
        <argument key="port">465</argument>
      </argument>
    </service>
    <service id="mailer" class="%mailer.class%">
      <call method="setDefaultTransport">
        <argument type="service" id="mail.transport" />
      </call>
    </service>
  </services>
</container>
parameters:
  mailer.username: foo
  mailer.password: bar
  mailer.class:    Zend_Mail

services:
  mail.transport:
    class:     Zend_Mail_Transport_Smtp
    arguments: [smtp.gmail.com, { auth: login, username:
%mailer.username%, password: %mailer.password%, ssl: ssl, port: 465 }]
    shared:    false
  mailer:
    class: %mailer.class%
    calls:
      - [setDefaultTransport, [@mail.transport]]
class GuestbookController extends Zend_Controller_Action
{
  public function indexAction()
  {
    $guestbook = new Default_Model_Guestbook();
    $this->view->entries = $guestbook->fetchAll();

        $container = $this->getInvokeArg('bootstrap')->getContainer();
        $mailer = $container->mailer;
    }
}
Dependency Injection Container
•  By default in ZF, new resources can be added to the container but cannot
   be lazy-loaded
   –  All resources used by Zend_Application are loaded on every request
•  By using symfony Service Container, the resources are lazy-loaded
   –  Instances and their dependencies are created the first time you get them
•  Interesting for resources like DB
Output Escaper
•    Automatic XSS Protection for your templates
•    Wraps your template variables
•    Works for strings, arrays, objects, …
•    Works for deep method calls
require_once '/path/to/sfOutputEscaperAutoloader.php';
sfOutputEscaperAutoloader::register();

class My_View extends Zend_View
{ • 
   public function __set($key, $val)
   {
     if ('_' === substr($key, 0, 1))
     {
       // throw an exception
     }

        $this->$key = sfOutputEscaper::escape(array($this, 'escape'), $val);
    }
}
<dl>
  <?php foreach ($this->entries as $entry): ?>
     <dt><?php echo $this->escape($entry->email) ?></dt>
     <dd><?php echo $this->escape($entry->comment) ?></dd>
  <?php endforeach ?>
</dl>

<dl>
  <?php foreach ($this->entries as $entry): ?>
     <dt><?php echo $entry->email ?></dt>
     <dd><?php echo $entry->comment ?></dd>
  <?php endforeach ?>
</dl>

<?php echo $entry->getRawValue()->comment ?>

<?php echo $entry->getComment(ESC_RAW) ?>
Conclusion
•  Use the right tool for the job
•  The PHP community have a lot of great projects
   –  Zend Framework
   –  Symfony
   –  eZ Components
   –  Doctrine
   –  Swift Mailer
   –  Twig
   –  … and much more
symfony-live.com
           with Matthew Weier O’Pheinney




    I will reveal the first alpha release of Symfony 2.0!
symfony-live.com
          with Matthew Weier O’Pheinney




   … with Matthew Weier O'Phinney as a special guest
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 at sensio.com




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

More Related Content

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.3Fabien Potencier
 
The state of Symfony2 - SymfonyDay 2010
The state of Symfony2 - SymfonyDay 2010The state of Symfony2 - SymfonyDay 2010
The state of Symfony2 - SymfonyDay 2010Fabien Potencier
 
Dependency injection - phpday 2010
Dependency injection - phpday 2010Dependency injection - phpday 2010
Dependency injection - phpday 2010Fabien Potencier
 
Dependency Injection IPC 201
Dependency Injection IPC 201Dependency Injection IPC 201
Dependency Injection IPC 201Fabien Potencier
 
Caching on the Edge with Symfony2
Caching on the Edge with Symfony2Caching on the Edge with Symfony2
Caching on the Edge with Symfony2Fabien Potencier
 
Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2Fabien Potencier
 
News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 WorldFabien Potencier
 
Dependency Injection - ConFoo 2010
Dependency Injection - ConFoo 2010Dependency Injection - ConFoo 2010
Dependency Injection - ConFoo 2010Fabien Potencier
 
Dependency Injection with PHP 5.3
Dependency Injection with PHP 5.3Dependency Injection with PHP 5.3
Dependency Injection with PHP 5.3Fabien Potencier
 
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.3Fabien 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.3Fabien Potencier
 

More from Fabien Potencier (20)

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
 
Dependency injection - phpday 2010
Dependency injection - phpday 2010Dependency injection - phpday 2010
Dependency injection - phpday 2010
 
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
 
Dependency Injection IPC 201
Dependency Injection IPC 201Dependency Injection IPC 201
Dependency Injection IPC 201
 
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
 
Dependency Injection - ConFoo 2010
Dependency Injection - ConFoo 2010Dependency Injection - ConFoo 2010
Dependency Injection - ConFoo 2010
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
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
 
Symfony2 revealed
Symfony2 revealedSymfony2 revealed
Symfony2 revealed
 
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 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 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
 

Recently uploaded

Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 

Symfony And Zend Framework Together 2009

  • 1. Using symfony and Zend Framework together Fabien Potencier
  • 2. Fabien Potencier •  Serial entrepreneur and developer by passion •  Founder of Sensio –  Web Agency (France and USA) –  Since 1998 –  70 people –  Open-Source Specialists –  Big corporate customers –  Consulting, training, development, web design, … and more –  Sponsor of a lot of Open-Source projects like symfony and Doctrine
  • 3. Fabien Potencier •  Creator and lead developer of symfony… •  and creator and lead developer of some more: –  symfony components –  Swift Mailer : Powerful component based mailing library for PHP –  Twig : Fexible, fast, and secure template language for PHP –  Pirum : Simple PEAR Channel Server Manager –  Sismo : PHP continuous integration server –  Lime : Easy to use unit testing library for PHP –  Twitto : A web framework in a tweet –  Twittee : A Dependency Injection Container in a tweet –  Pimple : A small PHP 5.3 dependency injection container
  • 4. Fabien Potencier •  Read my technical blog: http://fabien.potencier.org/ •  Follow me on Twitter: @fabpot •  Fork my code on Github: http://github.com/fabpot/
  • 5. symfony •  Full-stack framework (MVC architecture) •  symfony provides the infrastructure/tools needed for 95% of the web projects •  Open-Source (MIT License) since 2005 •  Based on –  11 years of Sensio experience building websites –  Existing Open-Source projects
  • 6. Documentation •  Books in several languages 2ND EDITION 2ND EDITION The symfony 1.2 Reference Guide •  All the official documentation is released Practical symfony Practical The symfony 1.2 under an Open-Source license, and also symfony Reference Guide Create professional web applications available as printed books with PHP and symfony 1.2 Doctrine symfony 1.2 Fabien Potencier !"#$%&'( F. Potencier *+,-)"%&.'."(&!"#.#$.# "#### / *+,-)"%&.'."(&!"#.#$.! "#### / Fabien Potencier " %&'"(& !"##$# ) ) Fabien Potencier " %&'"(& !"##$! 9:; les Cahiers 9:; du Programmeur !"!"#$%&" !"!"#$%&" '('#!"#$%&"$%&'()*+,-./)*+ Mieux développer en PHP 0&123+,45678 avec Symfony et Doctrine Doctrine symfony 1.2 Fabien Potencier Avec la contribution !"#$%&'( de Hugo Hamon F. Potencier Le tutoriel i *+,-)"&'.(."$'!"#.$$.% "#### / Jobeet enrich et mis à jour eur par le créat Fabien Potencier ! " &'("$' !"#$$% ) de Symfony The symfony 1.2 symfony!"#$%& Reference Guide symfony The symfony 1.2 !"#$%& 9:; 9:; Reference Guide !"!"#$%&" !"!"#$%&" Fabien Potencier Fabien Potencier '('#!"#$%&"$%&'()*+,-./)*+ 0&123+,45678 Propel symfony 1.2 )*+,("&%-'-"$%!"#-$!-% F. Potencier "#### . Fabien Potencier Fabien Potencier ( " &%'"$% !"#$!% )*+,("&'-%-"$'!"#-$%-$ "#### . ( Fabien Potencier " &'%"$' !"#$%$
  • 8. Very active community Mailing-lists / forum / IRC More than 750 plugins with about 1-2 new plugins a day 700 000 visitors per month on symfony-project.org
  • 9. Used to build the largest websites •  Yahoo! Bookmarks sf-to.org/bookmarks •  Yahoo! Answers sf-to.org/answers •  delicious.com sf-to.org/delicious •  Dailymotion sf-to.org/dailymotion
  • 10. Dailymotion is the second most popular video sharing website One of the top 30 websites in the world 59 million unique users in July 2009
  • 11. …and of course many other smaller websites…
  • 12. Roadmap •  1.0 – January 2007 •  1.1 – June 2008 •  1.2 – November 2008 •  1.3 – November 2009 •  1.4 – Last 1.X version – same as 1.3 but with all deprecated features removed •  Version 2.0 – First alpha early 2010
  • 13. “Enterprise” version Version 1.0 LTS: Maintained for 3 years Version 1.1, 1.2, 1.3: Maintained for 1 year Version 1.4 LTS: Maintained for 3 years Regular releases – Bug and security fixes, compatibility with newer PHP versions – No new feature (even small ones) – Upgrading is simple and safe
  • 14. How many of you use symfony?
  • 16. Zend Framework •  Library of components with a MVC layer •  New BSD license •  Open-Source since 2007 How many of you use Zend Framework?
  • 17.
  • 18. How many of you use Zend Framework in symfony projects?
  • 19. How many of you use symfony in Zend Framework projects?
  • 20. Using symfony and Zend Framework together? •  Both are plain PHP projects •  Both use Subversion •  Both use a PHP autoloader •  So, using both in a project is, well, trivial
  • 21. Using symfony and Zend Framework together? •  Of course, people find it weird because both are MVC frameworks •  But both have more than just the MVC part •  Using them both in a project means –  Choosing one for the structure (controller, project organization, structure, and configuration) –  Choosing the components/libraries, based on your needs and their strengths
  • 22. Using symfony and Zend Framework together? •  I like this approach a lot because: –  I don't like to reinvent the wheel –  symfony itself started its life as a glue between existing components –  and symfony is still based on some third-party libraries •  Propel •  Doctrine •  Swift Mailer •  … •  Of course, I like it even more if you use Zend Framework within a symfony project ;)
  • 24. Install ZF into symfony Put library/Zend/ files into lib/vendor/Zend
  • 25. Setup autoloading // config/ProjectConfiguration.class.php class ProjectConfiguration extends sfProjectConfiguration { public function setup() { $this->enablePlugins(array('sfDoctrinePlugin')); set_include_path(sfConfig::get('sf_lib_dir').'/ vendor'.PATH_SEPARATOR.get_include_path()); require_once sfConfig::get('sf_lib_dir').'/vendor/Zend/ Loader/Autoloader.php'; Zend_Loader_Autoloader::getInstance(); } }
  • 26.
  • 27. What people use? •  Pretty much everything except the MVC part: –  Zend_Search_Lucene –  Zend_OpenId –  Zend_Amf –  Zend_Feed –  Zend_Ldap –  Zend_Pdf –  Zend_Service –  Zend_Soap
  • 28. Already well documented 2ND EDITION 2ND EDITION •  In the Jobeet tutorial Practical symfony •  and Practical symfony book Practical symfony •  Chapter 17 (symfony 1.3) explains Create professional web applications with PHP and symfony 1.2 Doctrine symfony 1.2 the configuration and how to use !"#$%&'( F. Potencier Zend_Search_Lucene *+,-)"%&.'."(&!"#.#$.# "#### / ) Fabien Potencier " %&'"(& !"##$# http://www.symfony-project.org/jobeet/1_3/Doctrine/en/17
  • 30. But wait, symfony is a monolithic framework, right?
  • 31. A bit of history symfony 1.0 (January 2007) started as a glue between existing Open-Source libraries
  • 32. A bit of history symfony 1.1 (June 2008) was a big refactoring of the code base –  Decoupled but cohesive components: the symfony component like Forms, Routing, Cache, YAML, ORMs, … sfRequest sfRouting sfLogger sfI18N sfUser sfResponse sfYAML sfDatabase sfForm sfEventDispatcher sfStorage sfCache sfOutputEscaper sfValidator sfWidget sfCoreAutoload platform
  • 33. The symfony MVC framework is based on a set of cohesive but decoupled classes, the symfony components
  • 34. Symfony Components •  Standalone components •  Packaged individually •  Dedicated website for each component (with code and documentation) –  http://components.symfony-project.org/ •  Dedicated Subversion and Git repository –  http://svn.symfony-project.com/components/ –  http://github.com/fabpot
  • 35. symfony components •  Extracted from symfony –  Event dispatcher –  YAML –  Output Escaping •  Written from scratch for Symfony 2 –  Dependency Injection Container –  Request Handler •  We won’t duplicate effort with ZF
  • 36. Published Components •  Already published components: –  YAML –  Dependency Injection –  Event Dispatcher –  Templating •  Upcoming –  Request Handler –  Output Escaper
  • 37. symfony components in a ZF project •  symfony components can make your ZF application better –  More configurable: symfony YAML –  More flexible: symfony Event Dispatcher –  Faster: symfony Dependency Injection –  More secure: symfony Output Escaper •  … and more fun of course
  • 38. symfony components in a ZF project •  The examples in this presentation are just to get you started faster •  So, be creative with them. They open all kind of opportunities for your next Zend Framework project •  And please, give me feedback, and tell me what you do with the symfony components
  • 39. YAML •  YAML is a human friendly data serialization standard for all programming languages (implementations exist in Perl, Ruby, Python, Java, …) •  YAML is a great format for your configuration files •  YAML files are as expressive as XML files and as readable as INI files
  • 40. YAML •  Used in symfony for all configuration files •  Used in Doctrine for schema and fixtures •  Can be used in Zend Framework for the same purposes
  • 41. require_once '/path/to/sfYaml.php'; // Parse YAML $config = sfYaml::load(<<<EOF config: key: value foo: [foo, bar] bar: { foo: bar } foobar: { foo: [foo, bar] } EOF ); // Dump YAML sfYaml::dump($config);
  • 42. Event Dispatcher •  Symfony Event Dispatcher is a PHP library that provides a lightweight implementation of the Observer design pattern •  Based on the Cocoa Notification Center •  Used in symfony to provide hooks and allow customizations of default behaviors sfRequest sfRouting sfLogger sfI18N sfUser sfResponse –  Inject the Web Debug Toolbar sfYAML sfDatabase sfForm sfEventDispatcher sfStorage sfCache sfOutputEscaper –  Inject methods into core Objects sfValidator sfWidget sfCoreAutoload platform –  I18n management –  …
  • 43. class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { public function run() { require_once '/path/to/sfEventDispatcher.php'; $dispatcher = new sfEventDispatcher(); $event = new sfEvent(null, 'bootstrap.prerun'); $dispatcher->notify($event); parent::run(); $event = new sfevent(null, 'bootstrap.postrun'); $dispatcher->notify($event); } }
  • 44. // register a listener $dispatcher->connect('event_name', array($this, 'callback')); // notify an event $event = new sfEvent($this, 'event_name', $parameters); $dispatcher->notify($event); $dispatcher->notifyUntil($event); if (!$event->isProcessed()) { // ... } $dispatcher->filter($event, $value); $value = $event->getReturnValue();
  • 45. Dependency Injection Container •  Symfony Dependency Injection is a PHP library that provides a lightweight Dependency Injection Container •  … for classes that implement the Dependency Injection pattern –  This is the case for symfony classes –  This is mostly the case for Zend Framework classes •  Based on the Java Spring framework •  Configuration with PHP, YAML, or XML
  • 46. « Dependency Injection is where components are given their dependencies through their constructors, methods, or directly into fields. » http://www.picocontainer.org/injection.html
  • 47. DI Hello World example class Message { public function __construct(OutputInterface $output, array $options) { $this->output = $output; $this->options = array_merge(array('with_newline' => false), $options); } public function say($msg) { $this->output->render($msg.($this->options['with_newline'] ? "n" : '')); } }
  • 48. DI Hello World example interface OutputInterface { public function render($msg); } class Output implements OutputInterface { public function render($msg) { echo $msg; } } class FancyOutput implements OutputInterface { public function render($msg) { echo sprintf("033[33m%s033[0m", $msg); } }
  • 49. DI Hello World example $output = new FancyOutput(); $message = new Message($output, array('with_newline' => true)); $message->say('Hello World');
  • 50. A DI container facilitates objects description and object relationships, configures and instantiates objects
  • 51. DI Container Hello World example $container = new sfServiceContainerBuilder(); $container->register('output', 'FancyOutput'); $container-> register('message', 'Message')-> setArguments(array(new sfServiceReference('output'), array('with_newline' => true))) ; $container->message->say('Hello World!');
  • 52. $message = $container->message; Get the configuration for the message service The Message constructor must be given an output service Get the output object from the container Create a Message object by passing the constructor arguments
  • 53. $message = $container->message; is roughly equivalent to $output = new FancyOutput(); $message = new Message($output, array('with_newline' => true));!
  • 54. class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { public function getContainer() { if (null === $this->_container) { $this->setContainer($this->_initContainer()); } return $this->_container; } protected function _initContainer() { require_once '/path/to/sfServiceContainerAutoloader.php'; sfServiceContainerAutoloader::register(); Example from Ben Eberlei (he rocks!): http://www.whitewashing.de/blog/articles/118 $container = new sfServiceContainerBuilder(); $loader = new sfServiceContainerLoaderFileXml($container); $loader->load(dirname(__FILE__).'/configs/resources.xml'); return $container; } }
  • 55. <?xml version="1.0" ?> <container xmlns="http://symfony-project.org/2.0/container"> <parameters> <parameter key="mailer.username">foo</parameter> <parameter key="mailer.password">bar</parameter> <parameter key="mailer.class">Zend_Mail</parameter> </parameters> <services> <service id="mail.transport" class="Zend_Mail_Transport_Smtp" shared="false"> <argument>smtp.gmail.com</argument> <argument type="collection"> <argument key="auth">login</argument> <argument key="username">%mailer.username%</argument> <argument key="password">%mailer.password%</argument> <argument key="ssl">ssl</argument> <argument key="port">465</argument> </argument> </service> <service id="mailer" class="%mailer.class%"> <call method="setDefaultTransport"> <argument type="service" id="mail.transport" /> </call> </service> </services> </container>
  • 56. parameters: mailer.username: foo mailer.password: bar mailer.class: Zend_Mail services: mail.transport: class: Zend_Mail_Transport_Smtp arguments: [smtp.gmail.com, { auth: login, username: %mailer.username%, password: %mailer.password%, ssl: ssl, port: 465 }] shared: false mailer: class: %mailer.class% calls: - [setDefaultTransport, [@mail.transport]]
  • 57. class GuestbookController extends Zend_Controller_Action { public function indexAction() { $guestbook = new Default_Model_Guestbook(); $this->view->entries = $guestbook->fetchAll(); $container = $this->getInvokeArg('bootstrap')->getContainer(); $mailer = $container->mailer; } }
  • 58. Dependency Injection Container •  By default in ZF, new resources can be added to the container but cannot be lazy-loaded –  All resources used by Zend_Application are loaded on every request •  By using symfony Service Container, the resources are lazy-loaded –  Instances and their dependencies are created the first time you get them •  Interesting for resources like DB
  • 59. Output Escaper •  Automatic XSS Protection for your templates •  Wraps your template variables •  Works for strings, arrays, objects, … •  Works for deep method calls
  • 60. require_once '/path/to/sfOutputEscaperAutoloader.php'; sfOutputEscaperAutoloader::register(); class My_View extends Zend_View { •  public function __set($key, $val) { if ('_' === substr($key, 0, 1)) { // throw an exception } $this->$key = sfOutputEscaper::escape(array($this, 'escape'), $val); } }
  • 61. <dl> <?php foreach ($this->entries as $entry): ?> <dt><?php echo $this->escape($entry->email) ?></dt> <dd><?php echo $this->escape($entry->comment) ?></dd> <?php endforeach ?> </dl> <dl> <?php foreach ($this->entries as $entry): ?> <dt><?php echo $entry->email ?></dt> <dd><?php echo $entry->comment ?></dd> <?php endforeach ?> </dl> <?php echo $entry->getRawValue()->comment ?> <?php echo $entry->getComment(ESC_RAW) ?>
  • 62. Conclusion •  Use the right tool for the job •  The PHP community have a lot of great projects –  Zend Framework –  Symfony –  eZ Components –  Doctrine –  Swift Mailer –  Twig –  … and much more
  • 63. symfony-live.com with Matthew Weier O’Pheinney I will reveal the first alpha release of Symfony 2.0!
  • 64. symfony-live.com with Matthew Weier O’Pheinney … with Matthew Weier O'Phinney as a special guest
  • 66. 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 at sensio.com http://www.sensiolabs.com/ http://www.symfony-project.org/ http://fabien.potencier.org/