Pull merge.
[yaffs-website] / web / core / lib / Drupal / Core / Installer / InstallerModuleExtensionList.php
1 <?php
2
3 namespace Drupal\Core\Installer;
4
5 use Drupal\Core\Extension\ModuleExtensionList;
6
7 /**
8  * Overrides the module extension list to have a static cache.
9  */
10 class InstallerModuleExtensionList extends ModuleExtensionList {
11
12   /**
13    * Static version of the added file names during the installer.
14    *
15    * @var string[]
16    *
17    * @internal
18    */
19   protected static $staticAddedPathNames;
20
21   /**
22    * {@inheritdoc}
23    */
24   public function setPathname($extension_name, $pathname) {
25     parent::setPathname($extension_name, $pathname);
26
27     // In the early installer the container is rebuilt multiple times. Therefore
28     // we have to keep the added filenames across those rebuilds. This is not a
29     // final design, but rather just a workaround resolved at some point,
30     // hopefully.
31     // @todo Remove as part of https://drupal.org/project/drupal/issues/2934063
32     static::$staticAddedPathNames[$extension_name] = $pathname;
33   }
34
35   /**
36    * {@inheritdoc}
37    */
38   public function getPathname($extension_name) {
39     if (isset($this->addedPathNames[$extension_name])) {
40       return $this->addedPathNames[$extension_name];
41     }
42     elseif (isset($this->pathNames[$extension_name])) {
43       return $this->pathNames[$extension_name];
44     }
45     elseif (isset(static::$staticAddedPathNames[$extension_name])) {
46       return static::$staticAddedPathNames[$extension_name];
47     }
48     elseif (($path_names = $this->getPathnames()) && isset($path_names[$extension_name])) {
49       // Ensure we don't have to do path scanning more than really needed.
50       foreach ($path_names as $extension => $path_name) {
51         static::$staticAddedPathNames[$extension] = $path_name;
52       }
53       return $path_names[$extension_name];
54     }
55     throw new \InvalidArgumentException("The {$this->type} $extension_name does not exist.");
56   }
57
58 }