FullModuleList.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Module;
  7. /**
  8. * A list of modules in the Magento application
  9. *
  10. * Represents all modules, regardless of enabled or not
  11. */
  12. class FullModuleList implements ModuleListInterface
  13. {
  14. /**
  15. * Loader of module information from source code
  16. *
  17. * @var ModuleList\Loader
  18. */
  19. private $loader;
  20. /**
  21. * Enumeration of the module names
  22. *
  23. * @var string[]
  24. */
  25. private $data;
  26. /**
  27. * Constructor
  28. *
  29. * @param ModuleList\Loader $loader
  30. */
  31. public function __construct(ModuleList\Loader $loader)
  32. {
  33. $this->loader = $loader;
  34. }
  35. /**
  36. * {@inheritdoc}
  37. * @see getNames()
  38. */
  39. public function getAll()
  40. {
  41. if (null === $this->data) {
  42. $this->data = $this->loader->load();
  43. }
  44. return $this->data;
  45. }
  46. /**
  47. * {@inheritdoc}
  48. * @see has()
  49. */
  50. public function getOne($name)
  51. {
  52. $data = $this->getAll();
  53. return $data[$name] ?? null;
  54. }
  55. /**
  56. * {@inheritdoc}
  57. */
  58. public function getNames()
  59. {
  60. $data = $this->getAll();
  61. return array_keys($data);
  62. }
  63. /**
  64. * {@inheritdoc}
  65. */
  66. public function has($name)
  67. {
  68. $this->getAll();
  69. return isset($this->data[$name]);
  70. }
  71. }