You are here

function _drupal_get_filename_perform_file_scan in Drupal 7

Performs a file system scan to search for a system resource.

Parameters

$type: The type of the item (theme, theme_engine, module, profile).

$name: The name of the item for which the filename is requested.

Return value

The filename of the requested item or FALSE if the item is not found.

See also

drupal_get_filename()

_drupal_get_filename_fallback()

1 call to _drupal_get_filename_perform_file_scan()
_drupal_get_filename_fallback in includes/bootstrap.inc
Performs a cached file system scan as a fallback when searching for a file.

File

includes/bootstrap.inc, line 1046
Functions that need to be loaded on every Drupal request.

Code

function _drupal_get_filename_perform_file_scan($type, $name) {

  // The location of files will not change during the request, so do not use
  // drupal_static().
  static $dirs = array(), $files = array();

  // We have a consistent directory naming: modules, themes...
  $dir = $type . 's';
  if ($type == 'theme_engine') {
    $dir = 'themes/engines';
    $extension = 'engine';
  }
  elseif ($type == 'theme') {
    $extension = 'info';
  }
  else {
    $extension = $type;
  }

  // Check if we had already scanned this directory/extension combination.
  if (!isset($dirs[$dir][$extension])) {

    // Log that we have now scanned this directory/extension combination
    // into a static variable so as to prevent unnecessary file scans.
    $dirs[$dir][$extension] = TRUE;
    if (!function_exists('drupal_system_listing')) {
      require_once DRUPAL_ROOT . '/includes/common.inc';
    }

    // Scan the appropriate directories for all files with the requested
    // extension, not just the file we are currently looking for. This
    // prevents unnecessary scans from being repeated when this function is
    // called more than once in the same page request.
    $matches = drupal_system_listing("/^" . DRUPAL_PHP_FUNCTION_PATTERN . "\\.{$extension}\$/", $dir, 'name', 0);
    foreach ($matches as $matched_name => $file) {

      // Log the locations found in the file scan into a static variable.
      $files[$type][$matched_name] = $file->uri;
    }
  }

  // Return the results of the file system scan, or FALSE to indicate the file
  // was not found.
  return isset($files[$type][$name]) ? $files[$type][$name] : FALSE;
}