_registry_parse_file

Definition

_registry_parse_file($filename, $contents, $module = '', $weight = 0)
drupal/includes/registry.inc, line 163

Description

Parse a file and save its function and class listings.

Parameters

$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.

Related topics

Namesort iconDescription
Code registryThe code registry engine.

Code

function _registry_parse_file($filename, $contents, $module = '', $weight = 0) {
  static $map = array(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();
  if (preg_match_all('/^\s*(?:abstract)?\s*(class|interface)\s+([a-zA-Z0-9_]+)/m', $contents, $matches)) {
    $query = db_insert('registry')->fields(array('name', 'type', 'filename', 'module', 'weight'));
    foreach ($matches[2] as $key => $name) {
      $query->values(array(
        'name' => $name,
        'type' => $matches[1][$key],
        'filename' => $filename,
        'module' => $module,
        'weight' => $weight,
      ));
    }
    $query->execute();
  }
}