diff --git a/src/Core/PluginInterface.php b/src/Core/PluginInterface.php index 9f940ab2465..8ca539bc682 100644 --- a/src/Core/PluginInterface.php +++ b/src/Core/PluginInterface.php @@ -18,6 +18,14 @@ */ interface PluginInterface { + /** + * Load all the application configuration and bootstrap logic. + * + * Override this method to add additional bootstrap logic for your application. + * + * @return void + */ + public function bootstrap(); /** * Disables route loading for the plugin diff --git a/src/Core/PluginRegistry.php b/src/Core/PluginRegistry.php index 500cf3c7d9e..52082470456 100644 --- a/src/Core/PluginRegistry.php +++ b/src/Core/PluginRegistry.php @@ -20,7 +20,7 @@ /** * Plugin Registry */ -class PluginRegistry extends ObjectRegistry implements ConsoleApplicationInterface, HttpApplicationInterface +class PluginRegistry extends ObjectRegistry implements PluginRegistryInterface { /** @@ -79,7 +79,7 @@ protected function _create($class, $alias, $config) if ((!$instance instanceof HttpApplicationInterface && !$instance instanceof ConsoleApplicationInterface) || !$instance instanceof PluginInterface) { - throw new \RuntimeException(sprintf( + throw new RuntimeException(sprintf( '`%s` is not a valid plugin object. It\'s not implementing `%s` or `%s`', get_class($instance)), HttpApplicationInterface::class, diff --git a/src/Core/PluginRegistryInterface.php b/src/Core/PluginRegistryInterface.php new file mode 100644 index 00000000000..81142a3b268 --- /dev/null +++ b/src/Core/PluginRegistryInterface.php @@ -0,0 +1,29 @@ +configDir = $configDir; - $this->plugins = new PluginRegistry(); + + $this->setPluginRegistry($pluginRegistry); + } + + /** + * Sets the plugin registry + * + * @param string|null $pluginRegistry Plugin Registry Object + * @return void + */ + public function setPluginRegistry($pluginRegistry = null) + { + if (empty($pluginRegistry)) { + $this->pluginRegistry = new $this->defaultPluginRegistry(); + + return; + } + + if (!$pluginRegistry instanceof PluginRegistryInterface) { + throw new InvalidArgumentException(sprintf( + '`%s` is not an instance of `%s`', + get_class($pluginRegistry), + PluginRegistryInterface::class + )); + } + + $this->pluginRegistry = $pluginRegistry; } /** @@ -134,6 +170,6 @@ protected function getDispatcher() */ public function plugins() { - return $this->plugins; + return $this->pluginRegistry; } }