function Connection::getProvider

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Database/Connection.php \Drupal\Core\Database\Connection::getProvider()
  2. 11.x core/lib/Drupal/Core/Database/Connection.php \Drupal\Core\Database\Connection::getProvider()

Get the module name of the module that is providing the database driver.

Return value

string The module name of the module that is providing the database driver, or "core" when the driver is not provided as part of a module.

File

core/lib/Drupal/Core/Database/Connection.php, line 2049

Class

Connection
Base Database API class.

Namespace

Drupal\Core\Database

Code

public function getProvider() : string {
    [
        $first,
        $second,
    ] = explode('\\', $this->connectionOptions['namespace'], 3);
    // The namespace for Drupal modules is Drupal\MODULE_NAME, and the module
    // name must be all lowercase. Second-level namespaces containing uppercase
    // letters (e.g., "Core", "Component", "Driver") are not modules.
    // @see \Drupal\Core\DrupalKernel::getModuleNamespacesPsr4()
    // @see https://www.drupal.org/docs/8/creating-custom-modules/naming-and-placing-your-drupal-8-module#s-name-your-module
    return $first === 'Drupal' && strtolower($second) === $second ? $second : 'core';
}

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