Browse Source

Avoid creating multiple instances of ClassLoader.

ADmad 12 years ago
parent
commit
29c2b25d73
1 changed files with 12 additions and 3 deletions
  1. 12 3
      src/Core/Plugin.php

+ 12 - 3
src/Core/Plugin.php

@@ -35,6 +35,13 @@ class Plugin {
 	protected static $_plugins = [];
 
 /**
+ * Class loader instance
+ *
+ * @var \Cake\Core\ClassLoader
+ */
+	protected static $_loader;
+
+/**
  * Loads a plugin and optionally loads bootstrapping,
  * routing files or runs a initialization function.
  *
@@ -140,9 +147,11 @@ class Plugin {
 		}
 
 		if ($config['autoload'] === true) {
-			$loader = new ClassLoader;
-			$loader->register();
-			$loader->addNamespace($config['namespace'], $config['path']);
+			if (empty(static::$_loader)) {
+				static::$_loader = new ClassLoader;
+				static::$_loader->register();
+			}
+			static::$_loader->addNamespace($config['namespace'], $config['path']);
 		}
 	}