function DatabaseDriver::getAutoloadInfo
Same name and namespace in other branches
- 10 core/lib/Drupal/Core/Extension/DatabaseDriver.php \Drupal\Core\Extension\DatabaseDriver::getAutoloadInfo()
Returns an array with the driver's autoload information.
The module that provides the database driver should add the driver's namespace to Composer's autoloader. However, since the database connection must be established before Drupal adds the module's entire namespace to the autoloader, the database connection info array includes an "autoload" key containing the autoload directory for the driver's namespace. For requests that connect to the database via a connection info array, the value of the "autoload" key is automatically added to the autoloader.
This method can be called to find the default value of that key when the database connection info array isn't available. This includes:
- Console commands and test runners that connect to a database specified by a database URL rather than a connection info array.
- During installation, prior to the connection info array being written to settings.php.
This method returns an array with the driver's namespace and autoload directory that must be added to the autoloader, as well as those of any dependency specified in the driver's module.info.yml file, in the format
[
'autoload' => 'path_to_modules/module_a/src/Driver/Database/driver_1/',
'namespace' => 'Drupal\\module_a\\Driver\\Database\\driver_1',
'dependencies' => [
'module_x' => [
'autoload' => 'path_to_modules/module_x/src/',
'namespace' => 'Drupal\\module_x',
],
],
];
Return value
array{ 'autoload': string, 'namespace': string, 'dependencies': array<string, array{'autoload': string, 'namespace': string}>, }
File
-
core/
lib/ Drupal/ Core/ Extension/ DatabaseDriver.php, line 165
Class
- DatabaseDriver
- Defines a database driver extension object.
Namespace
Drupal\Core\ExtensionCode
public function getAutoloadInfo() : array {
$this->getModuleInfo();
$autoloadInfo = [
'namespace' => $this->getNamespace(),
'autoload' => $this->getPath() . DIRECTORY_SEPARATOR,
];
foreach ($this->info['dependencies'] ?? [] as $dependency) {
$dependencyData = Dependency::createFromString($dependency);
$dependencyName = $dependencyData->getName();
if (empty($this->discoveredModules[$dependencyName])) {
throw new \RuntimeException(sprintf("Cannot find the module '%s' that is required by module '%s'", $dependencyName, $this->getModule()
->getName()));
}
$autoloadInfo['dependencies'][$dependencyName] = [
'namespace' => "Drupal\\{$dependencyName}",
'autoload' => $this->discoveredModules[$dependencyName]
->getPath() . '/src/',
];
}
return $autoloadInfo;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.