mirror of
https://github.com/Mibew/mibew.git
synced 2025-02-12 10:31:09 +03:00
Add a function to check if a plugin exists or it does not.
This commit is contained in:
parent
03a8eab3d1
commit
48978fb060
@ -49,22 +49,12 @@ class Utils
|
|||||||
);
|
);
|
||||||
|
|
||||||
foreach (glob($pattern) as $plugin_file) {
|
foreach (glob($pattern) as $plugin_file) {
|
||||||
// Build plugin's name and validate it.
|
// Build plugin's name and make sure the plugin exists.
|
||||||
$parts = array_reverse(explode(DIRECTORY_SEPARATOR, $plugin_file));
|
$parts = array_reverse(explode(DIRECTORY_SEPARATOR, $plugin_file));
|
||||||
$plugin_name = $parts[4] . ':' . $parts[1];
|
$plugin_name = $parts[4] . ':' . $parts[1];
|
||||||
if (!self::isValidPluginName($plugin_name)) {
|
if (!self::pluginExists($plugin_name)) {
|
||||||
continue;
|
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;
|
$plugins[] = $plugin_name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -101,6 +91,30 @@ class Utils
|
|||||||
return '\\' . $vendor . '\\Mibew\\Plugin\\' . $short_name . '\\Plugin';
|
return '\\' . $vendor . '\\Mibew\\Plugin\\' . $short_name . '\\Plugin';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a plugin with specified name exists.
|
||||||
|
*
|
||||||
|
* @param string $plugin_name Name of the plugin to check.
|
||||||
|
* @return boolean True if the plugin exists and false otherwise.
|
||||||
|
*/
|
||||||
|
public static function pluginExists($plugin_name)
|
||||||
|
{
|
||||||
|
if (!self::isValidPluginName($plugin_name)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure plugin class exists and represents a real plugin.
|
||||||
|
$class_name = self::getPluginClassName($plugin_name);
|
||||||
|
if (!class_exists($class_name)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!in_array('Mibew\\Plugin\\PluginInterface', class_implements($class_name))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class should not be instantiated
|
* This class should not be instantiated
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user