function RulesAbstractPlugin::rebuildCache

Add in the data provided by the info hooks to the cache.

Overrides RulesExtendable::rebuildCache

File

includes/rules.core.inc, line 1752

Class

RulesAbstractPlugin
Defines a common base class for so-called "Abstract Plugins" like actions.

Code

public function rebuildCache(&$itemInfo, &$cache) {
    parent::rebuildCache($itemInfo, $cache);
    // Include all declared files so we can find all implementations.
    self::includeFiles();
    // Get the plugin's own info data.
    $cache[$this->itemName . '_info'] = rules_fetch_data($this->itemName . '_info');
    foreach ($cache[$this->itemName . '_info'] as $name => &$info) {
        $info += array(
            'parameter' => isset($info['arguments']) ? $info['arguments'] : array(),
            'provides' => isset($info['new variables']) ? $info['new variables'] : array(),
            'base' => $name,
            'callbacks' => array(),
        );
        unset($info['arguments'], $info['new variables']);
        if (function_exists($info['base'])) {
            $info['callbacks'] += array(
                'execute' => $info['base'],
            );
        }
        // We do not need to build a faces cache for RulesPluginHandlerInterface,
        // which gets added in automatically as its a parent of
        // RulesPluginImplInterface.
        unset($this->faces['RulesPluginHandlerInterface']);
        // Build up the per-plugin implementation faces cache.
        foreach ($this->faces as $interface) {
            $methods = $file_names = array();
            $includes = self::getIncludeFiles($info['module']);
            foreach (get_class_methods($interface) as $method) {
                if (isset($info['callbacks'][$method]) && ($function = $info['callbacks'][$method])) {
                    $methods[$method][0] = $function;
                    $file_names[$method] = $this->getFileName($function, $includes);
                }
                elseif (isset($info['class']) && is_subclass_of($info['class'], $interface)) {
                    $methods[$method][1] = $info['class'];
                }
                elseif (function_exists($function = $info['base'] . '_' . $method)) {
                    $methods[$method][0] = $function;
                    $file_names[$method] = $this->getFileName($function, $includes);
                }
            }
            // Cache only the plugin implementation specific callbacks.
            $info['faces_cache'][$interface] = array(
                $methods,
                array_filter($file_names),
            );
        }
        // Filter out interfaces with no overridden methods.
        $info['faces_cache'] = rules_filter_array($info['faces_cache'], 0, TRUE);
        // We don't need that any more.
        unset($info['callbacks'], $info['base']);
    }
}