ZF-7350: Make Zend_Loader_PluginLoader to prefix agnostic (namespaces)


Zend_Loader_PluginLoader appends '_' to the prefixes added to it, preventing the use of namespaces classes as plugins. Making it prefix-agnostic allows it to load namespaced classes, by specification of a "My\View\Helper\" prefix.


Quick and dirty fix to allow the use of namespaced view helpers. This works only because since view helpers cannot be in subfolders and the basename is directly appended to the path. For other classes path calculation could be wrong.

The provided fix works well and does not seem to break the tests though that one must always append the \ at the end of the namespace prefix for exemple in resource loading in an ini file:

pluginPaths["My\Application\Resource\"] = "My/Application/Resource"

To optionnally provide the ending backslash strstr($prefix, '\') could be used but then again non subnamespaces would fail at that using

$pluginLoader->addPrefixPath('My', 'Path/To/My'); //My is a namespace

still the only quick solution remain but an end backslash must be provided.

$pluginLoader->addPrefixPath('My\', 'Path/To/My'); //My is a namespace

Don't know your thoughts on that maybe Giorgio's solution may prove the only one not breaking anything.

Edit (correction): though that one must always append the "\ \"

[second code snippet]:

and $pluginLoader->addPrefixPath('My\ \', 'Path/To/My'); //My is a namespace

I also came across this issue as I'm starting to write my applications using proper namespaces. I tackled the issue using the same method. I can't see it having any problems considering \ has never been used as a class name character, and looking at the end character seems the most logical way to do this.

Since Zend_Loader has been modified to support PHP 5.3 namespaces in 1.10, I was hoping this could be implemented as a minor release?

I'm still watching and hoping for this as it is my only patch that I need to apply each time Zend upgrades. It does not break unit tests and I, too, think it should be implemented in a minor release.

Updated patch for Zend Framework 1.10.1; hope this will be integrated soon.

Giorgio -- any chance I can get a unit test from you as well?

zf-7350-3: patch to use against /trunk with unit test added to PluginLoaderTest and necessary changes to Zend_Loader_PluginLoader. It incorporates the previous ones.

Patch applied to trunk and 1.10 release branch. Modified slightly to add a conditional to skip the test when PHP version is < 5.3.0.