From 428c5921395a8640235e628c0f30321f2acc4190 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Fri, 21 Nov 2014 13:06:44 +0000 Subject: [PATCH] Statically cache results of Plugin\Utils::discoverPlugins --- src/mibew/libs/classes/Mibew/Plugin/Utils.php | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/src/mibew/libs/classes/Mibew/Plugin/Utils.php b/src/mibew/libs/classes/Mibew/Plugin/Utils.php index 58f3d08e..275c4cff 100644 --- a/src/mibew/libs/classes/Mibew/Plugin/Utils.php +++ b/src/mibew/libs/classes/Mibew/Plugin/Utils.php @@ -37,31 +37,36 @@ class Utils */ public static function discoverPlugins() { - $pattern = MIBEW_FS_ROOT . str_replace( - '/', - DIRECTORY_SEPARATOR, - '/plugins/*/Mibew/Plugin/*/Plugin.php' - ); + static $plugins = null; - $plugins = array(); - foreach (glob($pattern) as $plugin_file) { - // Build plugin's name and validate it. - $parts = array_reverse(explode(DIRECTORY_SEPARATOR, $plugin_file)); - $plugin_name = $parts[4] . ':' . $parts[1]; - if (!self::isValidPluginName($plugin_name)) { - continue; - } + if (is_null($plugins)) { + $plugins = array(); - // Make sure we found a plugin. - $class_name = self::getPluginClassName($plugin_name); - if (!class_exists($class_name)) { - continue; - } - if (!in_array('Mibew\\Plugin\\PluginInterface', class_implements($class_name))) { - continue; - } + $pattern = MIBEW_FS_ROOT . str_replace( + '/', + DIRECTORY_SEPARATOR, + '/plugins/*/Mibew/Plugin/*/Plugin.php' + ); - $plugins[] = $plugin_name; + foreach (glob($pattern) as $plugin_file) { + // Build plugin's name and validate it. + $parts = array_reverse(explode(DIRECTORY_SEPARATOR, $plugin_file)); + $plugin_name = $parts[4] . ':' . $parts[1]; + if (!self::isValidPluginName($plugin_name)) { + continue; + } + + // Make sure we found a plugin. + $class_name = self::getPluginClassName($plugin_name); + if (!class_exists($class_name)) { + continue; + } + if (!in_array('Mibew\\Plugin\\PluginInterface', class_implements($class_name))) { + continue; + } + + $plugins[] = $plugin_name; + } } return $plugins;