X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2FPluginManager.php;h=59ece4fa9c735b8c2d150b939d48794fddeb2279;hb=7fde6de1212323418401c15efba06026c704ca87;hp=1e132a7f652c78aa077a86ed3c1013ad58b7c95b;hpb=f63632a6fb84594b8aeacb387a5cd17b4a841d2c;p=github%2Fshaarli%2FShaarli.git diff --git a/application/PluginManager.php b/application/PluginManager.php index 1e132a7f..59ece4fa 100644 --- a/application/PluginManager.php +++ b/application/PluginManager.php @@ -24,6 +24,11 @@ class PluginManager */ protected $conf; + /** + * @var array List of plugin errors. + */ + protected $errors; + /** * Plugins subdirectory. * @var string $PLUGINS_PATH @@ -44,6 +49,7 @@ class PluginManager public function __construct(&$conf) { $this->conf = $conf; + $this->errors = array(); } /** @@ -106,6 +112,7 @@ class PluginManager /** * Load a single plugin from its files. + * Call the init function if it exists, and collect errors. * Add them in $loadedPlugins if successful. * * @param string $dir plugin's directory. @@ -128,6 +135,14 @@ class PluginManager $conf = $this->conf; include_once $pluginFilePath; + $initFunction = $pluginName . '_init'; + if (function_exists($initFunction)) { + $errors = call_user_func($initFunction, $this->conf); + if (!empty($errors)) { + $this->errors = array_merge($this->errors, $errors); + } + } + $this->loadedPlugins[] = $pluginName; } @@ -195,6 +210,16 @@ class PluginManager return $metaData; } + + /** + * Return the list of encountered errors. + * + * @return array List of errors (empty array if none exists). + */ + public function getErrors() + { + return $this->errors; + } } /**