Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / lib / Drupal / Core / Extension / InfoParserDynamic.php
1 <?php
2
3 namespace Drupal\Core\Extension;
4
5 use Drupal\Component\Serialization\Exception\InvalidDataTypeException;
6 use Drupal\Core\Serialization\Yaml;
7
8 /**
9  * Parses dynamic .info.yml files that might change during the page request.
10  */
11 class InfoParserDynamic implements InfoParserInterface {
12
13   /**
14    * {@inheritdoc}
15    */
16   public function parse($filename) {
17     if (!file_exists($filename)) {
18       $parsed_info = [];
19     }
20     else {
21       try {
22         $parsed_info = Yaml::decode(file_get_contents($filename));
23       }
24       catch (InvalidDataTypeException $e) {
25         throw new InfoParserException("Unable to parse $filename " . $e->getMessage());
26       }
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);
30       }
31       if (isset($parsed_info['version']) && $parsed_info['version'] === 'VERSION') {
32         $parsed_info['version'] = \Drupal::VERSION;
33       }
34       // Special backwards compatible handling profiles and their 'dependencies'
35       // key.
36       if ($parsed_info['type'] === 'profile' && isset($parsed_info['dependencies']) && !array_key_exists('install', $parsed_info)) {
37         // Only trigger the deprecation message if we are actually using the
38         // profile with the missing 'install' key. This avoids triggering the
39         // deprecation when scanning all the available install profiles.
40         global $install_state;
41         if (isset($install_state['parameters']['profile'])) {
42           $pattern = '@' . preg_quote(DIRECTORY_SEPARATOR . $install_state['parameters']['profile'] . '.info.yml') . '$@';
43           if (preg_match($pattern, $filename)) {
44             @trigger_error("The install profile $filename only implements a 'dependencies' key. As of Drupal 8.6.0 profile's support a new 'install' key for modules that should be installed but not depended on. See https://www.drupal.org/node/2952947.", E_USER_DEPRECATED);
45           }
46         }
47         // Move dependencies to install so that if a profile has both
48         // dependencies and install then dependencies are real.
49         $parsed_info['install'] = $parsed_info['dependencies'];
50         $parsed_info['dependencies'] = [];
51       }
52     }
53     return $parsed_info;
54   }
55
56   /**
57    * Returns an array of keys required to exist in .info.yml file.
58    *
59    * @return array
60    *   An array of required keys.
61    */
62   protected function getRequiredKeys() {
63     return ['type', 'core', 'name'];
64   }
65
66 }