Initializes and returns the class loader.
The class loader is responsible for lazy-loading all PSR-0 compatible classes, interfaces, and traits (PHP 5.4 and later). It's only dependency is DRUPAL_ROOT. Otherwise it may be called as early as possible.
$class_loader: The name of class loader to use. This can be used to change the class loader class when calling drupal_classloader() from settings.php. It is ignored otherwise.
\Symfony\Component\ClassLoader\ClassLoader A ClassLoader class instance (or extension thereof).
function drupal_classloader($class_loader = NULL) {
// By default, use the ClassLoader which is best for development, as it does
// not break when code is moved on the file system. However, as it is slow,
// allow to use the APC class loader in production.
static $loader;
if (!isset($loader)) {
// Include the Symfony ClassLoader for loading PSR-0-compatible classes.
require_once DRUPAL_ROOT . '/core/vendor/symfony/class-loader/Symfony/Component/ClassLoader/ClassLoader.php';
$loader = new ClassLoader();
// Register the class loader.
// When configured to use APC, the ApcClassLoader is registered instead.
// Note that ApcClassLoader decorates ClassLoader and only provides the
// findFile() method, but none of the others. The actual registry is still
// in ClassLoader.
if (!isset($class_loader)) {
$class_loader = settings()
->get('class_loader', 'default');
}
if ($class_loader === 'apc') {
require_once DRUPAL_ROOT . '/core/vendor/symfony/class-loader/Symfony/Component/ClassLoader/ApcClassLoader.php';
$apc_loader = new ApcClassLoader('drupal.' . drupal_get_hash_salt(), $loader);
$apc_loader
->register();
}
else {
$loader
->register();
}
// Register namespaces for vendor libraries managed by Composer.
$prefixes_and_namespaces = (require DRUPAL_ROOT . '/core/vendor/composer/autoload_namespaces.php');
$loader
->addPrefixes($prefixes_and_namespaces);
// Register the loader with PHP.
$loader
->register();
}
return $loader;
}