You are here

protected function YamlDiscovery::decode in Drupal 10

Same name in this branch
  1. 10 core/lib/Drupal/Core/Discovery/YamlDiscovery.php \Drupal\Core\Discovery\YamlDiscovery::decode()
  2. 10 core/lib/Drupal/Component/Discovery/YamlDiscovery.php \Drupal\Component\Discovery\YamlDiscovery::decode()
Same name and namespace in other branches
  1. 8 core/lib/Drupal/Component/Discovery/YamlDiscovery.php \Drupal\Component\Discovery\YamlDiscovery::decode()
  2. 9 core/lib/Drupal/Component/Discovery/YamlDiscovery.php \Drupal\Component\Discovery\YamlDiscovery::decode()

Decode a YAML file.

Parameters

string $file: Yaml file path.

Return value

array

File

core/lib/Drupal/Component/Discovery/YamlDiscovery.php, line 81

Class

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

Namespace

Drupal\Component\Discovery

Code

protected function decode($file) {
  try {
    return Yaml::decode(file_get_contents($file)) ?: [];
  } catch (InvalidDataTypeException $e) {
    throw new InvalidDataTypeException($file . ': ' . $e
      ->getMessage(), $e
      ->getCode(), $e);
  }
}