diff options
author | ArthurHoaro <arthur@hoa.ro> | 2016-06-09 20:04:32 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2016-06-11 09:30:56 +0200 |
commit | 51def0d84955c7a951bd091eb5eeb3fce9deabd4 (patch) | |
tree | 466c24f215ee4d25bdcce67100b11e2fd3b0c78b /application/PluginManager.php | |
parent | 278d9ee2836df7d805845077f26f8cecd16f0f4f (diff) | |
download | Shaarli-51def0d84955c7a951bd091eb5eeb3fce9deabd4.tar.gz Shaarli-51def0d84955c7a951bd091eb5eeb3fce9deabd4.tar.zst Shaarli-51def0d84955c7a951bd091eb5eeb3fce9deabd4.zip |
PluginManager no longer uses singleton pattern
Diffstat (limited to 'application/PluginManager.php')
-rw-r--r-- | application/PluginManager.php | 50 |
1 files changed, 14 insertions, 36 deletions
diff --git a/application/PluginManager.php b/application/PluginManager.php index 787ac6a9..dca7e63e 100644 --- a/application/PluginManager.php +++ b/application/PluginManager.php | |||
@@ -4,18 +4,10 @@ | |||
4 | * Class PluginManager | 4 | * Class PluginManager |
5 | * | 5 | * |
6 | * Use to manage, load and execute plugins. | 6 | * Use to manage, load and execute plugins. |
7 | * | ||
8 | * Using Singleton design pattern. | ||
9 | */ | 7 | */ |
10 | class PluginManager | 8 | class PluginManager |
11 | { | 9 | { |
12 | /** | 10 | /** |
13 | * PluginManager singleton instance. | ||
14 | * @var PluginManager $instance | ||
15 | */ | ||
16 | private static $instance; | ||
17 | |||
18 | /** | ||
19 | * List of authorized plugins from configuration file. | 11 | * List of authorized plugins from configuration file. |
20 | * @var array $authorizedPlugins | 12 | * @var array $authorizedPlugins |
21 | */ | 13 | */ |
@@ -28,6 +20,11 @@ class PluginManager | |||
28 | private $loadedPlugins = array(); | 20 | private $loadedPlugins = array(); |
29 | 21 | ||
30 | /** | 22 | /** |
23 | * @var ConfigManager Configuration Manager instance. | ||
24 | */ | ||
25 | protected $conf; | ||
26 | |||
27 | /** | ||
31 | * Plugins subdirectory. | 28 | * Plugins subdirectory. |
32 | * @var string $PLUGINS_PATH | 29 | * @var string $PLUGINS_PATH |
33 | */ | 30 | */ |
@@ -40,33 +37,13 @@ class PluginManager | |||
40 | public static $META_EXT = 'meta'; | 37 | public static $META_EXT = 'meta'; |
41 | 38 | ||
42 | /** | 39 | /** |
43 | * Private constructor: new instances not allowed. | 40 | * Constructor. |
44 | */ | ||
45 | private function __construct() | ||
46 | { | ||
47 | } | ||
48 | |||
49 | /** | ||
50 | * Cloning isn't allowed either. | ||
51 | * | ||
52 | * @return void | ||
53 | */ | ||
54 | private function __clone() | ||
55 | { | ||
56 | } | ||
57 | |||
58 | /** | ||
59 | * Return existing instance of PluginManager, or create it. | ||
60 | * | 41 | * |
61 | * @return PluginManager instance. | 42 | * @param ConfigManager $conf Configuration Manager instance. |
62 | */ | 43 | */ |
63 | public static function getInstance() | 44 | public function __construct(&$conf) |
64 | { | 45 | { |
65 | if (!(self::$instance instanceof self)) { | 46 | $this->conf = $conf; |
66 | self::$instance = new self(); | ||
67 | } | ||
68 | |||
69 | return self::$instance; | ||
70 | } | 47 | } |
71 | 48 | ||
72 | /** | 49 | /** |
@@ -102,9 +79,9 @@ class PluginManager | |||
102 | /** | 79 | /** |
103 | * Execute all plugins registered hook. | 80 | * Execute all plugins registered hook. |
104 | * | 81 | * |
105 | * @param string $hook name of the hook to trigger. | 82 | * @param string $hook name of the hook to trigger. |
106 | * @param array $data list of data to manipulate passed by reference. | 83 | * @param array $data list of data to manipulate passed by reference. |
107 | * @param array $params additional parameters such as page target. | 84 | * @param array $params additional parameters such as page target. |
108 | * | 85 | * |
109 | * @return void | 86 | * @return void |
110 | */ | 87 | */ |
@@ -122,7 +99,7 @@ class PluginManager | |||
122 | $hookFunction = $this->buildHookName($hook, $plugin); | 99 | $hookFunction = $this->buildHookName($hook, $plugin); |
123 | 100 | ||
124 | if (function_exists($hookFunction)) { | 101 | if (function_exists($hookFunction)) { |
125 | $data = call_user_func($hookFunction, $data); | 102 | $data = call_user_func($hookFunction, $data, $this->conf); |
126 | } | 103 | } |
127 | } | 104 | } |
128 | } | 105 | } |
@@ -148,6 +125,7 @@ class PluginManager | |||
148 | throw new PluginFileNotFoundException($pluginName); | 125 | throw new PluginFileNotFoundException($pluginName); |
149 | } | 126 | } |
150 | 127 | ||
128 | $conf = $this->conf; | ||
151 | include_once $pluginFilePath; | 129 | include_once $pluginFilePath; |
152 | 130 | ||
153 | $this->loadedPlugins[] = $pluginName; | 131 | $this->loadedPlugins[] = $pluginName; |