Prevent redundant autoloader registerations. Fixes #304
This commit is contained in:
@@ -16,6 +16,14 @@ class Mustache_Autoloader
|
||||
{
|
||||
private $baseDir;
|
||||
|
||||
/**
|
||||
* An array where the key is the baseDir and the key is an instance of this
|
||||
* class.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static private $instances;
|
||||
|
||||
/**
|
||||
* Autoloader constructor.
|
||||
*
|
||||
@@ -45,7 +53,13 @@ class Mustache_Autoloader
|
||||
*/
|
||||
public static function register($baseDir = null)
|
||||
{
|
||||
$loader = new self($baseDir);
|
||||
$key = $baseDir ? $baseDir : 0;
|
||||
|
||||
if (!isset(self::$instances[$key])) {
|
||||
self::$instances[$key] = new self($baseDir);
|
||||
}
|
||||
|
||||
$loader = self::$instances[$key];
|
||||
spl_autoload_register(array($loader, 'autoload'));
|
||||
|
||||
return $loader;
|
||||
|
||||
Reference in New Issue
Block a user