class ExtensionDiscovery in Composer Manager 8
Discovers available extensions in the filesystem.
Hierarchy
- class \Drupal\Core\Extension\ExtensionDiscovery
- class \Drupal\composer_manager\ExtensionDiscovery
Expanded class hierarchy of ExtensionDiscovery
1 file declares its use of ExtensionDiscovery
- ExtensionDiscoveryTest.php in tests/
src/ Unit/ ExtensionDiscoveryTest.php
File
- src/
ExtensionDiscovery.php, line 10
Namespace
Drupal\composer_managerView source
class ExtensionDiscovery extends BaseExtensionDiscovery {
/**
* 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).
*/
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);
}
/**
* Resets the internal static cache.
*
* Used by unit tests to ensure a clean slate.
*/
public function resetCache() {
static::$files = [];
}
/**
* Returns an array of all site directories.
*
* @return array
* An array of site directories. For example: ['default', 'test.site.com'].
* Doesn't include the 'all' directory since it doesn't represent a site.
*/
protected function getSiteDirectories() {
$site_directories = scandir($this->root . '/sites');
$site_directories = array_filter($site_directories, function ($site_directory) {
$is_directory = is_dir($this->root . '/sites/' . $site_directory);
$not_hidden = substr($site_directory, 0, 1) != '.';
$not_all = $site_directory != 'all';
return $is_directory && $not_hidden && $not_all;
});
return $site_directories;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ExtensionDiscovery:: |
protected | property | The file cache object. | |
ExtensionDiscovery:: |
protected static | property | Previously discovered files keyed by origin directory and extension type. | |
ExtensionDiscovery:: |
protected | property | List of installation profile directories to additionally scan. | |
ExtensionDiscovery:: |
protected | property | The app root for the current operation. | |
ExtensionDiscovery:: |
protected | property | The site path. | |
ExtensionDiscovery:: |
protected | function | Filters out extensions not belonging to the scanned installation profiles. | |
ExtensionDiscovery:: |
public | function | Gets the installation profile directories to be scanned. | |
ExtensionDiscovery:: |
protected | function | Returns an array of all site directories. | |
ExtensionDiscovery:: |
constant | Origin directory weight: Core. | ||
ExtensionDiscovery:: |
constant | Origin directory weight: Parent site directory of a test site environment. | ||
ExtensionDiscovery:: |
constant | Origin directory weight: Installation profile. | ||
ExtensionDiscovery:: |
constant | Origin directory weight: Site-wide directory. | ||
ExtensionDiscovery:: |
constant | Origin directory weight: Site-specific directory. | ||
ExtensionDiscovery:: |
constant | Origin directory weight: sites/all. | ||
ExtensionDiscovery:: |
constant | Regular expression to match PHP function names. | ||
ExtensionDiscovery:: |
protected | function | Processes the filtered and sorted list of extensions. | |
ExtensionDiscovery:: |
public | function | Resets the internal static cache. | |
ExtensionDiscovery:: |
public | function |
Overrides BaseExtensionDiscovery::scan(). Overrides ExtensionDiscovery:: |
|
ExtensionDiscovery:: |
protected | function | Recursively scans a base directory for the extensions it contains. | |
ExtensionDiscovery:: |
public | function | Sets explicit profile directories to scan. | |
ExtensionDiscovery:: |
public | function | Sets installation profile directories based on current site settings. | |
ExtensionDiscovery:: |
protected | function | Sorts the discovered extensions. | |
ExtensionDiscovery:: |
public | function | Constructs a new ExtensionDiscovery object. |