You are here

function _rules_discover_module in Rules 7.2

Determines the module providing the given class.

Parameters

string $class: The name of the class or interface plugins to discover.

Return value

string|false The path of the class, relative to the Drupal installation root, or FALSE if not discovered.

1 call to _rules_discover_module()
rules_discover_plugins in ./rules.module
Discover plugin implementations.

File

./rules.module, line 344
Rules engine module.

Code

function _rules_discover_module($class) {
  $paths =& drupal_static(__FUNCTION__);
  if (!isset($paths)) {

    // Build up a map of modules keyed by their directory.
    foreach (system_list('module_enabled') as $name => $module_info) {
      $paths[dirname($module_info->filename)] = $name;
    }
  }

  // Retrieve the class file and convert its absolute path to a regular Drupal
  // path relative to the installation root.
  $reflection = new ReflectionClass($class);
  $path = str_replace(realpath(DRUPAL_ROOT) . DIRECTORY_SEPARATOR, '', realpath(dirname($reflection
    ->getFileName())));
  $path = DIRECTORY_SEPARATOR != '/' ? str_replace(DIRECTORY_SEPARATOR, '/', $path) : $path;

  // Go up the path until we match a module.
  $parts = explode('/', $path);
  while (!isset($paths[$path]) && array_pop($parts)) {
    $path = dirname($path);
  }
  return isset($paths[$path]) ? $paths[$path] : FALSE;
}