function DrupalDebugClassLoader::getExtensionName

Extracts the Drupal extension name from a fully qualified class name.

Parameters

string $class: The fully qualified class name.

Return value

string|null The extension name, or NULL for non-Drupal classes.

1 call to DrupalDebugClassLoader::getExtensionName()
DrupalDebugClassLoader::checkAnnotations in core/tests/Drupal/TestTools/ErrorHandler/DrupalDebugClassLoader.php

File

core/tests/Drupal/TestTools/ErrorHandler/DrupalDebugClassLoader.php, line 104

Class

DrupalDebugClassLoader
Extends Symfony's DebugClassLoader for Drupal-aware vendor boundaries.

Namespace

Drupal\TestTools\ErrorHandler

Code

private static function getExtensionName(string $class) : ?string {
  if (!str_starts_with($class, 'Drupal\\')) {
    return NULL;
  }
  $parts = explode('\\', $class);
  if (isset($parts[2]) && $parts[1] === 'Tests') {
    return $parts[2];
  }
  return $parts[1] ?? NULL;
}

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