function DeprecatedAutoloadAccess::getActualClassLoader

Same name and namespace in other branches
  1. main core/lib/Drupal/Core/Runtime/DeprecatedAutoloadAccess.php \Drupal\Core\Runtime\DeprecatedAutoloadAccess::getActualClassLoader()

Lazy load the actual classloader once.

Return value

\Composer\Autoload\ClassLoader The classloader for this project.

File

core/lib/Drupal/Core/Runtime/DeprecatedAutoloadAccess.php, line 200

Class

DeprecatedAutoloadAccess
Provides deprecation errors when the classloader is accessed.

Namespace

Drupal\Core\Runtime

Code

private static function getActualClassLoader() : ClassLoader {
  // Find the autoload.php.
  if (static::$actual === NULL) {
    // No matter whether we're in $root/core or in vendor/drupal/core, we can
    // always traverse up to find an autoload.php file.
    $dir = __DIR__;
    while (($parent = dirname($dir)) !== $dir) {
      if (file_exists("{$dir}/autoload.php")) {
        static::$actual = require "{$dir}/autoload.php";
        break;

      }
      // Move up one directory.
      $dir = $parent;
    }
  }
  // If we haven't found it by now then we're outside of a Drupal
  // installation.
  if (static::$actual === NULL) {
    throw new \RuntimeException("Unable to find autoload.php file.");
  }
  return static::$actual;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.