function InstalledPackage::scanForProjectName

Scans a given path to determine the Drupal project name.

The path will be scanned recursively for `.info.yml` files containing a `project` key.

Return value

string|null The name of the project, as declared in the first found `.info.yml` which contains a `project` key, or NULL if none was found.

1 call to InstalledPackage::scanForProjectName()
InstalledPackage::getProjectName in core/modules/package_manager/src/InstalledPackage.php
Returns the Drupal project name for this package.

File

core/modules/package_manager/src/InstalledPackage.php, line 95

Class

InstalledPackage
A value object that represents an installed Composer package.

Namespace

Drupal\package_manager

Code

private function scanForProjectName() : ?string {
    $iterator = new \RecursiveDirectoryIterator($this->path);
    $iterator = new \RecursiveIteratorIterator($iterator);
    $iterator = new \RegexIterator($iterator, '/.+\\.info\\.yml$/', \RegexIterator::GET_MATCH);
    foreach ($iterator as $match) {
        $info = file_get_contents($match[0]);
        $info = Yaml::decode($info);
        if (!empty($info['project'])) {
            return $info['project'];
        }
    }
    return NULL;
}

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