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();
comments powered by Disqus