1 bootstrap.inc backdrop_autoload($class)

Confirms that a class is available.

This function is rarely called directly. Instead, it is registered as an spl_autoload_function() handler, and PHP calls it for us when necessary.

Parameters

$class: The name of the class to check or load.

Return value

TRUE if the class is currently available, FALSE otherwise.:

File

core/includes/bootstrap.inc, line 4041
Functions that need to be loaded on every Backdrop request.

Code

function backdrop_autoload($class) {
  $class_registry = &backdrop_static(__FUNCTION__, NULL);

  if (!isset($class_registry)) {
    include_once BACKDROP_ROOT . '/core/includes/bootstrap.classes.inc';
    $class_registry = backdrop_class_list();
    // Loop through all modules to build the list of classes. We avoid
    // module_invoke_all() because it uses array_merge_recursive(), which is an
    // expensive O(n^2) operation. Instead we use module_implements() and merge
    // the array manually, which is O(n).
    include_once BACKDROP_ROOT . '/core/includes/module.inc';
    foreach (module_implements('autoload_info') as $module) {
      $module_classes = module_invoke($module, 'autoload_info');
      $module_path = backdrop_get_path('module', $module);
      foreach ($module_classes as $module_class => $relative_path) {
        $class_registry[$module_class] = BACKDROP_ROOT . '/' . $module_path . '/' . $relative_path;
      }
    }
    backdrop_alter('autoload_info', $class_registry);
  }

  if (isset($class_registry[$class])) {
    require_once $class_registry[$class];
    return TRUE;
  }
  else {
    return FALSE;
  }
}