]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - application/PluginManager.php
Merge pull request #656 from ArthurHoaro/v0.8.0
[github/shaarli/Shaarli.git] / application / PluginManager.php
index 787ac6a930f63f4c1245a3178b6de444be6569a9..1e132a7f652c78aa077a86ed3c1013ad58b7c95b 100644 (file)
@@ -4,17 +4,9 @@
  * Class PluginManager
  *
  * Use to manage, load and execute plugins.
- *
- * Using Singleton design pattern.
  */
 class PluginManager
 {
-    /**
-     * PluginManager singleton instance.
-     * @var PluginManager $instance
-     */
-    private static $instance;
-
     /**
      * List of authorized plugins from configuration file.
      * @var array $authorizedPlugins
@@ -27,6 +19,11 @@ class PluginManager
      */
     private $loadedPlugins = array();
 
+    /**
+     * @var ConfigManager Configuration Manager instance.
+     */
+    protected $conf;
+
     /**
      * Plugins subdirectory.
      * @var string $PLUGINS_PATH
@@ -40,33 +37,13 @@ class PluginManager
     public static $META_EXT = 'meta';
 
     /**
-     * Private constructor: new instances not allowed.
-     */
-    private function __construct()
-    {
-    }
-
-    /**
-     * Cloning isn't allowed either.
+     * Constructor.
      *
-     * @return void
+     * @param ConfigManager $conf Configuration Manager instance.
      */
-    private function __clone()
+    public function __construct(&$conf)
     {
-    }
-
-    /**
-     * Return existing instance of PluginManager, or create it.
-     *
-     * @return PluginManager instance.
-     */
-    public static function getInstance()
-    {
-        if (!(self::$instance instanceof self)) {
-            self::$instance = new self();
-        }
-
-        return self::$instance;
+        $this->conf = $conf;
     }
 
     /**
@@ -102,9 +79,9 @@ class PluginManager
     /**
      * Execute all plugins registered hook.
      *
-     * @param string $hook   name of the hook to trigger.
-     * @param array  $data   list of data to manipulate passed by reference.
-     * @param array  $params additional parameters such as page target.
+     * @param string        $hook   name of the hook to trigger.
+     * @param array         $data   list of data to manipulate passed by reference.
+     * @param array         $params additional parameters such as page target.
      *
      * @return void
      */
@@ -122,7 +99,7 @@ class PluginManager
             $hookFunction = $this->buildHookName($hook, $plugin);
 
             if (function_exists($hookFunction)) {
-                $data = call_user_func($hookFunction, $data);
+                $data = call_user_func($hookFunction, $data, $this->conf);
             }
         }
     }
@@ -148,6 +125,7 @@ class PluginManager
             throw new PluginFileNotFoundException($pluginName);
         }
 
+        $conf = $this->conf;
         include_once $pluginFilePath;
 
         $this->loadedPlugins[] = $pluginName;
@@ -207,7 +185,11 @@ class PluginManager
                     continue;
                 }
 
-                $metaData[$plugin]['parameters'][$param] = '';
+                $metaData[$plugin]['parameters'][$param]['value'] = '';
+                // Optional parameter description in parameter.PARAM_NAME=
+                if (isset($metaData[$plugin]['parameter.'. $param])) {
+                    $metaData[$plugin]['parameters'][$param]['desc'] = $metaData[$plugin]['parameter.'. $param];
+                }
             }
         }
 
@@ -232,4 +214,4 @@ class PluginFileNotFoundException extends Exception
     {
         $this->message = 'Plugin "'. $pluginName .'" files not found.';
     }
-}
\ No newline at end of file
+}