function YamlDirectoryDiscovery::findAll

Same name in other branches
  1. 9 core/lib/Drupal/Component/Discovery/YamlDirectoryDiscovery.php \Drupal\Component\Discovery\YamlDirectoryDiscovery::findAll()
  2. 8.9.x core/lib/Drupal/Component/Discovery/YamlDirectoryDiscovery.php \Drupal\Component\Discovery\YamlDirectoryDiscovery::findAll()
  3. 11.x core/lib/Drupal/Component/Discovery/YamlDirectoryDiscovery.php \Drupal\Component\Discovery\YamlDirectoryDiscovery::findAll()

Overrides DiscoverableInterface::findAll

File

core/lib/Drupal/Component/Discovery/YamlDirectoryDiscovery.php, line 67

Class

YamlDirectoryDiscovery
Discovers multiple YAML files in a set of directories.

Namespace

Drupal\Component\Discovery

Code

public function findAll() {
    $all = [];
    $files = $this->findFiles();
    $file_cache = FileCacheFactory::get('yaml_discovery:' . $this->fileCacheKeySuffix);
    // Try to load from the file cache first.
    foreach ($file_cache->getMultiple(array_keys($files)) as $file => $data) {
        $all[$files[$file]][$this->getIdentifier($file, $data)] = $data;
        unset($files[$file]);
    }
    // If there are files left that were not returned from the cache, load and
    // parse them now. This list was flipped above and is keyed by filename.
    if ($files) {
        foreach ($files as $file => $provider) {
            // If a file is empty or its contents are commented out, return an empty
            // array instead of NULL for type consistency.
            try {
                $data = Yaml::decode(file_get_contents($file)) ?: [];
            } catch (InvalidDataTypeException $e) {
                throw new DiscoveryException("The {$file} contains invalid YAML", 0, $e);
            }
            $data[static::FILE_KEY] = $file;
            $all[$provider][$this->getIdentifier($file, $data)] = $data;
            $file_cache->set($file, $data);
        }
    }
    return $all;
}

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