PHP Class Gdn_PluginManager, vanilla

A singleton class used to identify extensions, register them in a central location, and instantiate/call them when necessary.
Inheritance: extends Gdn_Pluggable
Datei anzeigen Open project: vanilla/vanilla Class Usage Examples

Public Properties

Property Type Description
$trace Whether or not to trace some event information.

Protected Properties

Property Type Description
$alternatePluginSearchPaths
$enabledPlugins A simple list of enabled plugins.
$instances An array of the instances of plugins.
$pluginCache Available plugins. Never access this directly, instead use $this->AvailablePlugins();
$pluginFoldersByPath array
$pluginSearchPaths Search paths for plugins and their files.
$pluginsByClass array

Public Methods

Method Description
__construct ( AddonManager $addonManager = null ) Initialize a new instance of the {@link Gdn_PluginManager} class.
addSearchPath ( ) : boolean TODO: Remove this.
availablePluginFolders ( null $SearchPath = null ) : array | mixed
availablePlugins ( ) Get a list of available plugins.
calcOldInfoArray ( Addon $addon ) : array Calculate an old info array from a new {@link Addon}.
callEventHandler ( object $Sender, string $EventClassName, string $EventName, string $EventHandlerType = 'Handler', array $Options = [] ) : mixed Call a single event handler.
callEventHandlers ( object $Sender, string $EventClassName, string $EventName, string $EventHandlerType = 'Handler' ) : boolean Transfer control to the plugins.
callMethodOverride ( object $Sender, string $ClassName, string $MethodName ) : mixed Looks through $this->_MethodOverrideCollection for a matching method signature to override.
callNewMethod ( object $Sender, string $ClassName, string $MethodName ) : mixed Looks through the registered new methods for a matching method signature to call.
checkPlugin ( string $pluginName ) : boolean Check whether a plugin is enabled.
clearPluginCache ( ) The {@link AddonManager} does all this now.
disablePlugin ( string $pluginName ) : boolean Disable a plugin.
enablePlugin ( $pluginName, Gdn_Validation $validation, boolean $setup = true ) : boolean
enabledPluginFolders ( null $SearchPath = null ) : array
enabledPlugins ( ) : array Get a list of all of the enabled plugins.
findPluginFile ( string $path ) : string | false Deprecated.
forceAutoloaderIndex ( ) The {@link AddonManager} does all this now.
getCallback ( string $ClassName, string $MethodName, string $Type = 'Create' ) : callback Get the callback for an event handler.
getEventHandlers ( $Sender, $EventName, string $HandlerType = 'Handler', array $Options = [] ) : array
getPluginInfo ( string $name, string $accessType = self::ACCESS_PLUGINNAME ) : boolean | array Get the information array for a plugin.
getPluginInstance ( string $name, string $accessType = self::ACCESS_CLASSNAME, mixed $sender = null ) : Gdn_IPlugin Gets an instance of a given plugin.
hasMethodOverride ( string $ClassName, string $MethodName ) : boolean Checks to see if there are any plugins that override the method being executed.
hasNewMethod ( string $ClassName, string $MethodName ) : boolean Checks to see if there are any plugins that create the method being executed.
includePlugins ( ) Includes all of the plugin files for enabled plugins.
indexSearchPath ( string $SearchPath, &$PluginInfo, &$ClassInfo, array | null $PathListing = null ) : boolean | string TODO: Remove this method.
isEnabled ( string $Name ) : boolean Returns whether or not a plugin is enabled.
registerCallback ( string $eventName, callable $callback ) Register a a callback to handle an event.
registerHandler ( string $HandlerClassName, string $HandlerMethodName, string $EventClassName = '', string $EventName = '', string $EventHandlerType = '' ) Registers a plugin method name as a handler.
registerNewMethod ( string $NewMethodClassName, string $NewMethodName, string $EventClassName = '', string $EventName = '' ) Registers a plugin new method.
registerOverride ( string $OverrideClassName, string $OverrideMethodName, string $EventClassName = '', string $EventName = '' ) Registers a plugin override method.
registerPlugin ( $ClassName )
registerPlugins ( ) Register all enabled plugins' event handlers and overrides.
registeredPlugins ( ) : array
removeMobileUnfriendlyPlugins ( ) Removes all plugins that are marked as mobile unfriendly.
removeSearchPath ( ) : boolean TODO: Remove this.
scanPluginFile ( $PluginFile, null $VariableName = null ) : null | void
searchPaths ( boolean $OnlyCustom = false ) : array Get the current search paths
splitAuthors ( string $authorsString, string $format = 'html' ) : array | string Split a string containing several authors.
start ( ) Set up the plugin framework.
started ( ) : boolean Is the plugin manager started?
testPlugin ( string $PluginName ) Test to see if a plugin throws fatal errors.
unregisterPlugin ( $PluginClassName ) : boolean

