mirror of
https://github.com/Mibew/mibew.git
synced 2025-04-10 09:50:12 +03:00
Statically cache results of Plugin\Utils::discoverPlugins
This commit is contained in:
parent
dca7c2c520
commit
428c592139
@ -37,31 +37,36 @@ class Utils
|
|||||||
*/
|
*/
|
||||||
public static function discoverPlugins()
|
public static function discoverPlugins()
|
||||||
{
|
{
|
||||||
$pattern = MIBEW_FS_ROOT . str_replace(
|
static $plugins = null;
|
||||||
'/',
|
|
||||||
DIRECTORY_SEPARATOR,
|
|
||||||
'/plugins/*/Mibew/Plugin/*/Plugin.php'
|
|
||||||
);
|
|
||||||
|
|
||||||
$plugins = array();
|
if (is_null($plugins)) {
|
||||||
foreach (glob($pattern) as $plugin_file) {
|
$plugins = array();
|
||||||
// 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.
|
$pattern = MIBEW_FS_ROOT . str_replace(
|
||||||
$class_name = self::getPluginClassName($plugin_name);
|
'/',
|
||||||
if (!class_exists($class_name)) {
|
DIRECTORY_SEPARATOR,
|
||||||
continue;
|
'/plugins/*/Mibew/Plugin/*/Plugin.php'
|
||||||
}
|
);
|
||||||
if (!in_array('Mibew\\Plugin\\PluginInterface', class_implements($class_name))) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$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;
|
return $plugins;
|
||||||
|
Loading…
Reference in New Issue
Block a user