mirror of
https://github.com/Mibew/mibew.git
synced 2025-04-10 09:50:12 +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'];
|
$plugin_name = $plugin['name'];
|
||||||
|
|
||||||
// Split full name to vendor name and short name
|
// Get vendor name and short name from plugin's name
|
||||||
list($vendor_name, $plugin_short_name) = explode(':', $plugin_name, 2);
|
if (!Utils::isValidPluginName($plugin_name)) {
|
||||||
if (empty($vendor_name) || empty($plugin_short_name)) {
|
|
||||||
trigger_error(
|
trigger_error(
|
||||||
"Wrong formated plugin name '" . $plugin_name . "'!",
|
"Wrong formated plugin name '" . $plugin_name . "'!",
|
||||||
E_USER_WARNING
|
E_USER_WARNING
|
||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
list($vendor_name, $plugin_short_name) = explode(':', $plugin_name, 2);
|
||||||
|
|
||||||
$plugin_config = isset($plugin['config']) ? $plugin['config'] : array();
|
$plugin_config = isset($plugin['config']) ? $plugin['config'] : array();
|
||||||
|
|
||||||
// Build name of the plugin class
|
// Build name of the plugin class
|
||||||
$plugin_name_parts = explode('_', $plugin_short_name);
|
$plugin_classname = '\\' . $vendor_name
|
||||||
$plugin_name_parts = array_map('ucfirst', $plugin_name_parts);
|
. '\\Mibew\\Plugin\\' . $plugin_short_name . '\\Plugin';
|
||||||
$plugin_classname = '\\' . ucfirst($vendor_name)
|
|
||||||
. '\\Mibew\\Plugin\\' . implode('', $plugin_name_parts) . '\\Plugin';
|
|
||||||
|
|
||||||
// Check plugin class name
|
// Check plugin class name
|
||||||
if (!class_exists($plugin_classname)) {
|
if (!class_exists($plugin_classname)) {
|
||||||
|
@ -24,6 +24,11 @@ namespace Mibew\Plugin;
|
|||||||
*/
|
*/
|
||||||
class Utils
|
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.
|
* Gets list of plugins existing in File System.
|
||||||
*
|
*
|
||||||
@ -61,6 +66,17 @@ class Utils
|
|||||||
return $plugins;
|
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
|
* This class should not be instantiated
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user