Skip to content

Commit

Permalink
Avoid creating multiple instances of ClassLoader.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Jan 19, 2014
1 parent 91c463d commit 29c2b25
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/Core/Plugin.php
Expand Up @@ -34,6 +34,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.
Expand Down Expand Up @@ -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']);
}
}

Expand Down

0 comments on commit 29c2b25

Please sign in to comment.