aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/PluginManager.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2016-10-14 13:22:58 +0200
committerArthurHoaro <arthur@hoa.ro>2016-10-14 13:22:58 +0200
commit7fde6de1212323418401c15efba06026c704ca87 (patch)
tree63b7efe598d1c563eee939fe9be3505afff1d873 /application/PluginManager.php
parentf63632a6fb84594b8aeacb387a5cd17b4a841d2c (diff)
downloadShaarli-7fde6de1212323418401c15efba06026c704ca87.tar.gz
Shaarli-7fde6de1212323418401c15efba06026c704ca87.tar.zst
Shaarli-7fde6de1212323418401c15efba06026c704ca87.zip
New init function for plugins, supports errors reporting
All plugins can optionally add an init function named `pluginname_init()` which is called when the plugin is loaded. This function is aware of the config, and can return initialization errors, which are displayed in the header template. Note that the previous error system hack no longer work.
Diffstat (limited to 'application/PluginManager.php')
-rw-r--r--application/PluginManager.php25
1 files changed, 25 insertions, 0 deletions
diff --git a/application/PluginManager.php b/application/PluginManager.php
index 1e132a7f..59ece4fa 100644
--- a/application/PluginManager.php
+++ b/application/PluginManager.php
@@ -25,6 +25,11 @@ class PluginManager
25 protected $conf; 25 protected $conf;
26 26
27 /** 27 /**
28 * @var array List of plugin errors.
29 */
30 protected $errors;
31
32 /**
28 * Plugins subdirectory. 33 * Plugins subdirectory.
29 * @var string $PLUGINS_PATH 34 * @var string $PLUGINS_PATH
30 */ 35 */
@@ -44,6 +49,7 @@ class PluginManager
44 public function __construct(&$conf) 49 public function __construct(&$conf)
45 { 50 {
46 $this->conf = $conf; 51 $this->conf = $conf;
52 $this->errors = array();
47 } 53 }
48 54
49 /** 55 /**
@@ -106,6 +112,7 @@ class PluginManager
106 112
107 /** 113 /**
108 * Load a single plugin from its files. 114 * Load a single plugin from its files.
115 * Call the init function if it exists, and collect errors.
109 * Add them in $loadedPlugins if successful. 116 * Add them in $loadedPlugins if successful.
110 * 117 *
111 * @param string $dir plugin's directory. 118 * @param string $dir plugin's directory.
@@ -128,6 +135,14 @@ class PluginManager
128 $conf = $this->conf; 135 $conf = $this->conf;
129 include_once $pluginFilePath; 136 include_once $pluginFilePath;
130 137
138 $initFunction = $pluginName . '_init';
139 if (function_exists($initFunction)) {
140 $errors = call_user_func($initFunction, $this->conf);
141 if (!empty($errors)) {
142 $this->errors = array_merge($this->errors, $errors);
143 }
144 }
145
131 $this->loadedPlugins[] = $pluginName; 146 $this->loadedPlugins[] = $pluginName;
132 } 147 }
133 148
@@ -195,6 +210,16 @@ class PluginManager
195 210
196 return $metaData; 211 return $metaData;
197 } 212 }
213
214 /**
215 * Return the list of encountered errors.
216 *
217 * @return array List of errors (empty array if none exists).
218 */
219 public function getErrors()
220 {
221 return $this->errors;
222 }
198} 223}
199 224
200/** 225/**