ZF-10293: Zend_Loader_Autoloader_Resource couldn't load resource which named with native namespace
Description
h3.Environment: php 5.3.3 + ZF 1.10.7
h3.Project Tree: {panel:title=Project Tree| borderStyle=dashed| borderColor=#ccc| titleBGColor=#F7D6C1| bgColor=#FFFFCE} application ├───configs ├───controllers │ └───IndexController.php ├───entities │ └───Product.php ├───views └───Bootstrap.php {panel}
h3.Key Code:
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initAutoLoader()
{
$loader = new Zend_Application_Module_Autoloader(array(
'namespace' => '',
'basePath' => APPLICATION_PATH,
));
$loader->addResourceType('entity', 'entities', 'Entity');
return $loader;
}
}
namespace Entity;
class Product
{
protected $id;
}
class IndexController extends Zend_Controller_Action
{
public function indexAction()
{
$product = new Entity\Product(); // error, include_once(Entity\Category.php): failed to open stream: ...
}
}
h3.Solution:
*** Zend\Loader\Autoloader\Resource.fix.php Wed Aug 11 11:04:37 2010
--- Zend\Loader\Autoloader\Resource.php Tue Jan 05 21:05:10 2010
***************
*** 139,145 ****
*/
public function getClassPath($class)
{
! $segments = explode('_', str_replace('\\', '_', $class));
$namespaceTopLevel = $this->getNamespace();
$namespace = '';
--- 139,145 ----
*/
public function getClassPath($class)
{
! $segments = explode('_', $class);
$namespaceTopLevel = $this->getNamespace();
$namespace = '';
Comments
Posted by Dolf Schimmel (Freeaqingme) (freak) on 2010-08-11T03:30:10.000+0000
Thanks for the supplied patch. Did you try to run the unittests with this patch in place?
Posted by Ben Yan (ben_yan) on 2010-08-11T08:20:43.000+0000
yes. I run the existing unit tests, it's OK.
Posted by Ben Yan (ben_yan) on 2010-08-11T08:22:23.000+0000
sorry for typo.