3 namespace Drupal\Core\Extension;
5 use Drupal\Component\Serialization\Exception\InvalidDataTypeException;
6 use Drupal\Core\Serialization\Yaml;
9 * Parses dynamic .info.yml files that might change during the page request.
11 class InfoParserDynamic implements InfoParserInterface {
16 public function parse($filename) {
17 if (!file_exists($filename)) {
22 $parsed_info = Yaml::decode(file_get_contents($filename));
24 catch (InvalidDataTypeException $e) {
25 throw new InfoParserException("Unable to parse $filename " . $e->getMessage());
27 $missing_keys = array_diff($this->getRequiredKeys(), array_keys($parsed_info));
28 if (!empty($missing_keys)) {
29 throw new InfoParserException('Missing required keys (' . implode(', ', $missing_keys) . ') in ' . $filename);
31 if (isset($parsed_info['version']) && $parsed_info['version'] === 'VERSION') {
32 $parsed_info['version'] = \Drupal::VERSION;
39 * Returns an array of keys required to exist in .info.yml file.
42 * An array of required keys.
44 protected function getRequiredKeys() {
45 return ['type', 'core', 'name'];