CWIS Developer Documentation
Plugin.php
Go to the documentation of this file.
1 <?PHP
2 #
3 # FILE: PluginManager.php
4 #
5 # Part of the ScoutLib application support library
6 # Copyright 2009-2013 Edward Almasy and Internet Scout Research Group
7 # http://scout.wisc.edu
8 #
9 
13 abstract class Plugin {
14 
15  # ----- PUBLIC INTERFACE -------------------------------------------------
16 
24  abstract function Register();
25 
36  function SetUpConfigOptions()
37  {
38  return NULL;
39  }
40 
49  function Initialize()
50  {
51  return NULL;
52  }
53 
61  function HookEvents()
62  {
63  return array();
64  }
65 
73  function DeclareEvents()
74  {
75  return array();
76  }
77 
84  function Install()
85  {
86  return NULL;
87  }
88 
97  function Upgrade($PreviousVersion)
98  {
99  return NULL;
100  }
101 
107  function Uninstall()
108  {
109  return NULL;
110  }
111 
116  final function GetAttributes()
117  {
118  return array(
119  "Author" => $this->Author,
120  "CfgPage" => $this->CfgPage,
121  "CfgSetup" => $this->CfgSetup,
122  "Description" => $this->Description,
123  "Email" => $this->Email,
124  "EnabledByDefault" => $this->EnabledByDefault,
125  "InitializeAfter" => is_array($this->InitializeAfter)
126  ? $this->InitializeAfter : array($this->InitializeAfter),
127  "InitializeBefore" => is_array($this->InitializeBefore)
128  ? $this->InitializeBefore : array($this->InitializeBefore),
129  "Instructions" => $this->Instructions,
130  "Name" => $this->Name,
131  "Requires" => $this->Requires,
132  "Url" => $this->Url,
133  "Version" => $this->Version,
134  );
135  }
136 
144  final function ConfigSetting($SettingName, $NewValue = NULL)
145  {
146  # if a new value was supplied for the setting
147  if (func_num_args() > 1)
148  {
149  # if this setting has a filter function specified
150  if (array_key_exists($SettingName, $this->CfgSetup)
151  && array_key_exists("SettingFilter",
152  $this->CfgSetup[$SettingName]))
153  {
154  # pass new value through filter function
155  $FilterMethod = $this->CfgSetup[$SettingName]["SettingFilter"];
156  $NewValue = $this->$FilterMethod($SettingName, $NewValue);
157  }
158 
159  # if caller requested that setting be cleared
160  if ($NewValue === NULL)
161  {
162  # clear setting
163  unset($this->Cfg[$SettingName]);
164  }
165  else
166  {
167  # save new value for setting
168  $this->Cfg[$SettingName] = $NewValue;
169  }
170 
171  # if we have a way of saving configuration settings
172  if (is_callable($this->CfgSaveCallback))
173  {
174  # save new configuration settings
175  call_user_func_array($this->CfgSaveCallback,
176  array(get_class($this), $this->Cfg));
177  }
178  }
179 
180  # return current value of setting to caller
181  return isset($this->Cfg[$SettingName]) ? $this->Cfg[$SettingName] : NULL;
182  }
183 
184 
185  # ----- PROTECTED INTERFACE ----------------------------------------------
186 
188  protected $Author = NULL;
190  protected $Description = NULL;
192  protected $Email = NULL;
194  protected $EnabledByDefault = FALSE;
196  protected $InitializeBefore = array();
198  protected $InitializeAfter = array();
202  protected $Instructions = NULL;
204  protected $Name = NULL;
206  protected $Version = NULL;
208  protected $Url = NULL;
209 
217  protected $Requires = array();
218 
226  protected $CfgSetup = array();
227 
231  protected $CfgPage = NULL;
232 
233 
234  # ----- PRIVATE INTERFACE ------------------------------------------------
235 
237  private $Cfg;
239  private $CfgSaveCallback;
240 
246  final public function SetAllCfg($NewValues)
247  {
248  $this->Cfg = $NewValues;
249  }
258  final public function SetCfgSaveCallback($Callback)
259  {
260  $this->CfgSaveCallback = $Callback;
261  }
263 }
264 
265 
Install()
Perform any work needed when the plugin is first installed (for example, creating database tables)...
Definition: Plugin.php:84
$InitializeAfter
Plugins that should be initialized before us.
Definition: Plugin.php:198
$Email
Contact email for the plugin's author.
Definition: Plugin.php:192
Register()
Set the plugin attributes.
Upgrade($PreviousVersion)
Perform any work needed when the plugin is upgraded to a new version (for example, adding fields to database tables).
Definition: Plugin.php:97
$EnabledByDefault
Whether the plugin should be enabled by default when installed.
Definition: Plugin.php:194
$Version
Version number of plugin in the format X.X.X (for example: 1.2.12).
Definition: Plugin.php:206
$Author
Name of the plugin's author.
Definition: Plugin.php:188
$InitializeBefore
Plugins that should be initialized after us.
Definition: Plugin.php:196
HookEvents()
Hook methods to be called when specific events occur.
Definition: Plugin.php:61
Electronic mail message.
Definition: Email.php:14
$CfgSetup
Associative array describing the configuration values for the plugin.
Definition: Plugin.php:226
$Requires
Array with plugin base (class) names for the index and minimum version numbers for the values...
Definition: Plugin.php:217
SetUpConfigOptions()
Set up plugin configuration options.
Definition: Plugin.php:36
DeclareEvents()
Declare events defined by this plugin.
Definition: Plugin.php:73
Base class for all plugins.
Definition: Plugin.php:13
GetAttributes()
Retrieve plugin information.
Definition: Plugin.php:116
$CfgPage
Name of configuration page for plugin.
Definition: Plugin.php:231
$Description
Text description of the plugin.
Definition: Plugin.php:190
$Name
Proper (human-readable) name of plugin.
Definition: Plugin.php:204
Initialize()
Initialize the plugin.
Definition: Plugin.php:49
$Url
Web address for more information about the plugin.
Definition: Plugin.php:208
ConfigSetting($SettingName, $NewValue=NULL)
Get/set plugin configuration setting.
Definition: Plugin.php:144
$Instructions
Instructions for configuring the plugin (displayed on the automatically-generated configuration page ...
Definition: Plugin.php:202
Uninstall()
Perform any work needed when the plugin is uninstalled.
Definition: Plugin.php:107