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

Checks whether a namespace is within the namespace of a Drupal module.

This can be used to determine if a database driver's namespace is provided by a Drupal module.

@todo remove in Drupal 11.

Parameters

string $namespace: The namespace (for example, of a database driver) to check.

Return value

bool TRUE if the passed in namespace is a sub-namespace of a Drupal module's namespace.

See also

https://www.drupal.org/node/3256524

1 call to Database::isWithinModuleNamespace()
Database::getConnectionInfoAsUrl in core/lib/Drupal/Core/Database/Database.php
Gets database connection info as a URL.

File

core/lib/Drupal/Core/Database/Database.php, line 741

Class

Database
Primary front-controller for the database system.

Namespace

Drupal\Core\Database

Code

private static function isWithinModuleNamespace(string $namespace) {
  [
    $first,
    $second,
  ] = explode('\\', $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;
}