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
Afficher le fichier Open project: vanilla/vanilla Class Usage Examples

Méthodes publiques

Свойство Type Description
$trace Whether or not to trace some event information.

Protected Properties

Свойство 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

Méthodes publiques

Méthode 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

Méthode 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 méthode

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 méthode

TODO: Remove this.
public addSearchPath ( ) : boolean
Résultat boolean Deprecated.

availablePluginFolders() public méthode

public availablePluginFolders ( null $SearchPath = null ) : array | mixed
$SearchPath null
Résultat array | mixed

availablePlugins() public méthode

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

calcOldInfoArray() public static méthode

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.
Résultat array Returns an info array.

callEventHandler() public méthode

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.
Résultat mixed Returns whatever the event handler returns or **false** of there is not event handler.

callEventHandlers() public méthode

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).
Résultat boolean Returns **true** if an event was executed.

callMethodOverride() public méthode

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.
Résultat mixed Returns the value of overridden method.

callNewMethod() public méthode

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.
Résultat mixed Return value of new method.

checkPlugin() public méthode

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

clearPluginCache() public méthode

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

disablePlugin() public méthode

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

enablePlugin() public méthode

public enablePlugin ( $pluginName, Gdn_Validation $validation, boolean $setup = true ) : boolean
$pluginName
$validation Gdn_Validation
$setup boolean
Résultat boolean

enabledPluginFolders() public méthode

public enabledPluginFolders ( null $SearchPath = null ) : array
$SearchPath null
Résultat array

enabledPlugins() public méthode

Get a list of all of the enabled plugins.
public enabledPlugins ( ) : array
Résultat array

findPluginFile() public méthode

Deprecated.
public findPluginFile ( string $path ) : string | false
$path string Deprecated.
Résultat string | false Deprecated.

forceAutoloaderIndex() public méthode

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

getCallback() public méthode

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.
Résultat callback

getEventHandlers() public méthode

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

getPluginInfo() public méthode

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).
Résultat boolean | array Returns an info array or **false** if the plugin isn't found.

getPluginInstance() public méthode

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.
Résultat Gdn_IPlugin The plugin instance.

hasMethodOverride() public méthode

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.
Résultat boolean Returns **true** if an override exists or **false** otherwise.

hasNewMethod() public méthode

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.
Résultat boolean Returns **true** if the method exists.

includePlugins() public méthode

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 méthode

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

isEnabled() public méthode

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

registerCallback() public méthode

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 méthode

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 méthode

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 méthode

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 méthode

public registerPlugin ( $ClassName )
$ClassName

registerPlugins() public méthode

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 méthode

public registeredPlugins ( ) : array
Résultat array

removeMobileUnfriendlyPlugins() public méthode

Removes all plugins that are marked as mobile unfriendly.

removeSearchPath() public méthode

TODO: Remove this.
public removeSearchPath ( ) : boolean
Résultat boolean Deprecated.

scanPluginFile() public méthode

public scanPluginFile ( $PluginFile, null $VariableName = null ) : null | void
$PluginFile
$VariableName null
Résultat null | void

searchPaths() public méthode

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
Résultat array Search paths

splitAuthors() public static méthode

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.
Résultat array | string Returns the authors as an array or string if HTML is requested.

start() public méthode

Set up the plugin framework.
public start ( )

started() public méthode

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

testPlugin() public méthode

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 méthode

public unregisterPlugin ( $PluginClassName ) : boolean
$PluginClassName
Résultat 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
Résultat array

$pluginSearchPaths protected_oe property

Search paths for plugins and their files.
protected $pluginSearchPaths

$pluginsByClass protected_oe property

protected array $pluginsByClass
Résultat array

$trace public_oe property

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