Actions

Plugin system architecture

From LimeSurvey Manual

Revision as of 11:27, 8 January 2013 by Sammousa (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Some random stuff on plugin architecture.

The plugins will extend a base class.

The base plugin class will initialize a storage interface and create wrapper functions for the get and set implemented in the interface.

Code below might contain mistakes, textarea doesnt have syntax checking :p

interface PluginStorage {

/**

 Returns plugin data.

 @param object $plugin The plugin object getting its data.

 @param string | null $key The storage key, if null will return all data for the plugin.

 @param string $model Name of a model in case its model specific plugin data, like for a specific question or survey.

 @param int $id Id of the model for which the data is retreived

 @return mixed The data stored.
*/

public function get($plugin, $key = null, $model = null, $id = null);

/**

 Stores plugin data.

 @param object $plugin The plugin object getting its data.

 @param string $key The storage key to identify the data.

 @param mixed $data The data to be stored, serialized using serialize.

 @param string $model Name of a model in case its model specific plugin data, like for a specific question or survey.

 @param int $id Id of the model for which the data is retreived
*/

public function set ($plugin, $key, $data, $model = null, $id = null);

}

class PluginBase {

   protected $storage = 'PluginStorage';

   private $store = null;

   public function '''construct()

   {

       $this->store = Plugin::getStore($this->storage);

   }

   /**

     This function stores plugin data.

   */

   protected function set($key, $data, $model = null, $id = null)

   {

       if (isset($this->store))

       {

           return $this->store->set($this, $key, $model, $id);

       }

       return false;

   }

   /**

     This function retrieves plugin data. Do not cache this data; the plugin storage

     engine will handling caching. After the first call to this function, subsequent

     calls will only consist of a few function calls and array lookups.

   */

   protected function get($key = null, $model = null, $id = null)

   {

       if (isset($this->store))

       {

           return $this->store->get($this, $key, $model, $id);

       }

       return false;

   }

}