function PathLocator::getVendorDirectory
Returns the absolute path of the vendor directory.
Return value
string The absolute path of the vendor directory.
1 call to PathLocator::getVendorDirectory()
- PathLocator::getProjectRoot in core/
modules/ package_manager/ src/ PathLocator.php - Returns the absolute path of the project root.
File
-
core/
modules/ package_manager/ src/ PathLocator.php, line 42
Class
- PathLocator
- Computes file system paths that are needed to stage code changes.
Namespace
Drupal\package_managerCode
public function getVendorDirectory() : string {
// There may be multiple class loaders at work.
// ClassLoader::getRegisteredLoaders() keeps track of them all, indexed by
// the path of the vendor directory they load classes from.
$loaders = ClassLoader::getRegisteredLoaders();
// If there's only one class loader, we don't need to search for the right
// one.
if (count($loaders) === 1) {
return key($loaders);
}
// To determine which class loader is the one for Drupal's vendor directory,
// look for the loader whose vendor path starts the same way as the path to
// this file.
foreach (array_keys($loaders) as $path) {
if (str_starts_with(__FILE__, dirname($path))) {
return $path;
}
}
// If we couldn't find a match, assume that the first registered class
// loader is the one we want.
return key($loaders);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.