_registry_check_code

  1. drupal
    1. drupal7
Versionen
drupal7 _registry_check_code($type, $name = NULL)

Helper to check for a resource in the registry.

Übergabeparameter

$type The type of resource we are looking up, or one of the constants REGISTRY_RESET_LOOKUP_CACHE or REGISTRY_WRITE_LOOKUP_CACHE, which signal that we should reset or write the cache, respectively.

$name The name of the resource, or NULL if either of the REGISTRY_* constants is passed in.

Rückgabewert

TRUE if the resource was found, FALSE if not. NULL if either of the REGISTRY_* constants is passed in as $type.

Verwandte Themen

▾ 5 functions call _registry_check_code()

drupal_autoload_class in includes/bootstrap.inc
Confirm that a class is available.
drupal_autoload_interface in includes/bootstrap.inc
Confirm that an interface is available.
drupal_function_exists in includes/bootstrap.inc
Confirm that a function is available.
drupal_page_footer in includes/common.inc
Perform end-of-request tasks.
_registry_rebuild in includes/registry.inc

Code

includes/bootstrap.inc, line 1744

<?php
function _registry_check_code($type, $name = NULL) {
  static $lookup_cache, $cache_update_needed;

  if (!isset($lookup_cache)) {
    $lookup_cache = array();
    if ($cache = cache_get('lookup_cache', 'cache_registry')) {
      $lookup_cache = $cache->data;
    }
  }

  // When we rebuild the registry, we need to reset this cache so
  // we don't keep lookups for resources that changed during the rebuild.
  if ($type == REGISTRY_RESET_LOOKUP_CACHE) {
    $cache_update_needed = TRUE;
    $lookup_cache = NULL;
    return;
  }

  // Called from drupal_page_footer, we write to permanent storage if there
  // changes to the lookup cache for this request.
  if ($type == REGISTRY_WRITE_LOOKUP_CACHE) {
    if ($cache_update_needed) {
      cache_set('lookup_cache', $lookup_cache, 'cache_registry');
    }
    return;
  }

  // $type can be one of 'function', 'interface' or 'class', so we only need the
  // first letter to keep the cache key unique.
  $cache_key = $type[0] . $name;
  if (isset($lookup_cache[$cache_key])) {
    if ($lookup_cache[$cache_key]) {
      require_once DRUPAL_ROOT . '/' . $lookup_cache[$cache_key];
    }
    return $lookup_cache[$cache_key];
  }

  // This function may get called when the default database is not active, but
  // there is no reason we'd ever want to not use the default database for
  // this query.
  $file = Database::getConnection('default', 'default')->query("SELECT filename FROM {registry} WHERE name = :name AND type = :type", array(
      ':name' => $name,
      ':type' => $type,
    ))
    ->fetchField();

  // Flag that we've run a lookup query and need to update the cache.
  $cache_update_needed = TRUE;

  // Misses are valuable information worth caching, so cache even if
  // $file is FALSE.
  $lookup_cache[$cache_key] = $file;

  if ($file) {
    require_once DRUPAL_ROOT . '/' . $file;
    return TRUE;
  }
  else {
    return FALSE;
  }
}
?>

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen