function autoload in Autoload 7.2
Returns the autoloading class map of a settled autoloader.
Parameters
bool $rebuild: Tells whether the autoloading class map has to be rebuilt.
Return value
\AutoloadCache The autoloading class map.
3 calls to autoload()
- autoload.module in ./
autoload.module - CustomTest::test in src/
Tests/ Unit/ CustomTest.php - drush_autoload_rebuild in ./
autoload.drush.inc - Implements drush_COMMAND().
3 string references to 'autoload'
- AutoloadTestBase::setUp in src/
Tests/ Unit/ AutoloadTestBase.php - CacheTest::test in src/
Tests/ Unit/ CacheTest.php - Tests the autoloading cache.
- drush_autoload_rebuild in ./
autoload.drush.inc - Implements drush_COMMAND().
File
- ./
autoload.module, line 21
Code
function autoload($rebuild = FALSE) {
static $callback;
$map =& drupal_static(__FUNCTION__);
if (NULL === $map) {
$map = new \AutoloadCache(variable_get('autoload_file', sprintf('%s/%s.php', DRUPAL_ROOT, __FUNCTION__)));
// Assume the autoloading mapping needs to re-registered if someone
// requires this.
$callback = NULL;
}
if ($rebuild) {
if (NULL !== $callback && spl_autoload_unregister($callback)) {
// Our autoloader has been deregistered and its updated state needs
// to be registered repeatedly.
$callback = NULL;
}
$map
->rebuild();
}
if (NULL === $callback) {
// Do not set an autoloading callback in a case when something went wrong.
// An exception might be thrown during module installation when no database
// schema available yet.
try {
$modules = module_list();
$callback = function ($namespace) use ($map, $modules) {
if (isset($map[$namespace])) {
// Report about the problem but load class in any way.
if (!isset($modules[$map[$namespace]['provider']]) && 'cli' !== PHP_SAPI) {
trigger_error(sprintf('You are autoloading the "%s", provided by "%s" that is currently disabled!', $namespace, $map[$namespace]['provider']), E_USER_WARNING);
}
// The "DRUPAL_ROOT" constant is not prepended to allow including
// files relative to the Drupal root as well as those, that are
// located outside.
require_once $map[$namespace]['file'];
}
};
// Make this autoloader first to omit execution of Drupal ones.
spl_autoload_register($callback, TRUE, TRUE);
} catch (Exception $e) {
}
}
return $map;
}