Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Zend Framework 2 and Symfony2: The Perfect Team (ZendCon)

Zend Framework 2 and Symfony2: The Perfect Team (ZendCon)

The next generation of frameworks is upon is, and now that they're more decoupled and component-based than ever before and use the same standard for naming and autoloading, there is no reason to stick to a single framework for your projects. During this session, we will go through several ways of combining Zend Framework 2 and Symfony2, so that you walk away being able to focus even more on on writing the complex custom logic your project needs, and don't have to worry about the rest.

Stefan Koopmanschap

October 25, 2012

More Decks by Stefan Koopmanschap

Other Decks in Programming


  1. Zend Framework 2 and Symfony2: Zend Framework 2 and Symfony2:

    The Perfect Team The Perfect Team Stefan Koopmanschap, Enrico Zimuel
  2. About us • Stefan Koopmanschap • Enterpreneur: Ingewikkeld and Techademy

    • Symfony Community Manager • Co-Founder PHPBenelux, now PFZ.nl • [email protected] • Enrico Zimuel • Software Engineer at Zend Technologies • Zend Framework Core Team • Co-founder PUG Turin • [email protected]
  3. PHP frameworks • Symfony and Zend Framework are the most

    used PHP frameworks worldwide • Both offer a tons of features that can improve the development of web applications • Modular architectures and high quality PHP code (SoC + SOLID principles) • Why don't use it together to get the best features of both?
  4. PSR-* • Framework interoperability standards • Meant to make it

    easier to work with multiple frameworks • Naming standards and coding standards • For instance: Only one autoloader! • https://github.com/php-fig/fig-standards
  5. Composer • Composer (getcomposer.org) can help the management of projects

    that use ZF2 and Symfony2 – Select your favorite ZF2 and Symfony2 components using composer.json – $ php composer.phar install – Components installed in /vendor – Include the /vendor/autoload.php in your PHP code, that's it!
  6. How to integrate How to integrate Zend Framework 2 in

    Symfony 2 Zend Framework 2 in Symfony 2
  7. Some stuff I won't show... • Zend\Barcode • Zend\Captcha •

    Zend\Feed • Zend\I18n • ZendService_*
  8. How to use Symfony2 in ZF2 • Use composer.json to

    include the Symfony2 components • Execute the update (or install) command of composer • The Symfony2 composer will be installed in /vendor • MVC approach: • Register the Symfony2 components in the ServiceManager • “Standard” approach: • Use the Symfony2 components directly (instantiate the class and use it)
  9. composer.json { "require": { "php": ">=5.3.3", "zendframework/zendframework": "2.0.*", "symfony/yaml": "2.2.*",

    "symfony/dom-crawler": "2.2.*", }, "autoload": { "psr-0": { "Application": "module/Application/src" } } }
  10. Symfony component as a service // a module config "module/SomeModule/config/module.config.php"

    return array( 'service_manager' => array( 'services' => array( // Keys are the service names // Values are objects 'YamlParser' => new Symfony\Component\Yaml\Parser(), 'DomCrawler' => new Symfony\Component\DomCrawler\Crawler(), // ... ), ) );
  11. Symfony component as a factory // a module config "module/SomeModule/config/module.config.php"

    return array( 'service_manager' => array( 'factories' => array( // Keys are the service names. // Valid values include names of classes implementing // FactoryInterface, instances of classes implementing // FactoryInterface, or any PHP callbacks 'YamlParser' => 'Symfony\Component\Yaml\Parser', 'DomCrawler' => 'Symfony\Component\DomCrawler\Crawler', // ... ), ) );
  12. Use a service in a Controller class AlbumController extends AbstractActionController

    { public function indexAction() { $sm = $this->getServiceLocator(); $yamlParser = $sm->get('YamlParser'); $domCrawler = $sm->get('DomCrawler'); } // ... }
  13. Symfony 2 components • Some components useful for ZF2 users:

    – BrowserKit (simulates a web browser) – CssSelector – Filesystem – Finder (file search) – OptionsResolver – Process (executes commands in sub-processes) – Serializer (handle serializing data structures) – YAML parser
  14. To integrate • PSR / Framework Interoperability • Composer •

    Pick your components • Don't stop at Zend Framework/Symfony • Don't Reinvent The Wheel!