Omeka_Plugin_Broker¶
Package: Plugin\Broker
-
class
Omeka_Plugin_Broker
¶ Plugin Broker for Omeka.
For example, $broker->callHook(‘add_action_contexts’, array(‘controller’ => $controller)) would call the ‘add_action_contexts’ on all plugins, and it would provide the controller object as the first argument to all implementations of that hook.
-
property
_callbacks
¶ protected array
Array of hooks that have been implemented for plugins.
-
property
_filters
¶ protected array
Stores all defined filters.
Storage in array where $_filters[‘filterName’][‘priority’][‘plugin’] = $hook;
-
property
_current
¶ protected string
The directory name of the current plugin (used for calling hooks)
-
addHook
($hook, $callback, $plugin = null)¶ Add a hook implementation for a plugin.
Parameters: - $hook (string) – Name of the hook being implemented.
- $callback (string) – PHP callback for the hook implementation.
- $plugin (string|null) – Optional name of the plugin for which to add the hook. If omitted, the current plugin is used.
-
getHook
($pluginDirName, $hook)¶ Get the hook implementation for a plugin.
Parameters: - $pluginDirName (string) – Name of the plugin to get the implementation from.
- $hook (string) – Name of the hook to get the implementation for.
Returns: callback|null
-
setCurrentPluginDirName
($pluginDirName)¶ Set the currently-focused plugin by directory name.
The plugin helper functions do not have any way of determining what plugin to is currently in focus. These get/setCurrentPluginDirName methods allow the broker to know how to delegate to specific plugins if necessary.
Parameters: - $pluginDirName (string) – Plugin to set as current.
-
getCurrentPluginDirName
()¶ Get the directory name of the currently-focused plugin.
Returns: string
-
callHook
($name, $args = array(), $plugin = null)¶ Call a hook by name.
Hooks can either be called globally or for a specific plugin only.
Parameters: - $name (string) – The name of the hook.
- $args (array) – Arguments to be passed to the hook implementations.
- $plugin (Plugin|string) – Name of the plugin that will invoke the hook.
-
addFilter
($name, $callback, $priority = 10)¶ Add a filter implementation.
Parameters: - $name (string|array) – Name of filter being implemented.
- $callback (callback) – PHP callback for filter implementation.
- $priority –
-
_getFilterNamespace
()¶ Retrieve the namespace to use for the filter to be added.
Returns: string Name of the current plugin (if applicable). Otherwise, a magic constant that denotes globally applied filters.
-
_getFilterKey
($name)¶ Retrieve the key used for indexing the filter. The filter name should be either a string or an array of strings. If the filter name is an object, that might cause fiery death when using the serialized value for an array key.
Parameters: - $name (string|array) – Filter name.
Returns: string Key for filter indexing.
-
getFilters
($hookName)¶ Return all the filters for a specific hook in the correct order of execution.
Parameters: - $hookName (string|array) – Filter name.
Returns: array Indexed array of filter callbacks.
-
clearFilters
($name = null)¶ Clear all implementations for a filter (or all filters).
Parameters: - $name (string|null) – The name of the filter to clear. If null or omitted, all filters will be cleared.
-
applyFilters
($name, $value, $args = array())¶ Run an arbitrary value through a set of filters.
Parameters: - $name (mixed) – The filter name.
- $value (mixed) – The value to filter.
- $args (array) – Additional arguments to pass to filter implementations.
Returns: mixed Result of applying filters to $value.
-
register
()¶ Register the plugin broker so that plugin writers can use global functions like add_plugin_hook() to interact with the plugin API.
-
property