You are here

public function ExtensionDiscovery::scan in Composer Manager 8

Overrides BaseExtensionDiscovery::scan().

Compared to the parent method:

  • doesn't scan core/ because composer_manager doesn't need to care about core extensions (core already ships with their dependencies).
  • scans all sites (to accommodate the poor souls still using multisite).

Overrides ExtensionDiscovery::scan

File

src/ExtensionDiscovery.php, line 20

Class

ExtensionDiscovery
Discovers available extensions in the filesystem.

Namespace

Drupal\composer_manager

Code

public function scan($type, $include_tests = NULL) {
  $searchdirs[static::ORIGIN_SITES_ALL] = 'sites/all';
  $searchdirs[static::ORIGIN_ROOT] = '';

  // Add all site directories, so that in a multisite environment each site
  // gets the necessary dependencies.
  foreach ($this
    ->getSiteDirectories() as $index => $siteDirectory) {

    // The indexes are used as weights, so start at 10 to avoid conflicting
    // with the ones defined in the constants (ORIGIN_CORE, etc).
    $index = 10 + $index;
    $searchdirs[$index] = 'sites/' . $siteDirectory;
  }

  // We don't care about tests.
  $include_tests = FALSE;

  // From this point on the method is the same as the parent.
  $files = [];
  foreach ($searchdirs as $dir) {

    // Discover all extensions in the directory, unless we did already.
    if (!isset(static::$files[$dir][$include_tests])) {
      static::$files[$dir][$include_tests] = $this
        ->scanDirectory($dir, $include_tests);
    }

    // Only return extensions of the requested type.
    if (isset(static::$files[$dir][$include_tests][$type])) {
      $files += static::$files[$dir][$include_tests][$type];
    }
  }

  // If applicable, filter out extensions that do not belong to the current
  // installation profiles.
  $files = $this
    ->filterByProfileDirectories($files);

  // Sort the discovered extensions by their originating directories.
  $origin_weights = array_flip($searchdirs);
  $files = $this
    ->sort($files, $origin_weights);

  // Process and return the list of extensions keyed by extension name.
  return $this
    ->process($files);
}