mirror of
https://github.com/Mibew/mibew.git
synced 2025-03-14 06:54:08 +03:00
Create a method for plugin class name building
This commit is contained in:
parent
b896d43db7
commit
a63f4ced3d
@ -121,6 +121,7 @@ class PluginManager
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$plugin_name = $plugin['name'];
|
$plugin_name = $plugin['name'];
|
||||||
|
$plugin_config = isset($plugin['config']) ? $plugin['config'] : array();
|
||||||
|
|
||||||
// Get vendor name and short name from plugin's name
|
// Get vendor name and short name from plugin's name
|
||||||
if (!Utils::isValidPluginName($plugin_name)) {
|
if (!Utils::isValidPluginName($plugin_name)) {
|
||||||
@ -130,13 +131,9 @@ class PluginManager
|
|||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
list($vendor_name, $plugin_short_name) = explode(':', $plugin_name, 2);
|
|
||||||
|
|
||||||
$plugin_config = isset($plugin['config']) ? $plugin['config'] : array();
|
|
||||||
|
|
||||||
// Build name of the plugin class
|
// Build name of the plugin class
|
||||||
$plugin_classname = '\\' . $vendor_name
|
$plugin_classname = Utils::getPluginClassName($plugin_name);
|
||||||
. '\\Mibew\\Plugin\\' . $plugin_short_name . '\\Plugin';
|
|
||||||
|
|
||||||
// Check plugin class name
|
// Check plugin class name
|
||||||
if (!class_exists($plugin_classname)) {
|
if (!class_exists($plugin_classname)) {
|
||||||
|
@ -45,22 +45,23 @@ class Utils
|
|||||||
|
|
||||||
$plugins = array();
|
$plugins = array();
|
||||||
foreach (glob($pattern) as $plugin_file) {
|
foreach (glob($pattern) as $plugin_file) {
|
||||||
|
// Build plugin's name and validate it.
|
||||||
$parts = array_reverse(explode(DIRECTORY_SEPARATOR, $plugin_file));
|
$parts = array_reverse(explode(DIRECTORY_SEPARATOR, $plugin_file));
|
||||||
$plugin = $parts[1];
|
$plugin_name = $parts[4] . ':' . $parts[1];
|
||||||
$vendor = $parts[4];
|
if (!self::isValidPluginName($plugin_name)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$class_name = '\\' . $vendor . '\\Mibew\\Plugin\\' . $plugin . '\\Plugin';
|
// Make sure we found a plugin.
|
||||||
|
$class_name = self::getPluginClassName($plugin_name);
|
||||||
// Check plugin class name
|
|
||||||
if (!class_exists($class_name)) {
|
if (!class_exists($class_name)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Check if plugin implements 'Plugin' interface
|
|
||||||
if (!in_array('Mibew\\Plugin\\PluginInterface', class_implements($class_name))) {
|
if (!in_array('Mibew\\Plugin\\PluginInterface', class_implements($class_name))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$plugins[] = $vendor . ':' . $plugin;
|
$plugins[] = $plugin_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $plugins;
|
return $plugins;
|
||||||
@ -77,6 +78,24 @@ class Utils
|
|||||||
return (preg_match(self::pluginNameRegExp, $name) != 0);
|
return (preg_match(self::pluginNameRegExp, $name) != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds class name for a plugin with the specified name.
|
||||||
|
*
|
||||||
|
* @param string $plugin_name Plugin's name in "Vendor:Name" format.
|
||||||
|
* @return string Fully qualified class name for the plugin.
|
||||||
|
* @throws \InvalidArgumentException If the passed in plugin name is
|
||||||
|
* invalid.
|
||||||
|
*/
|
||||||
|
public static function getPluginClassName($plugin_name)
|
||||||
|
{
|
||||||
|
if (!self::isValidPluginName($plugin_name)) {
|
||||||
|
throw new \InvalidArgumentException('Wrong formated plugin name');
|
||||||
|
}
|
||||||
|
list($vendor, $short_name) = explode(':', $plugin_name, 2);
|
||||||
|
|
||||||
|
return '\\' . $vendor . '\\Mibew\\Plugin\\' . $short_name . '\\Plugin';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class should not be instantiated
|
* This class should not be instantiated
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user