private static function Database::isWithinModuleNamespace in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Database/Database.php \Drupal\Core\Database\Database::isWithinModuleNamespace()
- 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.
File
- core/
lib/ Drupal/ Core/ Database/ Database.php, line 650
Class
- Database
- Primary front-controller for the database system.
Namespace
Drupal\Core\DatabaseCode
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;
}