YamlDirectoryDiscovery::findAll

public YamlDirectoryDiscovery::findAll()

Returns an array of discoverable items.

Return value

array An array of discovered data keyed by provider.

Throws

\Drupal\Component\Discovery\DiscoveryException Exception thrown if there is a problem during discovery.

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
public function findAll() {
  $all = array();
 
  $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;
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.