Integrating Zend Framework 2 in Symfony 1.4

With PHP 5.3 the new era of PHP frameworks has begun, and things are really, for example, simpler to integrate, thanks to the PSR0, which is the standard autoloader adopted by the community.

The PSR0 is, obviously, not supported by the symfony 1.4 framework, which was released far before PHP 5.3 was ready, but it’s not that difficult to integrate PSR0-compliant projects in Sf1.4.

If you want, for example, to use the Zend Framework 2 in symfony you just need a few quick steps: first of all, copy the standard SplClassLoader in your symfony project ( lib/autoload? ), then require it in your projectConfiguration.class.php:

1
2
3
4
5
<?php

require_once dirname(__FILE__).'/../lib/vendor/symfony/lib/autoload/sfCoreAutoload.class.php';
require_once dirname(__FILE__).'/../lib/autoload/SplClassLoader.php';
sfCoreAutoload::register();

then, put the Zend Framework wherever you want ( lib/vendor/ZF2? ) and re-edit the projectConfiguration:

1
2
3
4
5
6
<?php

...
sfCoreAutoload::register();
$classLoader = new SplClassLoader('ZF2', '/path/to/zend/framework/2');
$classLoader->register();

and you’re done!

You can start using the Zend Framework 2 using namespaces inside your existing symfony code, without breaking anything:

1
2
3
4
5
6
7
8
<?php

use ZF2\Service\Twitter;
class twitterActions extends sfActions
{
  public function executeTwitterLogin(sfWebRequest $request)
  {
    $service = new Twitter();

Hi there! I recently wrote an ebook on web application security, currently sold on leanpub, the Amazon Kindle store and gumroad.

It contains 160+ pages of content dedicated to securing web applications and improving your security awareness when building web apps, with chapters ranging from explaining how to secure HTTP cookies with the right flags to understanding why it is important to consider joining a bug bounty program.

Feel free to skim through some of the free chapters published on this blog and, if the content seems interesting enough to you, grab a copy on leanpub, the Amazon Kindle store, gumroad or simply checkout right down below!

Buy the Web Application Security ebook for $9.99

In the mood for some more reading?

...or check the archives.