]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - application/PluginManager.php
New init function for plugins, supports errors reporting
[github/shaarli/Shaarli.git] / application / PluginManager.php
index 1e132a7f652c78aa077a86ed3c1013ad58b7c95b..59ece4fa9c735b8c2d150b939d48794fddeb2279 100644 (file)
@@ -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;
+    }
 }
 
 /**