Private Methods

Method Description
enableAddon ( Addon $addon, boolean $setup ) Enable an addon and do all the stuff that's entailed there.
findPluginFileOld ( string $path ) : string | false Find a plugin file using the old plugin manager method.
pluginHook ( string $pluginName, string $forAction, boolean $callback = false ) : void Hooks to the various actions, i.e. enable, disable and load.
removeFromCollectionByPrefix ( $Prefix, &$Collection )
trace ( string $Message, string $Type = TRACE_INFO ) Trace a message when tracing is turned on.

Method Details

__construct() public method

Initialize a new instance of the {@link Gdn_PluginManager} class.
public __construct ( AddonManager $addonManager = null )
$addonManager Vanilla\AddonManager The addon manager that manages all of the addons.

addSearchPath() public method

TODO: Remove this.
public addSearchPath ( ) : boolean
return boolean Deprecated.

availablePluginFolders() public method

public availablePluginFolders ( null $SearchPath = null ) : array | mixed
$SearchPath null
return array | mixed

availablePlugins() public method

Get a list of available plugins.
Deprecation: Use {@link AddonManager::lookupAllByType()}.
public availablePlugins ( )

calcOldInfoArray() public static method

This is a backwards compatibility function only and should not be used for new code.
Deprecation:
public static calcOldInfoArray ( Addon $addon ) : array
$addon Vanilla\Addon The addon to calculate.
return array Returns an info array.

callEventHandler() public method

Call a single event handler.
public callEventHandler ( object $Sender, string $EventClassName, string $EventName, string $EventHandlerType = 'Handler', array $Options = [] ) : mixed
$Sender object The object firing the event.
$EventClassName string The name of the class firing the event.
$EventName string The name of the event being fired.
$EventHandlerType string The type of event handler being looked for.
$Options array An array of options to modify the call.
return mixed Returns whatever the event handler returns or **false** of there is not event handler.

callEventHandlers() public method

Looks through $this->_EventHandlerCollection for matching event signatures to handle. If it finds any, it executes them in the order it found them. It instantiates any plugins and adds them as properties to this class (unless they were previously instantiated), and then calls the handler in question.
public callEventHandlers ( object $Sender, string $EventClassName, string $EventName, string $EventHandlerType = 'Handler' ) : boolean
$Sender object The object that fired the event being handled.
$EventClassName string The name of the class that fired the event being handled.
$EventName string The name of the event being fired.
$EventHandlerType string The type of handler being fired (Handler, Before, After).
return boolean Returns **true** if an event was executed.

callMethodOverride() public method

It instantiates any plugins and adds them as properties to this class (unless they were previously instantiated), then calls the method in question.
public callMethodOverride ( object $Sender, string $ClassName, string $MethodName ) : mixed
$Sender object The object being worked on.
$ClassName string The name of the class that called the method being overridden.
$MethodName string The name of the method that is being overridden.
return mixed Returns the value of overridden method.

callNewMethod() public method

It instantiates any plugins and adds them as properties to this class (unless they were previously instantiated), then calls the method in question.
public callNewMethod ( object $Sender, string $ClassName, string $MethodName ) : mixed
$Sender object The object being worked on.
$ClassName string The name of the class that called the method being created.
$MethodName string The name of the method that is being created.
return mixed Return value of new method.

checkPlugin() public method

Check whether a plugin is enabled.
Deprecation: Use {@link AddonManager::isEnabled()} instead.
public checkPlugin ( string $pluginName ) : boolean
$pluginName string The name of the plugin.
return boolean Returns **true** if the plugin is enabled or **false** otherwise.

