MDL-49329 admin: Keep reference to plugin manager in plugininfo objects
Plugin info objects are owned by the plugin manager (composition pattern). Even if the plugin manager is a singleton, we need to keep explicit reference to the plugin manager that owns the plugin info so that we can mock up things in unit tests. Therefore this patch introduces a new property of plugin info objects that holds the reference to the instance of the plugin manager that made (and hence owns) the given info instance. The only trouble here is with static methods of plugin info classes such as \core\plugininfo\base::get_enabled_plugins(). In these cases, the code keeps using the core_plugin_manager singleton. The solution would be to pass the plugin manager instance as a parameter but that is not worth of change for now, IMHO.
This commit is contained in:
@@ -64,12 +64,12 @@ class orphaned extends base {
|
||||
* @param string $type the name of the plugintype, eg. mod, auth or workshopform
|
||||
* @param string $typerootdir full path to the location of the plugin dir
|
||||
* @param string $typeclass the name of the actually called class
|
||||
* @param core_plugin_manager $pluginman the plugin manager calling this method
|
||||
* @return array of plugintype classes, indexed by the plugin name
|
||||
*/
|
||||
public static function get_plugins($type, $typerootdir, $typeclass) {
|
||||
public static function get_plugins($type, $typerootdir, $typeclass, $pluginman) {
|
||||
$return = array();
|
||||
$manager = \core_plugin_manager::instance();
|
||||
$plugins = $manager->get_installed_plugins($type);
|
||||
$plugins = $pluginman->get_installed_plugins($type);
|
||||
|
||||
foreach ($plugins as $name => $version) {
|
||||
$plugin = new $typeclass();
|
||||
@@ -79,6 +79,7 @@ class orphaned extends base {
|
||||
$plugin->rootdir = null;
|
||||
$plugin->displayname = $name;
|
||||
$plugin->versiondb = $version;
|
||||
$plugin->pluginman = $pluginman;
|
||||
$plugin->init_is_standard();
|
||||
|
||||
$return[$name] = $plugin;
|
||||
|
||||
Reference in New Issue
Block a user