From 51def0d84955c7a951bd091eb5eeb3fce9deabd4 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Thu, 9 Jun 2016 20:04:32 +0200 Subject: PluginManager no longer uses singleton pattern --- application/PluginManager.php | 50 ++++++++++++------------------------------- 1 file changed, 14 insertions(+), 36 deletions(-) (limited to 'application') diff --git a/application/PluginManager.php b/application/PluginManager.php index 787ac6a9..dca7e63e 100644 --- a/application/PluginManager.php +++ b/application/PluginManager.php @@ -4,17 +4,9 @@ * Class PluginManager * * Use to manage, load and execute plugins. - * - * Using Singleton design pattern. */ class PluginManager { - /** - * PluginManager singleton instance. - * @var PluginManager $instance - */ - private static $instance; - /** * List of authorized plugins from configuration file. * @var array $authorizedPlugins @@ -27,6 +19,11 @@ class PluginManager */ private $loadedPlugins = array(); + /** + * @var ConfigManager Configuration Manager instance. + */ + protected $conf; + /** * Plugins subdirectory. * @var string $PLUGINS_PATH @@ -40,33 +37,13 @@ class PluginManager public static $META_EXT = 'meta'; /** - * Private constructor: new instances not allowed. - */ - private function __construct() - { - } - - /** - * Cloning isn't allowed either. - * - * @return void - */ - private function __clone() - { - } - - /** - * Return existing instance of PluginManager, or create it. + * Constructor. * - * @return PluginManager instance. + * @param ConfigManager $conf Configuration Manager instance. */ - public static function getInstance() + public function __construct(&$conf) { - if (!(self::$instance instanceof self)) { - self::$instance = new self(); - } - - return self::$instance; + $this->conf = $conf; } /** @@ -102,9 +79,9 @@ class PluginManager /** * Execute all plugins registered hook. * - * @param string $hook name of the hook to trigger. - * @param array $data list of data to manipulate passed by reference. - * @param array $params additional parameters such as page target. + * @param string $hook name of the hook to trigger. + * @param array $data list of data to manipulate passed by reference. + * @param array $params additional parameters such as page target. * * @return void */ @@ -122,7 +99,7 @@ class PluginManager $hookFunction = $this->buildHookName($hook, $plugin); if (function_exists($hookFunction)) { - $data = call_user_func($hookFunction, $data); + $data = call_user_func($hookFunction, $data, $this->conf); } } } @@ -148,6 +125,7 @@ class PluginManager throw new PluginFileNotFoundException($pluginName); } + $conf = $this->conf; include_once $pluginFilePath; $this->loadedPlugins[] = $pluginName; -- cgit v1.2.3