开发者

Loading multiple versions of the same library

I'm using a library, Zend Framework in this and it has the path

ZendFramework-1.10.8/library/Zend/

I load it in index.php

realpath(CENTRAL_LIBS_PATH . '/ZendFramework-1.10.8/library'), // /Zend left out

and so can call one of its classes class with Zend_Form_

Now to my question, how can I use multiple versions of the same library. I suppose I would load both of the in index.php

realpath(CENTRAL_LIBS_PATH . '/ZendFramework-1.10.8/library'),
realpath(CENTRAL_LIBS_PATH . '/ZendFramework-2.0.0/library')

but then when I call a class like Zend_Form, how do I explicitly tell it to use the one from v1.10.8 or the one from v2.0.0? I remember reading somewhere that if 2 libraries have the same class, the library above is the one called. But how can I switch between开发者_如何学Python the 2 at will? Can it be done in the same project?


Zend Framework 2 classes are grouped within namespaces and has its own autoloader that looks through directories (it should be 1:1 relationship between a directory and a namespace).

You will need to register both autoloaders (you may need to rewrite ZF 1.10 to use SPL autoloading so that you can register multiple autoloaders. At that point the autoloaders should handle everything themselves, since there is a distinct difference in how ZF1 will try to load Zend_Form and ZF2 will try to load Zend\Form. I would probably go ahead and modify the ZF1 autoloader to ignore any request that is using true PHP namespaces.

Don't forget, SPL autoloading uses a FIFO method of looking for classes so if you're intending to use mostly ZF2 classes you should register its autoloader first and ZF1 second, as it will give you a decent performance boost.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