LimeSurvey API - Master branch

PluginManager extends CApplicationComponent
in package

Factory for limesurvey plugin objects.

Table of Contents

Properties

$api  : mixed
Object containing any API that the plugins can use.
$pluginDirs  : array<string|int, mixed>
$shutdownObject  : PluginManagerShutdownFunction
Created at init.
$guidToQuestion  : array<string|int, mixed>
Array mapping guids to question object class names.
$plugins  : array<string|int, mixed>
$stores  : array<string|int, mixed>
$subscriptions  : array<string, array<string|int, mixed>>

Methods

dispatchEvent()  : mixed
dispatchEvent()  : PluginEvent
This function dispatches an event to all registered plugins.
getAPI()  : LimesurveyApi
This function returns an API object, exposing an API to each plugin.
getInstalledPlugins()  : array<string|int, mixed>
Return a list of installed plugins, but only if the files are still there
getPluginFolder()  : mixed
getPluginInfo()  : array<string|int, mixed>|null
Gets the description of a plugin. The description is accessed via a static function inside the plugin file.
getStore()  : mixed
Returns the storage instance of type $storageClass.
init()  : void
Creates the plugin manager. Loads all active plugins.
installPlugin()  : array<string|int, mixed>
Install a plugin given a plugin configuration and plugin type (core or user).
installUploadedPlugin()  : array<string|int, mixed>
isPluginActive()  : bool
Return the status of plugin (true/active or false/desactive)
isWhitelisted()  : bool
Returns true if the plugin name is allowlisted or the allowlist is disabled.
loadAllPlugins()  : void
Load ALL plugins, active and non-active
loadPlugin()  : iPlugin|null
Returns the instantiated plugin
loadPlugins()  : mixed
Handles loading all active plugins
loadQuestionObjects()  : mixed
Get a list of question objects and load some information about them.
readConfigFiles()  : void
Read all plugin config files and updates information in database if plugin version differs.
scanPlugins()  : array<string|int, mixed>
Scans the plugin directory for plugins.
subscribe()  : mixed
Registers a plugin to be notified on some event.
unsubscribe()  : mixed
Unsubscribes a plugin from an event.
getPluginDescription()  : string
Get plugin description.
getPluginName()  : string
Get plugin name.
getAllowedCorePluginList()  : array<string|int, string>
Return the list of core plugins allowed to be loaded.
getCorePluginList()  : array<string|int, string>
Return the core plugin list No way to update by php or DB

Properties

$api

Object containing any API that the plugins can use.

public mixed $api

The class name of the API class to load, or

$pluginDirs

