InstallerModuleExtensionList.php 1.8 KB

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