ModuleManager.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * @copyright Vertex. All rights reserved. https://www.vertexinc.com/
  4. * @copyright Magento. All rights reserved.
  5. * @author Mediotype https://www.mediotype.com/
  6. */
  7. namespace Vertex\Tax\Model;
  8. use Magento\Framework\App\DeploymentConfig;
  9. use Magento\Framework\Config\ConfigOptionsListConstants;
  10. /**
  11. * Determine if a Module is Enabled or not
  12. *
  13. * Fill in for {@see \Magento\Framework\Module\Manager} since it's not part of the public API.
  14. * See github PR #12677
  15. */
  16. class ModuleManager
  17. {
  18. /** @var DeploymentConfig */
  19. private $config;
  20. /** @var array */
  21. private $configData;
  22. /**
  23. * @param DeploymentConfig $config
  24. */
  25. public function __construct(DeploymentConfig $config)
  26. {
  27. $this->config = $config;
  28. }
  29. /**
  30. * Determine if a module is enabled or not
  31. *
  32. * @param string $moduleName
  33. * @return bool
  34. */
  35. public function isEnabled($moduleName)
  36. {
  37. $this->loadModuleConfiguration();
  38. if (!$this->configData) {
  39. return false;
  40. }
  41. return !empty($this->configData[$moduleName]);
  42. }
  43. /**
  44. * Loads module configuration data
  45. */
  46. private function loadModuleConfiguration()
  47. {
  48. $this->config->resetData();
  49. if ($this->configData === null) {
  50. $this->configData = $this->config->get(ConfigOptionsListConstants::KEY_MODULES);
  51. }
  52. }
  53. }