mirror of
https://github.com/Mibew/mibew.git
synced 2024-11-15 16:44:11 +03:00
Use more strict policy for plugin names
This commit is contained in:
parent
f4b08ff0a3
commit
b896d43db7
@ -122,23 +122,21 @@ class PluginManager
|
||||
}
|
||||
$plugin_name = $plugin['name'];
|
||||
|
||||
// Split full name to vendor name and short name
|
||||
list($vendor_name, $plugin_short_name) = explode(':', $plugin_name, 2);
|
||||
if (empty($vendor_name) || empty($plugin_short_name)) {
|
||||
// Get vendor name and short name from plugin's name
|
||||
if (!Utils::isValidPluginName($plugin_name)) {
|
||||
trigger_error(
|
||||
"Wrong formated plugin name '" . $plugin_name . "'!",
|
||||
E_USER_WARNING
|
||||
);
|
||||
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
|
||||
$plugin_name_parts = explode('_', $plugin_short_name);
|
||||
$plugin_name_parts = array_map('ucfirst', $plugin_name_parts);
|
||||
$plugin_classname = '\\' . ucfirst($vendor_name)
|
||||
. '\\Mibew\\Plugin\\' . implode('', $plugin_name_parts) . '\\Plugin';
|
||||
$plugin_classname = '\\' . $vendor_name
|
||||
. '\\Mibew\\Plugin\\' . $plugin_short_name . '\\Plugin';
|
||||
|
||||
// Check plugin class name
|
||||
if (!class_exists($plugin_classname)) {
|
||||
|
@ -24,6 +24,11 @@ namespace Mibew\Plugin;
|
||||
*/
|
||||
class Utils
|
||||
{
|
||||
/**
|
||||
* Describes a valid plugin name.
|
||||
*/
|
||||
const pluginNameRegExp = "/^([A-Z][0-9A-Za-z]+):([A-Z][0-9A-Za-z]+)$/";
|
||||
|
||||
/**
|
||||
* Gets list of plugins existing in File System.
|
||||
*
|
||||
@ -61,6 +66,17 @@ class Utils
|
||||
return $plugins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified name is a valid plugin name.
|
||||
*
|
||||
* @param string $name A string to check.
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isValidPluginName($name)
|
||||
{
|
||||
return (preg_match(self::pluginNameRegExp, $name) != 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* This class should not be instantiated
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user