_registry_parse_file

  1. drupal
    1. drupal7
Versionen
drupal7 _registry_parse_file($filename, $contents, $module = '', $weight = 0)

Parse a file and save its function and class listings.

Übergabeparameter

$filename Name of the file we are going to parse.

$contents Contents of the file we are going to parse as a string.

$module (optional) Name of the module this file belongs to.

$weight (optional) Weight of the module.

Verwandte Themen

▾ 2 functions call _registry_parse_file()

RegistryParseFileTestCase::testRegistryParseFile in modules/simpletest/tests/registry.test
testRegistryParseFile
_registry_parse_files in includes/registry.inc
Parse all files that have changed since the registry was last built, and save their function and class listings.

Code

includes/registry.inc, line 153

<?php
function _registry_parse_file($filename, $contents, $module = '', $weight = 0) {
  $map = &drupal_static(__FUNCTION__, array(T_FUNCTION => 'function', T_CLASS => 'class', T_INTERFACE => 'interface'));
  // Delete registry entries for this file, so we can insert the new resources.
  db_delete('registry')
    ->condition('filename', $filename)
    ->execute();
  $tokens = token_get_all($contents);
  while ($token = next($tokens)) {
    // Ignore all tokens except for those we are specifically saving.
    if (is_array($token) && isset($map[$token[0]])) {
      $type = $map[$token[0]];
      if ($resource_name = _registry_get_resource_name($tokens, $type)) {
        $suffix = '';
        // Collect the part of the function name after the module name,
        // so that we can query the registry for possible hook implementations.
        if ($type == 'function' && !empty($module)) {
          $n = strlen($module);
          if (substr($resource_name, 0, $n) == $module) {
            $suffix = substr($resource_name, $n + 1);
          }
        }
        $fields = array(
          'filename' => $filename,
          'module' => $module,
          'suffix' => $suffix,
          'weight' => $weight,
        );
        // Because some systems, such as cache, currently use duplicate function
        // names in separate files an insert query cannot be used here as it
        // would cause a key constraint violation. Instead we use a merge query.
        // In practice this should not be an issue as those systems all initialize
        // pre-registry and therefore are never loaded by the registry so it
        // doesn't matter if those records in the registry table point to one
        // filename instead of another.
        // TODO: Convert this back to an insert query after all duplicate
        // function names have been purged from Drupal.
        db_merge('registry')
          ->key(array('name' => $resource_name, 'type' => $type))
          ->fields($fields)
          ->execute();

        // We skip the body because classes may contain functions.
        _registry_skip_body($tokens);
      }
    }
  }
}
?>

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