Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
50.00% |
1 / 2 |
CRAP | |
66.67% |
8 / 12 |
| InfoParserDynamic | |
0.00% |
0 / 1 |
|
50.00% |
1 / 2 |
8.81 | |
66.67% |
8 / 12 |
| parse | |
0.00% |
0 / 1 |
7.73 | |
63.64% |
7 / 11 |
|||
| getRequiredKeys | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| <?php | |
| /** | |
| * @file | |
| * Contains \Drupal\Core\Extension\InfoParserDynamic. | |
| */ | |
| namespace Drupal\Core\Extension; | |
| use Drupal\Component\Serialization\Yaml; | |
| use Drupal\Component\Serialization\Exception\InvalidDataTypeException; | |
| /** | |
| * Parses dynamic .info.yml files that might change during the page request. | |
| */ | |
| class InfoParserDynamic implements InfoParserInterface { | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function parse($filename) { | |
| if (!file_exists($filename)) { | |
| $parsed_info = array(); | |
| } | |
| else { | |
| try { | |
| $parsed_info = Yaml::decode(file_get_contents($filename)); | |
| } | |
| catch (InvalidDataTypeException $e) { | |
| throw new InfoParserException("Unable to parse $filename " . $e->getMessage()); | |
| } | |
| $missing_keys = array_diff($this->getRequiredKeys(), array_keys($parsed_info)); | |
| if (!empty($missing_keys)) { | |
| throw new InfoParserException('Missing required keys (' . implode(', ', $missing_keys) . ') in ' . $filename); | |
| } | |
| if (isset($parsed_info['version']) && $parsed_info['version'] === 'VERSION') { | |
| $parsed_info['version'] = \Drupal::VERSION; | |
| } | |
| } | |
| return $parsed_info; | |
| } | |
| /** | |
| * Returns an array of keys required to exist in .info.yml file. | |
| * | |
| * @return array | |
| * An array of required keys. | |
| */ | |
| protected function getRequiredKeys() { | |
| return array('type', 'core', 'name'); | |
| } | |
| } |