Permalink
Browse files

Avoid creating multiple instances of ClassLoader.

  • Loading branch information...
1 parent 91c463d commit 29c2b25d73061e5b8615ef567e08e72dc7193286 @ADmad ADmad committed Jan 19, 2014
Showing with 12 additions and 3 deletions.
  1. +12 −3 src/Core/Plugin.php
View
@@ -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 @@ public static function load($plugin, $config = []) {
}
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']);
}
}

0 comments on commit 29c2b25

Please sign in to comment.