You are here

function DrupalExtensionAdapter::registerExtensionPsr4 in X Autoload 7.4

Same name and namespace in other branches
  1. 7.5 src/Adapter/DrupalExtensionAdapter.php \Drupal\xautoload\Adapter\DrupalExtensionAdapter::registerExtensionPsr4()

Register PSR-4 directory for an extension. Override previous settings for this extension.

Parameters

string $name: The extension name.

string $extension_dir: The directory of the extension.

string $subdir: The PSR-4 base directory, relative to the extension directory. E.g. 'lib' or 'src'.

File

lib/Adapter/DrupalExtensionAdapter.php, line 167

Class

DrupalExtensionAdapter
Service that knows how to register module namespaces and prefixes into the class loader, and that remembers which modules have already been registered.

Namespace

Drupal\xautoload\Adapter

Code

function registerExtensionPsr4($name, $extension_dir, $subdir) {
  if (!empty($this->registered[$name])) {
    if ('psr-4' === $this->registered[$name]) {

      // It already happened.
      return;
    }

    // Unregister the lazy plugins.
    $this->namespaceMap
      ->unregisterDeepPath('Drupal/' . $name . '/', $name);
    $this->prefixMap
      ->unregisterDeepPath(str_replace('_', '/', $name) . '/', $name);
  }
  $dir = strlen($subdir) ? $extension_dir . '/' . trim($subdir, '/') . '/' : $extension_dir . '/';
  $this->namespaceMap
    ->registerDeepPath('Drupal/' . $name . '/', $dir, $this->defaultBehavior);

  // Re-add the PSR-0 test directory, for consistency's sake.
  if (is_dir($psr0_tests_dir = $extension_dir . '/lib/Drupal/' . $name . '/Tests')) {
    $this->namespaceMap
      ->registerDeepPath('Drupal/' . $name . '/Tests/', $psr0_tests_dir, $this->defaultBehavior);
  }
}