clearPluginCache() public method

The {@link AddonManager} does all this now.
Deprecation:
public clearPluginCache ( )

disablePlugin() public method

Disable a plugin.
public disablePlugin ( string $pluginName ) : boolean
$pluginName string The name of the plugin.
return boolean

enablePlugin() public method

public enablePlugin ( $pluginName, Gdn_Validation $validation, boolean $setup = true ) : boolean
$pluginName
$validation Gdn_Validation
$setup boolean
return boolean

enabledPluginFolders() public method

public enabledPluginFolders ( null $SearchPath = null ) : array
$SearchPath null
return array

enabledPlugins() public method

Get a list of all of the enabled plugins.
public enabledPlugins ( ) : array
return array

findPluginFile() public method

Deprecated.
public findPluginFile ( string $path ) : string | false
$path string Deprecated.
return string | false Deprecated.

forceAutoloaderIndex() public method

The {@link AddonManager} does all this now.
Deprecation:

getCallback() public method

Get the callback for an event handler.
Since: 2.1
public getCallback ( string $ClassName, string $MethodName, string $Type = 'Create' ) : callback
$ClassName string The name of the class throwing the event.
$MethodName string The name of the event.
$Type string The type of event handler. - Create: A new method creation. - Override: A method override.
return callback

getEventHandlers() public method

public getEventHandlers ( $Sender, $EventName, string $HandlerType = 'Handler', array $Options = [] ) : array
$Sender
$EventName
$HandlerType string
$Options array
return array

getPluginInfo() public method

Get the information array for a plugin.
Deprecation:
public getPluginInfo ( string $name, string $accessType = self::ACCESS_PLUGINNAME ) : boolean | array
$name string The name of the plugin to access.
$accessType string Either **Gdn_PluginManager::ACCESS_CLASSNAME** or Gdn_PluginManager::ACCESS_PLUGINNAME** (default).
return boolean | array Returns an info array or **false** if the plugin isn't found.

getPluginInstance() public method

Gets an instance of a given plugin.
public getPluginInstance ( string $name, string $accessType = self::ACCESS_CLASSNAME, mixed $sender = null ) : Gdn_IPlugin
$name string The key of the plugin.
$accessType string The type of key for the plugin which must be one of the following: - Gdn_PluginManager::ACCESS_PLUGINNAME - Gdn_PluginManager::ACCESS_CLASSNAME
$sender mixed An object to pass to a new plugin instantiation.
return Gdn_IPlugin The plugin instance.

hasMethodOverride() public method

Checks to see if there are any plugins that override the method being executed.
public hasMethodOverride ( string $ClassName, string $MethodName ) : boolean
$ClassName string The name of the class that called the method being overridden.
$MethodName string The name of the method that is being overridden.
return boolean Returns **true** if an override exists or **false** otherwise.

hasNewMethod() public method

Checks to see if there are any plugins that create the method being executed.
public hasNewMethod ( string $ClassName, string $MethodName ) : boolean
$ClassName string The name of the class that called the method being created.
$MethodName string The name of the method that is being created.
return boolean Returns **true** if the method exists.

includePlugins() public method

Files are included in from the roots of each plugin directory if they have the following names. - default.php - *plugin.php
Deprecation:
public includePlugins ( )

indexSearchPath() public method

TODO: Remove this method.
Deprecation:
public indexSearchPath ( string $SearchPath, &$PluginInfo, &$ClassInfo, array | null $PathListing = null ) : boolean | string
$SearchPath string Deprecated.
$PathListing array | null Deprecated.
return boolean | string Deprecated.

isEnabled() public method

Returns whether or not a plugin is enabled.
Deprecation:
public isEnabled ( string $Name ) : boolean
$Name string The name of the plugin.
return boolean Whether or not the plugin is enabled.

registerCallback() public method

Register a a callback to handle an event.
public registerCallback ( string $eventName, callable $callback )
$eventName string The name of the event to register.
$callback callable The callback to call when the event is fired.

registerHandler() public method

