Skip to content

Commit

Permalink
Make the introduced performance optimization for PluginLoader optional (
Browse files Browse the repository at this point in the history
#4)

- restore original PluginLoader behavior by default
- introduce static Zend_Loader_PluginLoader::useFallbackLoader(false) toggle to disable the fallback and depend solely on composer's autoloader (for performance) - if your code structure supports that
  • Loading branch information
falkenhawk authored May 7, 2019
1 parent 9b068ec commit 69f3136
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions library/Zend/Loader/PluginLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ class Zend_Loader_PluginLoader implements Zend_Loader_PluginLoader_Interface
*/
protected static $_includeFileCacheHandler;

/**
* Toggle for fallback loader
* @var bool
*/
protected static $_useFallbackLoader = true;

/**
* Instance loaded plugin paths
*
Expand Down Expand Up @@ -393,8 +399,10 @@ public function load($name, $throwExceptions = true)
$found = true;
break;
}
// composer autoload should handle loading a class. class_exists call is enough
continue;
if (!self::$_useFallbackLoader) {
// composer autoload should handle loading a class. class_exists call is enough
continue;
}

$paths = array_reverse($paths, true);

Expand Down Expand Up @@ -505,4 +513,16 @@ protected static function _appendIncFile($incFile)
fwrite(self::$_includeFileCacheHandler, $line, strlen($line));
}
}

/**
* Set usage of fallback loader (enabled by default)
* You may disable it with Zend_Loader_PluginLoader::useFallbackLoader(false)
* to depend solely on composer's autoloader (for performance) - if your code structure supports that
*
* @param bool $flag
*/
public static function useFallbackLoader($flag)
{
self::$_useFallbackLoader = (bool)$flag;
}
}

0 comments on commit 69f3136

Please sign in to comment.