class crumbs_PluginEngine in Crumbs, the Breadcrumbs suite 6.2
Same name and namespace in other branches
- 7 lib/PluginEngine.php \crumbs_PluginEngine
Hierarchy
- class \crumbs_PluginEngine
Expanded class hierarchy of crumbs_PluginEngine
File
- ./
crumbs.plugin_engine.inc, line 160
View source
class crumbs_PluginEngine {
protected $_plugins;
protected $_weightKeeper;
protected $_pluginOrder_find = array();
protected $_pluginOrder_alter = array();
function __construct(array $plugins, array $weights) {
$this->_plugins = $plugins;
foreach ($plugins as $plugin_key => $plugin) {
if (!method_exists($plugin, 'defineOne')) {
$weights[$plugin_key] = FALSE;
}
if (!method_exists($plugin, 'defineMany') && !method_exists($plugin, 'define')) {
$weights[$plugin_key . '.*'] = FALSE;
}
}
$this->_weightKeeper = new crumbs_RuleWeightKeeper($weights);
foreach ($plugins as $plugin_key => $plugin) {
$keeper = $this->_weightKeeper
->prefixedWeightKeeper($plugin_key);
$w_find = $keeper
->getSmallestWeight();
if ($w_find !== FALSE) {
$this->_pluginOrder_find[$plugin_key] = $w_find;
}
$w_alter = $keeper
->findWeight();
if ($w_alter !== FALSE) {
$this->_pluginOrder_alter[$plugin_key] = $w_alter;
}
}
// lowest weight first = highest priority first
asort($this->_pluginOrder_find);
// lowest weight last = highest priority last
arsort($this->_pluginOrder_alter);
foreach ($this->_pluginOrder_find as $plugin_key => $weight) {
$this->_pluginOrder_find[$plugin_key] = $plugins[$plugin_key];
}
foreach ($this->_pluginOrder_alter as $plugin_key => $weight) {
$this->_pluginOrder_alter[$plugin_key] = $plugins[$plugin_key];
}
}
/**
* Invoke the invoke action for all plugins, starting with the plugin with
* highest priority. The function will stop when it has
*
* @param $invokeAction
* an object that does the method call, and can maintain a state between
* different plugins' method calls.
*/
function invokeAll_find(crumbs_InvokeActionInterface_find $invoke_action) {
foreach ($this->_pluginOrder_find as $plugin_key => $plugin) {
$weight_keeper = $this->_weightKeeper
->prefixedWeightKeeper($plugin_key);
$found = $invoke_action
->invoke($plugin, $plugin_key, $weight_keeper);
if ($found) {
return $found;
}
}
}
/**
* invokeAll for alter hooks.
* These need to be called with the lowest priority first,
* because later calls will overwrite earlier calls.
*/
function invokeAll_alter(crumbs_InvokeActionInterface_alter $invokeAction) {
foreach ($this->_pluginOrder_alter as $plugin_key => $plugin) {
$invokeAction
->invoke($plugin, $plugin_key);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
crumbs_PluginEngine:: |
protected | property | ||
crumbs_PluginEngine:: |
protected | property | ||
crumbs_PluginEngine:: |
protected | property | ||
crumbs_PluginEngine:: |
protected | property | ||
crumbs_PluginEngine:: |
function | invokeAll for alter hooks. These need to be called with the lowest priority first, because later calls will overwrite earlier calls. | ||
crumbs_PluginEngine:: |
function | Invoke the invoke action for all plugins, starting with the plugin with highest priority. The function will stop when it has | ||
crumbs_PluginEngine:: |
function |