You are here

xautoload.module in X Autoload 7

File

xautoload.module
View source
<?php

/**
 * Implements hook_boot()
 */
function xautoload_boot() {

  // TODO: We want a cached version of this.
  spl_autoload_register('_xautoload_autoload');
}

/**
 * Autoload callback for classes and interfaces, registered in hook_boot().
 */
function _xautoload_autoload($name) {
  $file = _xautoload_finder()
    ->findFile($name);
  if ($file) {
    require_once $file;
  }
}

/**
 * Static registry for the finder object.
 */
function _xautoload_finder() {
  static $_finder;
  if (!isset($_finder)) {
    $modules = module_list();
    foreach ($modules as $module => $m) {
      $path = drupal_get_path('module', $module) . '/lib/';
      if (is_dir($path)) {
        $modules[$module] = $path;
      }
    }

    // Autoload is not ready yet, this is why we include this one explicitly.
    module_load_include('php', 'xautoload', 'lib/ClassFinder');
    $_finder = new xautoload_ClassFinder($modules);
  }
  return $_finder;
}

/**
 * Implements hook_registry_files_alter()
 *
 * Support wildcard syntax in the files[] setting in your module's info file.
 */
function xautoload_registry_files_alter(&$files, $modules) {
  $orig = $files;

  // The class file is loaded using the regular uncached xautoload autoload.
  $rec_scan = new xautoload_RecursiveScan($files);
  foreach ($files as $path => $file) {
    $rec_scan
      ->check($path, $file);
  }
}

Functions

Namesort descending Description
xautoload_boot Implements hook_boot()
xautoload_registry_files_alter Implements hook_registry_files_alter()
_xautoload_autoload Autoload callback for classes and interfaces, registered in hook_boot().
_xautoload_finder Static registry for the finder object.