Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the introduced performance optimization for PluginLoader optional #4

Merged
merged 1 commit into from
May 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}