Manager.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Module statuses manager
  8. */
  9. namespace Magento\Framework\Module;
  10. /**
  11. * Module status manager.
  12. *
  13. * Usage:
  14. * ```php
  15. * $manager->isEnabled('Vendor_Module');
  16. * ```
  17. */
  18. class Manager
  19. {
  20. /**
  21. * @var Output\ConfigInterface
  22. * @deprecated 101.0.0
  23. */
  24. private $outputConfig;
  25. /**
  26. * @var ModuleListInterface
  27. */
  28. private $moduleList;
  29. /**
  30. * @var array
  31. * @deprecated 101.0.0
  32. */
  33. private $outputConfigPaths;
  34. /**
  35. * @param Output\ConfigInterface $outputConfig
  36. * @param ModuleListInterface $moduleList
  37. * @param array $outputConfigPaths
  38. */
  39. public function __construct(
  40. Output\ConfigInterface $outputConfig,
  41. ModuleListInterface $moduleList,
  42. array $outputConfigPaths = []
  43. ) {
  44. $this->outputConfig = $outputConfig;
  45. $this->moduleList = $moduleList;
  46. $this->outputConfigPaths = $outputConfigPaths;
  47. }
  48. /**
  49. * Whether a module is enabled in the configuration or not
  50. *
  51. * @param string $moduleName Fully-qualified module name
  52. * @return boolean
  53. */
  54. public function isEnabled($moduleName)
  55. {
  56. return $this->moduleList->has($moduleName);
  57. }
  58. /**
  59. * Whether a module output is permitted by the configuration or not
  60. *
  61. * @param string $moduleName Fully-qualified module name
  62. * @return boolean
  63. * @deprecated 101.0.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0
  64. * version. Module output can still be enabled/disabled in configuration files. However, this functionality should
  65. * not be used in future development. Module design should explicitly state dependencies to avoid requiring output
  66. * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity
  67. * issues that will be addressed in future releases.
  68. */
  69. public function isOutputEnabled($moduleName)
  70. {
  71. return $this->isEnabled($moduleName)
  72. && $this->_isCustomOutputConfigEnabled($moduleName)
  73. && !$this->outputConfig->isEnabled($moduleName);
  74. }
  75. /**
  76. * Whether a configuration switch for a module output permits output or not
  77. *
  78. * @param string $moduleName Fully-qualified module name
  79. * @return boolean
  80. * @deprecated 101.0.0
  81. */
  82. protected function _isCustomOutputConfigEnabled($moduleName)
  83. {
  84. if (isset($this->outputConfigPaths[$moduleName])) {
  85. $configPath = $this->outputConfigPaths[$moduleName];
  86. if (defined($configPath)) {
  87. $configPath = constant($configPath);
  88. }
  89. return $this->outputConfig->isSetFlag($configPath);
  90. }
  91. return true;
  92. }
  93. }