ZF-6484: Resource Autoloader does not take any namespace prefix
Description
It's not possible to set a namespace prefix like "Foo_Bar" to the class Zend_Loader_Autoloader_Resource. The class checks the namespace too restrictive.
The problem is that array_shift only returns the first part. So my namespace must be "Foo".
Line: 142
if (!empty($namespaceTopLevel)) {
$namespace = array_shift($segments);
if ($namespace != $this->getNamespace()) {
// wrong prefix? we're done
return false;
}
}
Comments
Posted by Dolf Schimmel (Freeaqingme) (freak) on 2009-05-01T10:08:20.000+0000
Assigning to Matthew.
Posted by Gildas de Cadoudal (gildas.de.cadoudal) on 2009-08-02T13:14:18.000+0000
I have encoutred the same problem following you can find a prosition of solution which replace the portion of code quote in issue description :
Posted by Matthew Weier O'Phinney (matthew) on 2010-06-18T09:30:02.000+0000
Can you demonstrate what your use case is for this? I'm not entirely convinced it makes sense for us to support this, particularly since you can override the resource autoloader yourself and override the appropriate method to drop in the functionality you desire.
Posted by Christian Münch (cmuench) on 2010-06-18T10:51:32.000+0000
I'm writing an CMS application with a plugin system. Each plugin should have an own namespace. The CMS plugin loader iterates over all plugins and registrates the namespace during runtime. All plugins have a namespace prefix "Plugin_". So i have i.E. a namespace like "Plugin_Frontend_Twitter". I overwritten the resource loader with my own Loader (Inmon_Cms_Loader_Autoloader_Resource) extended by Zend_Loader_Autoloader_Resource. So i have currently no problem. I think it's ok so. For ZF2 i have to port the CMS to the new plugin system with native PHP namespaces. So you can close the ticket IMHO.
Posted by Christian Opitz (metti) on 2010-06-20T18:37:26.000+0000
Hi guys,
had the same issue. I'm currently writing an implementation of ZF for TYPO3-extensions and there the "module" classes (for ZF they are modules; for TYPO3 plugins) are prefixed Tx_MyExt_...
I registered these modules with the Zend_Application_Module_Autoloader and everything worked fine except that getClassPath returned to early because it checked the toplevel namespace to be 'Tx' while the real one was Tx_ZfextSample_. My hack was then:
Cheers, Christian
Posted by Robert Goldsmith (far-blue) on 2010-11-01T01:53:26.000+0000
I've been trying to configure a per-module autoloader in a post-router plugin (after the module has been calculated) so I can have per-module forms, models etc. and consider the following format for the module namespace to be the 'correct' one: appNameSpace_moduleName. However, as has already bean mentioned, the getClassPath method in the 'module' autoloader assumes that the namespace for an autoloader does not contain the '' char. Instead of exploding the class path on the '' char and then comparing with the namespace, the following patch checks and correctly adjusts for any namespace before then continuing as normal by building the file path of a class based only on splitting on '_' chars after the namespace prefix.
Posted by Kim Blomqvist (kblomqvist) on 2011-05-28T07:17:57.000+0000
Seems like this is already resolved in ZF-11219?
Posted by Matthew Weier O'Phinney (matthew) on 2011-07-05T15:19:05.000+0000
Fixed with ZF-11219 for version 1.11.2.