Registers a plugin method name as a handler.
public registerHandler ( string $HandlerClassName, string $HandlerMethodName, string $EventClassName = '', string $EventName = '', string $EventHandlerType = '' )
$HandlerClassName string The name of the plugin class that will handle the event.
$HandlerMethodName string The name of the plugin method being registered to handle the event.
$EventClassName string The name of the class that will fire the event.
$EventName string The name of the event that will fire.
$EventHandlerType string The type of event handler.

registerNewMethod() public method

Registers a plugin new method.
public registerNewMethod ( string $NewMethodClassName, string $NewMethodName, string $EventClassName = '', string $EventName = '' )
$NewMethodClassName string The name of the plugin class that will add a new method.
$NewMethodName string The name of the plugin method being added.
$EventClassName string The name of the class that will fire the event.
$EventName string The name of the event that will fire.

registerOverride() public method

Registers a plugin override method.
public registerOverride ( string $OverrideClassName, string $OverrideMethodName, string $EventClassName = '', string $EventName = '' )
$OverrideClassName string The name of the plugin class that will override the existing method.
$OverrideMethodName string The name of the plugin method being registered to override the existing method.
$EventClassName string The name of the class that will fire the event.
$EventName string The name of the event that will fire.

registerPlugin() public method

public registerPlugin ( $ClassName )
$ClassName

registerPlugins() public method

Examines all declared classes, identifying which ones implement Gdn_IPlugin and registers all of their event handlers and method overrides. It recognizes them because Handlers end with _Handler, _Before, and _After and overrides end with "_Override". They are prefixed with the name of the class and method (or event) to be handled or overridden. For example: class MyPlugin implements Gdn_IPlugin { public function MyController_SignIn_After($Sender) { Do something neato } public function Url_AppRoot_Override($WithDomain) { return "MyCustomAppRoot!"; } }
public registerPlugins ( )

registeredPlugins() public method

public registeredPlugins ( ) : array
return array

removeMobileUnfriendlyPlugins() public method

Removes all plugins that are marked as mobile unfriendly.

removeSearchPath() public method

TODO: Remove this.
public removeSearchPath ( ) : boolean
return boolean Deprecated.

scanPluginFile() public method

public scanPluginFile ( $PluginFile, null $VariableName = null ) : null | void
$PluginFile
$VariableName null
return null | void

searchPaths() public method

By default, get all the paths as built by the constructor. Includes the two (or one) default plugin paths of PATH_PLUGINS and PATH_LOCAL_PLUGINS, as well as any extra paths defined in the config variable.
public searchPaths ( boolean $OnlyCustom = false ) : array
$OnlyCustom boolean whether or not to exclude the two default paths and return only config paths
return array Search paths

splitAuthors() public static method

Split a string containing several authors.
Deprecation: The authors array is already properly split in the {@link Addon}.
public static splitAuthors ( string $authorsString, string $format = 'html' ) : array | string
$authorsString string The author string.
$format string What format to return the result in.
return array | string Returns the authors as an array or string if HTML is requested.

start() public method

Set up the plugin framework.
public start ( )

started() public method

Is the plugin manager started?
public started ( ) : boolean
return boolean Returns **true** if the plugin manager is started or **false** otherwise.

testPlugin() public method

Test to see if a plugin throws fatal errors.
Deprecation:
public testPlugin ( string $PluginName )
$PluginName string The name of the plugin to test.

unregisterPlugin() public method

public unregisterPlugin ( $PluginClassName ) : boolean
$PluginClassName
return boolean

Property Details

$alternatePluginSearchPaths protected_oe property

protected $alternatePluginSearchPaths

$enabledPlugins protected_oe property

A simple list of enabled plugins.
protected $enabledPlugins

$instances protected_oe property

An array of the instances of plugins.
protected $instances

$pluginCache protected_oe property

Available plugins. Never access this directly, instead use $this->AvailablePlugins();
protected $pluginCache

$pluginFoldersByPath protected_oe property

protected array $pluginFoldersByPath
return array

$pluginSearchPaths protected_oe property

Search paths for plugins and their files.
protected $pluginSearchPaths

$pluginsByClass protected_oe property

protected array $pluginsByClass
return array

$trace public_oe property

Whether or not to trace some event information.
public $trace