public array<string|int, mixed> $pluginDirs = [ // User plugins installed through command line. 'user' => 'webroot.plugins', // Core plugins. 'core' => 'application.core.plugins', // Uploaded plugins installed through ZIP file. 'upload' => 'uploaddir.plugins', ]

$guidToQuestion

Array mapping guids to question object class names.

protected array<string|int, mixed> $guidToQuestion = []

$subscriptions

protected array<string, array<string|int, mixed>> $subscriptions = []

Array with string key to tuple value like 'eventName' => array($plugin, $method)

Methods

dispatchEvent()

This function dispatches an event to all registered plugins.

public dispatchEvent(PluginEvent $event[, string|array<string|int, mixed> $target = array() ]) : PluginEvent
Parameters
$event : PluginEvent

Object holding all event properties

$target : string|array<string|int, mixed> = array()

Optional name of plugin to fire the event on

Return values
PluginEvent

getInstalledPlugins()

Return a list of installed plugins, but only if the files are still there

public getInstalledPlugins() : array<string|int, mixed>
Tags
deprecated

unused in 5.3.8 This prevents errors when a plugin was installed but the files were removed from the server.

Return values
array<string|int, mixed>

getPluginInfo()

Gets the description of a plugin. The description is accessed via a static function inside the plugin file.

public getPluginInfo(string $pluginClass[, mixed $pluginDir = null ]) : array<string|int, mixed>|null
Parameters
$pluginClass : string

The classname of the plugin

$pluginDir : mixed = null
Tags
todo

Read config.xml instead.

Return values
array<string|int, mixed>|null

getStore()

Returns the storage instance of type $storageClass.

public getStore(string $storageClass) : mixed

If needed initializes the storage object.

Parameters
$storageClass : string

init()

Creates the plugin manager. Loads all active plugins.

public init() : void

If $plugin->save() is used in this method, it can lead to an infinite event loop, since beforeSave tries to get the PluginManager, which executes init() again.

installPlugin()

Install a plugin given a plugin configuration and plugin type (core or user).

public installPlugin(ExtensionConfig $extensionConfig, string $pluginType) : array<string|int, mixed>
Parameters
$extensionConfig : ExtensionConfig
$pluginType : string

'user' or 'core', depending on location of folder.

Return values
array<string|int, mixed>

[boolean $result, string $errorMessage]

installUploadedPlugin()

public installUploadedPlugin(string $destdir) : array<string|int, mixed>
Parameters
$destdir : string
Return values
array<string|int, mixed>

[boolean $result, string $errorMessage]

isPluginActive()

Return the status of plugin (true/active or false/desactive)

public isPluginActive(mixed $sPluginName) : bool
Parameters
$sPluginName : mixed
Return values
bool

isWhitelisted()

Returns true if the plugin name is allowlisted or the allowlist is disabled.

public isWhitelisted(string $pluginName) : bool
Parameters
$pluginName : string
Return values
bool

loadAllPlugins()

Load ALL plugins, active and non-active

public loadAllPlugins() : void

loadPlugin()

Returns the instantiated plugin

public loadPlugin(string $pluginName[, int $id = null ][, bool $init = true ]) : iPlugin|null
Parameters
$pluginName : string
$id : int = null

Identifier used for identifying a specific plugin instance.

$init : bool = true

launch init function (if exist) If ommitted will return the first instantiated plugin with the given name.

Return values
iPlugin|null

The plugin or null when missing

loadPlugins()

Handles loading all active plugins

public loadPlugins() : mixed

Possible improvement would be to load them for a specific context. For instance 'survey' for runtime or 'admin' for backend. This needs some thinking before implementing.

loadQuestionObjects()

Get a list of question objects and load some information about them.

public loadQuestionObjects([mixed $forceReload = false ]) : mixed

This registers the question object classes with Yii.

Parameters
$forceReload : mixed = false

readConfigFiles()

Read all plugin config files and updates information in database if plugin version differs.

public readConfigFiles() : void

scanPlugins()

Scans the plugin directory for plugins.

public scanPlugins([bool $includeInstalledPlugins = false ]) : array<string|int, mixed>

This function is not efficient so should only be used in the admin interface that specifically deals with enabling / disabling plugins.

Parameters
$includeInstalledPlugins : bool = false

If set, also return plugins even if already installed in database.

Tags
todo

Factor out

Return values
array<string|int, mixed>

subscribe()

Registers a plugin to be notified on some event.

public subscribe(iPlugin $plugin, string $event[, string $function = null ]) : mixed
Parameters
$plugin : iPlugin

Reference to the plugin.

$event : string

Name of the event.

$function : string = null

Optional function of the plugin to be called.

unsubscribe()

Unsubscribes a plugin from an event.

public unsubscribe(iPlugin $plugin, string $event) : mixed
Parameters
$plugin : iPlugin

Reference to the plugin being unsubscribed.

$event : string

Name of the event. Use '*', to unsubscribe all events for the plugin.

getPluginDescription()

Get plugin description.

protected getPluginDescription(string $class[, ExtensionConfig $extensionConfig = null ]) : string

First look in config.xml, then in plugin class.

Parameters
$class : string
$extensionConfig : ExtensionConfig = null
Tags
todo

Localization.

Return values
string

getPluginName()

Get plugin name.

protected getPluginName(string $class[, ExtensionConfig $extensionConfig = null ]) : string

First look in config.xml, then in plugin class.

Parameters
$class : string
$extensionConfig : ExtensionConfig = null
Tags
todo

Localization.

Return values
string

getAllowedCorePluginList()

Return the list of core plugins allowed to be loaded.

private getAllowedCorePluginList() : array<string|int, string>

That is, all core plugins not in the blocklist.

Return values
array<string|int, string>

getCorePluginList()

Return the core plugin list No way to update by php or DB

private static getCorePluginList() : array<string|int, string>
Return values
array<string|int, string>

        
On this page

Search results