Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/2754' into develop
Browse files Browse the repository at this point in the history
Forward port #2754

Conflicts:
	tests/ZendTest/Loader/ModuleAutoloaderTest.php
  • Loading branch information
weierophinney committed Oct 16, 2012
2 parents de6a9ef + 81cf86a commit 8a9b425
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 207 deletions.
33 changes: 32 additions & 1 deletion library/Zend/Loader/ModuleAutoloader.php
Expand Up @@ -29,6 +29,11 @@ class ModuleAutoloader implements SplAutoloader
*/
protected $explicitPaths = array();

/**
* @var array An array of namespaceName => namespacePath
*/
protected $namespacedPaths = array();

/**
* @var array An array of supported phar extensions (filled on constructor)
*/
Expand Down Expand Up @@ -149,6 +154,28 @@ public function autoload($class)
}
}

if (count($this->namespacedPaths) >= 1 ) {
foreach ( $this->namespacedPaths as $namespace=>$path ) {
if ( false === strpos($moduleName,$namespace) ) {
continue;
}

$moduleName_buffer = str_replace($namespace . "\\", "", $moduleName );
$path .= DIRECTORY_SEPARATOR . $moduleName_buffer . DIRECTORY_SEPARATOR;

$classLoaded = $this->loadModuleFromDir($path, $class);
if ($classLoaded) {
return $classLoaded;
}

$classLoaded = $this->loadModuleFromPhar($path, $class);
if ($classLoaded) {
return $classLoaded;
}
}
}


$moduleClassPath = str_replace('\\', DIRECTORY_SEPARATOR, $moduleName);

$pharSuffixPattern = null;
Expand Down Expand Up @@ -333,7 +360,11 @@ public function registerPath($path, $moduleName = false)
));
}
if ($moduleName) {
$this->explicitPaths[$moduleName] = static::normalizePath($path);
if (in_array( substr($moduleName, -2 ), array('\\*','\\%') ) ) {
$this->namespacedPaths[ substr($moduleName, 0, -2 ) ] = static::normalizePath($path);
} else {
$this->explicitPaths[$moduleName] = static::normalizePath($path);
}
} else {
$this->paths[] = static::normalizePath($path);
}
Expand Down
206 changes: 0 additions & 206 deletions tests/ZendTest/Loader/AutoloaderMultiVersionTest.php

This file was deleted.

12 changes: 12 additions & 0 deletions tests/ZendTest/Loader/ModuleAutoloaderTest.php
Expand Up @@ -209,4 +209,16 @@ public function testCanLoadModulesFromClassMap()
$this->assertTrue(class_exists('BarModule\Module'));
$this->assertTrue(class_exists('PharModuleMap\Module'));
}

public function testCanLoadModulesFromNamespace()
{
$loader = new ModuleAutoloader(array(
'FooModule\*' => __DIR__ . '/_files/FooModule',
'FooModule' => __DIR__ . '/_files/FooModule',
));
$loader->register();
$this->assertTrue(class_exists('FooModule\BarModule\Module'));
$this->assertTrue(class_exists('FooModule\SubModule\Module'));
$this->assertTrue(class_exists('FooModule\Module'));
}
}
15 changes: 15 additions & 0 deletions tests/ZendTest/Loader/_files/FooModule/BarModule/Module.php
@@ -0,0 +1,15 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Loader
*/

namespace FooModule\BarModule;

class Module
{
}

0 comments on commit 8a9b425

Please sign in to comment.