ModuleManager.php 1.4 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
<?php
/**
 * @copyright  Vertex. All rights reserved.  https://www.vertexinc.com/
 * @copyright  Magento.  All rights reserved.
 * @author     Mediotype                     https://www.mediotype.com/
 */

namespace Vertex\Tax\Model;

use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\Config\ConfigOptionsListConstants;

/**
 * Determine if a Module is Enabled or not
 *
 * Fill in for {@see \Magento\Framework\Module\Manager} since it's not part of the public API.
 * See github PR #12677
 */
class ModuleManager
{
    /** @var DeploymentConfig */
    private $config;

    /** @var array */
    private $configData;

    /**
     * @param DeploymentConfig $config
     */
    public function __construct(DeploymentConfig $config)
    {
        $this->config = $config;
    }

    /**
     * Determine if a module is enabled or not
     *
     * @param string $moduleName
     * @return bool
     */
    public function isEnabled($moduleName)
    {
        $this->loadModuleConfiguration();
        if (!$this->configData) {
            return false;
        }
        return !empty($this->configData[$moduleName]);
    }

    /**
     * Loads module configuration data
     */
    private function loadModuleConfiguration()
    {
        $this->config->resetData();
        if ($this->configData === null) {
            $this->configData = $this->config->get(ConfigOptionsListConstants::KEY_MODULES);
        }
    }
}