aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/PluginManager.php
diff options
context:
space:
mode:
authorArthur <arthur@hoa.ro>2016-10-17 08:50:18 +0200
committerGitHub <noreply@github.com>2016-10-17 08:50:18 +0200
commit06eec9bf764662cd328627247a1f43e4abd3c5ad (patch)
treefd66a3e1cb4cd93aa80b6f04c43958623140a008 /application/PluginManager.php
parentbb70e690598d270951148e003a4dc253b05868b4 (diff)
parent7fde6de1212323418401c15efba06026c704ca87 (diff)
downloadShaarli-06eec9bf764662cd328627247a1f43e4abd3c5ad.tar.gz
Shaarli-06eec9bf764662cd328627247a1f43e4abd3c5ad.tar.zst
Shaarli-06eec9bf764662cd328627247a1f43e4abd3c5ad.zip
Merge pull request #659 from ArthurHoaro/plugin-errors
New init function for plugins, supports errors reporting
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/**