Add a function to check if a plugin exists or it does not.

This commit is contained in:
Dmitriy Simushev 2014-11-24 10:13:51 +00:00
parent 03a8eab3d1
commit 48978fb060

View File

@ -49,22 +49,12 @@ class Utils
);
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));
$plugin_name = $parts[4] . ':' . $parts[1];
if (!self::isValidPluginName($plugin_name)) {
if (!self::pluginExists($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;
}
}
@ -101,6 +91,30 @@ class Utils
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
*/