You are here

private static function Database::isWithinModuleNamespace in Drupal 8

Same name and namespace in other branches
  1. 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 https://www.drupal.org/project/drupal/issues/3125476 Remove if we add this to the extension API or if \Drupal\Core\Database\Database::getConnectionInfoAsUrl() is removed.

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.

2 calls to Database::isWithinModuleNamespace()
Database::findDriverAutoloadDirectory in core/lib/Drupal/Core/Database/Database.php
Finds the directory to add to the autoloader for the driver's namespace.
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 657

Class

Database
Primary front-controller for the database system.

Namespace

Drupal\Core\Database

Code

private static function isWithinModuleNamespace(string $namespace) {
  list($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;
}