_registry_parse_file($filename, $contents, $module = '', $weight = 0)
drupal/includes/registry.inc, line 146
Parse a file and save its function and class listings.
$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.
| Name | Description |
|---|---|
| Code registry | The code registry engine. |
function _registry_parse_file($filename, $contents, $module = '', $weight = 0) {
static $map = 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);
}
}
}
}