YamlDiscovery.php 731 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. namespace Drupal\Core\Discovery;
  3. use Drupal\Component\Discovery\YamlDiscovery as ComponentYamlDiscovery;
  4. use Drupal\Component\Serialization\Exception\InvalidDataTypeException;
  5. use Drupal\Core\Serialization\Yaml;
  6. /**
  7. * Provides discovery for YAML files within a given set of directories.
  8. *
  9. * This overrides the Component file decoding with the Core YAML implementation.
  10. */
  11. class YamlDiscovery extends ComponentYamlDiscovery {
  12. /**
  13. * {@inheritdoc}
  14. */
  15. protected function decode($file) {
  16. try {
  17. return Yaml::decode(file_get_contents($file)) ?: [];
  18. }
  19. catch (InvalidDataTypeException $e) {
  20. throw new InvalidDataTypeException($file . ': ' . $e->getMessage(), $e->getCode(), $e);
  21. }
  22. }
  23. }