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

Commit

Permalink
Merge branch 'develop' of git://github.com/zendframework/zf2 into dev…
Browse files Browse the repository at this point in the history
…elop
  • Loading branch information
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/AutoloaderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static function factory($options = null)
);
}

foreach ($options as $class => $options) {
foreach ($options as $class => $autoloaderOptions) {
if (!isset(static::$loaders[$class])) {
$autoloader = static::getStandardAutoloader();
if (!class_exists($class) && !$autoloader->autoload($class)) {
Expand All @@ -94,22 +94,22 @@ public static function factory($options = null)
);
}

if (!self::isSubclassOf($class, 'Zend\Loader\SplAutoloader')) {
if (!static::isSubclassOf($class, 'Zend\Loader\SplAutoloader')) {
require_once 'Exception/InvalidArgumentException.php';
throw new Exception\InvalidArgumentException(
sprintf('Autoloader class %s must implement Zend\\Loader\\SplAutoloader', $class)
);
}

if ($class === static::STANDARD_AUTOLOADER) {
$autoloader->setOptions($options);
$autoloader->setOptions($autoloaderOptions);
} else {
$autoloader = new $class($options);
$autoloader = new $class($autoloaderOptions);
}
$autoloader->register();
static::$loaders[$class] = $autoloader;
} else {
static::$loaders[$class]->setOptions($options);
static::$loaders[$class]->setOptions($autoloaderOptions);
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/ClassMapAutoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,17 @@ public function getAutoloadMap()
}

/**
* Defined by Autoloadable
*
* @param string $class
* @return void
* {@inheritDoc}
*/
public function autoload($class)
{
if (isset($this->map[$class])) {
require_once $this->map[$class];

return $class;
}

return false;
}

/**
Expand Down
8 changes: 5 additions & 3 deletions test/ClassMapAutoloaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,16 @@ public function testAutoloadLoadsClasses()
{
$map = array('ZendTest\UnusualNamespace\ClassMappedClass' => __DIR__ . '/TestAsset/ClassMappedClass.php');
$this->loader->registerAutoloadMap($map);
$this->loader->autoload('ZendTest\UnusualNamespace\ClassMappedClass');
$loaded = $this->loader->autoload('ZendTest\UnusualNamespace\ClassMappedClass');
$this->assertSame('ZendTest\UnusualNamespace\ClassMappedClass', $loaded);
$this->assertTrue(class_exists('ZendTest\UnusualNamespace\ClassMappedClass', false));
}

public function testIgnoresClassesNotInItsMap()
{
$map = array('ZendTest\UnusualNamespace\ClassMappedClass' => __DIR__ . '/TestAsset/ClassMappedClass.php');
$this->loader->registerAutoloadMap($map);
$this->loader->autoload('ZendTest\UnusualNamespace\UnMappedClass');
$this->assertFalse($this->loader->autoload('ZendTest\UnusualNamespace\UnMappedClass'));
$this->assertFalse(class_exists('ZendTest\UnusualNamespace\UnMappedClass', false));
}

Expand All @@ -172,7 +173,8 @@ public function testCanLoadClassMapFromPhar()
{
$map = 'phar://' . __DIR__ . '/_files/classmap.phar/test/.//../autoload_classmap.php';
$this->loader->registerAutoloadMap($map);
$this->loader->autoload('some\loadedclass');
$loaded = $this->loader->autoload('some\loadedclass');
$this->assertSame('some\loadedclass', $loaded);
$this->assertTrue(class_exists('some\loadedclass', false));

// will not register duplicate, even with a different relative path
Expand Down

0 comments on commit 251bb65

Please sign in to comment.