public function YamlDiscovery::findAll

public YamlDiscovery::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/YamlDiscovery.php, line 44

Class

YamlDiscovery
Provides discovery for YAML files within a given set of directories.

Namespace

Drupal\Component\Discovery

Code

public function findAll() {
  $all = array();

  $files = $this->findFiles();
  $provider_by_files = array_flip($files);

  $file_cache = FileCacheFactory::get('yaml_discovery:' . $this->name);

  // Try to load from the file cache first.
  foreach ($file_cache->getMultiple($files) as $file => $data) {
    $all[$provider_by_files[$file]] = $data;
    unset($provider_by_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 ($provider_by_files) {
    foreach ($provider_by_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.
      $all[$provider] = Yaml::decode(file_get_contents($file)) ? : [];
      $file_cache->set($file, $all[$provider]);
    }
  }

  return $all;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Component!Discovery!YamlDiscovery.php/function/YamlDiscovery::findAll/8.1.x