function DuplicateInfoFileValidator::findInfoFiles

Recursively finds info.yml files in a directory.

Parameters

string $dir: The path of the directory to check.

Return value

int[] Array of count of info.yml files in the directory keyed by file name.

1 call to DuplicateInfoFileValidator::findInfoFiles()
DuplicateInfoFileValidator::validate in core/modules/package_manager/src/Validator/DuplicateInfoFileValidator.php
Validates the stage does not have duplicate info.yml not present in active.

File

core/modules/package_manager/src/Validator/DuplicateInfoFileValidator.php, line 82

Class

DuplicateInfoFileValidator
Validates the stage does not have duplicate info.yml not present in active.

Namespace

Drupal\package_manager\Validator

Code

private function findInfoFiles(string $dir) : array {
    // Use the official extension discovery mechanism, but tweak it, because by
    // default it resolves duplicates.
    // @see \Drupal\Core\Extension\ExtensionDiscovery::process()
    $duplicate_aware_extension_discovery = new class ($dir, FALSE, []) extends ExtensionDiscovery {
        
        /**
         * {@inheritdoc}
         */
        protected function process(array $all_files) {
            // Unlike parent implementation: no processing, to retain duplicates.
            return $all_files;
        }

};
    // Scan all 4 extension types, explicitly ignoring tests.
    $extension_info_files = array_merge(array_keys($duplicate_aware_extension_discovery->scan('module', FALSE)), array_keys($duplicate_aware_extension_discovery->scan('theme', FALSE)), array_keys($duplicate_aware_extension_discovery->scan('profile', FALSE)), array_keys($duplicate_aware_extension_discovery->scan('theme_engine', FALSE)));
    $info_files = [];
    foreach ($extension_info_files as $info_file) {
        $file_name = basename($info_file);
        $info_files[$file_name] = ($info_files[$file_name] ?? 0) + 1;
    }
    return $info_files;
}

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