diff --git a/lib/exceptions/PluginAlreadyLoadingException.php b/lib/exceptions/PluginAlreadyLoadingException.php new file mode 100644 index 0000000000000000000000000000000000000000..e939a1911cb49f8783a7af34ab48d8b69aebefd2 --- /dev/null +++ b/lib/exceptions/PluginAlreadyLoadingException.php @@ -0,0 +1,19 @@ +<?php + +/** + * This exception is thrown, if a plugin is already loading. + * + * There should always only be one instance of a plugin class. + */ +class PluginAlreadyLoadingException extends Exception +{ + public function __construct(string $pluginClassName) + { + return parent::__construct( + sprintf( + _("Plugin '%s' wird bereits geladen."), + $pluginClassName + ) + ); + } +} diff --git a/lib/plugins/engine/PluginEngine.php b/lib/plugins/engine/PluginEngine.php index 52f94af15b2d5223ba7aec62f904474d83cacf2a..a49f90bea4ecb7442d5669f8740c8a0ff3a639dd 100644 --- a/lib/plugins/engine/PluginEngine.php +++ b/lib/plugins/engine/PluginEngine.php @@ -60,6 +60,7 @@ class PluginEngine if (is_object($user) && $perm->have_perm('admin')) { self::getPlugins(AdministrationPlugin::class); } + NotificationCenter::postNotification('PluginsDidLoad', PluginManager::getInstance()); } /** diff --git a/lib/plugins/engine/PluginManager.php b/lib/plugins/engine/PluginManager.php index 919e175f65ee20c675add6ecdf767a4b772a0209..ef0cd1355ed73fc0b742bda3eb055921934029d9 100644 --- a/lib/plugins/engine/PluginManager.php +++ b/lib/plugins/engine/PluginManager.php @@ -586,16 +586,22 @@ class PluginManager $plugin_class = ''; $plugin = null; - if (isset($this->plugin_cache[$class])) { - return $this->plugin_cache[$class]; + if (array_key_exists($class, $this->plugin_cache)) { + if ($this->plugin_cache[$class] !== null) { + return $this->plugin_cache[$class]; + } + throw new PluginAlreadyLoadingException($class); } + $this->plugin_cache[$class] = null; + if ($plugin_info['core'] || !$this->isPluginsDisabled()) { $plugin_class = $this->loadPlugin($class, $path); } if ($plugin_class) { $plugin = app()->get($class); + NotificationCenter::postNotification('PluginDidLoad', $this, compact('class', 'plugin')); } return $this->plugin_cache[$class] = $plugin;