Issues

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

Thanks for the supplied patch. Did you try to run the unittests with this patch in place?

yes. I run the existing unit tests, it's OK.

sorry for typo.