Omeka_Plugin_Broker

class Omeka_Plugin_Broker

Package: 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 thecontroller object as the first argument to all implementations of that hook.

property _callbacks

Array of hooks that have been implemented for plugins.

property _filters

Stores all defined filters.

Storage in array where $_filters[‘filterName’][‘priority’][‘plugin’] = $hook;

property _current

The directory name of the current plugin (used for calling hooks)

addHook(string $hook, string $callback, string|null $plugin)

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.
Returns:

void

getHook(string $pluginDirName, string $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(string $pluginDirName)

Set the currently-focused plugin by directory name.

The plugin helper functions do not have any way of determining whatplugin to is currently in focus. These get/setCurrentPluginDirNamemethods allow the broker to know how to delegate to specific plugins ifnecessary.

Parameters:
  • $pluginDirName (string) – Plugin to set as current.
Returns:

void

getCurrentPluginDirName()

Get the directory name of the currently-focused plugin.

Returns:string
callHook(string $name, array $args = Array, Plugin|string $plugin)

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.
Returns:

void

addFilter(string|array $name, callback $callback, $priority = 10)

Add a filter implementation.

Parameters:
  • $name (string|array) – Name of filter being implemented.
  • $callback (callback) – PHP callback for filter implementation.
  • $priority (unknown) –
Returns:

void

_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(string|array $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(string|array $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(string|null $name)

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.
Returns:

void

applyFilters(mixed $name, mixed $value, array $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.

Returns:void