Use more strict policy for plugin names

This commit is contained in:
Dmitriy Simushev 2014-11-19 14:06:19 +00:00
parent f4b08ff0a3
commit b896d43db7
2 changed files with 21 additions and 7 deletions

View File

@ -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)) {

View File

@ -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
*/