为什么我的 Magento 模块没有被加载?

发布于 2024-11-24 00:56:51 字数 41 浏览 2 评论 0原文

我刚刚编写了一个 Magento 模块,但它没有被加载,我想调试它。

I just wrote a Magento module, but it's not being loaded and I'd like to debug it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

太傻旳人生 2024-12-01 00:56:51

这里有几个类和方法负责加载的各个阶段。

Mage_Core_Model_Config

为每个模块调用(返回一个 Mage_Core_Model_Config 表示主配置目录中模块的 XML 块(启用、版本等)):

/**
 * Get module config node
 *
 * @param string $moduleName
 * @return Varien_Simplexml_Object
 */
function getModuleConfig($moduleName='')
{
    $modules = $this->getNode('modules');
    if (''===$moduleName) {
        return $modules;
    } else {
        return $modules->$moduleName;
    }
}

为每个模块调用,但只是构建一个结构,但仍然不包含各个模块配置:

/**
 * Load declared modules configuration
 *
 * @param   null $mergeConfig depricated
 * @return  Mage_Core_Model_Config
 */
protected function _loadDeclaredModules($mergeConfig = null)
{
    $moduleFiles = $this->_getDeclaredModuleFiles();
    if (!$moduleFiles) {
        return ;
    }

    Varien_Profiler::start('config/load-modules-declaration');

    $unsortedConfig = new Mage_Core_Model_Config_Base();
    $unsortedConfig->loadString('<config/>');
    $fileConfig = new Mage_Core_Model_Config_Base();

    // load modules declarations
    foreach ($moduleFiles as $file) {
        $fileConfig->loadFile($file);
        $unsortedConfig->extend($fileConfig);
    }

    $moduleDepends = array();
    foreach ($unsortedConfig->getNode('modules')->children() as $moduleName => $moduleNode) {
        if (!$this->_isAllowedModule($moduleName)) {
            continue;
        }

        $depends = array();
        if ($moduleNode->depends) {
            foreach ($moduleNode->depends->children() as $depend) {
                $depends[$depend->getName()] = true;
            }
        }
        $moduleDepends[$moduleName] = array(
            'module'    => $moduleName,
            'depends'   => $depends,
            'active'    => ('true' === (string)$moduleNode->active ? true : false),
        );
    }

    // check and sort module dependence
    $moduleDepends = $this->_sortModuleDepends($moduleDepends);

    // create sorted config
    $sortedConfig = new Mage_Core_Model_Config_Base();
    $sortedConfig->loadString('<config><modules/></config>');

    foreach ($unsortedConfig->getNode()->children() as $nodeName => $node) {
        if ($nodeName != 'modules') {
            $sortedConfig->getNode()->appendChild($node);
        }
    }

    foreach ($moduleDepends as $moduleProp) {
        $node = $unsortedConfig->getNode('modules/'.$moduleProp['module']);
        $sortedConfig->getNode('modules')->appendChild($node);
    }

    $this->extend($sortedConfig);

    Varien_Profiler::stop('config/load-modules-declaration');
    return $this;
}

加载配置.xml、enterprise.xml、local.xml 等:

/**
 * Load base system configuration (config.xml and local.xml files)
 *
 * @return Mage_Core_Model_Config
 */
public function loadBase()
{
    $etcDir = $this->getOptions()->getEtcDir();
    $files = glob($etcDir.DS.'*.xml');
    $this->loadFile(current($files));
    while ($file = next($files)) {
        $merge = clone $this->_prototype;
        $merge->loadFile($file);
        $this->extend($merge);
    }
    if (in_array($etcDir.DS.'local.xml', $files)) {
        $this->_isLocalConfigLoaded = true;
    }
    return $this;
}

加载各个模块配置:

/**
 * Iterate all active modules "etc" folders and combine data from
 * specidied xml file name to one object
 *
 * @param   string $fileName
 * @param   null|Mage_Core_Model_Config_Base $mergeToObject
 * @return  Mage_Core_Model_Config_Base
 */
public function loadModulesConfiguration($fileName, $mergeToObject = null, $mergeModel=null)
{
    $disableLocalModules = !$this->_canUseLocalModules();

    if ($mergeToObject === null) {
        $mergeToObject = clone $this->_prototype;
        $mergeToObject->loadString('<config/>');
    }
    if ($mergeModel === null) {
        $mergeModel = clone $this->_prototype;
    }
    $modules = $this->getNode('modules')->children();
    foreach ($modules as $modName=>$module) {
        if ($module->is('active')) {
            if ($disableLocalModules && ('local' === (string)$module->codePool)) {
                continue;
            }
            $configFile = $this->getModuleDir('etc', $modName).DS.$fileName;
            if ($mergeModel->loadFile($configFile)) {
                $mergeToObject->extend($mergeModel, true);
            }
        }
    }
    return $mergeToObject;
}

Varien_Simplexml_Config (lib/Varien/Simplexml/Config.php)

实际读取各个模块配置的内容:

/**
 * Imports XML file
 *
 * @param string $filePath
 * @return boolean
 */
public function loadFile($filePath)
{
    if (!is_readable($filePath)) {
        //throw new Exception('Can not read xml file '.$filePath);
        return false;
    }

    $fileData = file_get_contents($filePath);
    $fileData = $this->processFileData($fileData);
    return $this->loadString($fileData, $this->_elementClass);
}

Dustin Oprea

Here are a couple of classes and the methods that are responsible for various stages of loading.

Mage_Core_Model_Config

Called for each module (returns a Mage_Core_Model_Config representing the module's XML block in the main config directory (enabled, version, etc..)):

/**
 * Get module config node
 *
 * @param string $moduleName
 * @return Varien_Simplexml_Object
 */
function getModuleConfig($moduleName='')
{
    $modules = $this->getNode('modules');
    if (''===$moduleName) {
        return $modules;
    } else {
        return $modules->$moduleName;
    }
}

Called for each module, but just builds a structure still without including the individual module configs:

/**
 * Load declared modules configuration
 *
 * @param   null $mergeConfig depricated
 * @return  Mage_Core_Model_Config
 */
protected function _loadDeclaredModules($mergeConfig = null)
{
    $moduleFiles = $this->_getDeclaredModuleFiles();
    if (!$moduleFiles) {
        return ;
    }

    Varien_Profiler::start('config/load-modules-declaration');

    $unsortedConfig = new Mage_Core_Model_Config_Base();
    $unsortedConfig->loadString('<config/>');
    $fileConfig = new Mage_Core_Model_Config_Base();

    // load modules declarations
    foreach ($moduleFiles as $file) {
        $fileConfig->loadFile($file);
        $unsortedConfig->extend($fileConfig);
    }

    $moduleDepends = array();
    foreach ($unsortedConfig->getNode('modules')->children() as $moduleName => $moduleNode) {
        if (!$this->_isAllowedModule($moduleName)) {
            continue;
        }

        $depends = array();
        if ($moduleNode->depends) {
            foreach ($moduleNode->depends->children() as $depend) {
                $depends[$depend->getName()] = true;
            }
        }
        $moduleDepends[$moduleName] = array(
            'module'    => $moduleName,
            'depends'   => $depends,
            'active'    => ('true' === (string)$moduleNode->active ? true : false),
        );
    }

    // check and sort module dependence
    $moduleDepends = $this->_sortModuleDepends($moduleDepends);

    // create sorted config
    $sortedConfig = new Mage_Core_Model_Config_Base();
    $sortedConfig->loadString('<config><modules/></config>');

    foreach ($unsortedConfig->getNode()->children() as $nodeName => $node) {
        if ($nodeName != 'modules') {
            $sortedConfig->getNode()->appendChild($node);
        }
    }

    foreach ($moduleDepends as $moduleProp) {
        $node = $unsortedConfig->getNode('modules/'.$moduleProp['module']);
        $sortedConfig->getNode('modules')->appendChild($node);
    }

    $this->extend($sortedConfig);

    Varien_Profiler::stop('config/load-modules-declaration');
    return $this;
}

Loads config.xml, enterprise.xml, local.xml, etc..:

/**
 * Load base system configuration (config.xml and local.xml files)
 *
 * @return Mage_Core_Model_Config
 */
public function loadBase()
{
    $etcDir = $this->getOptions()->getEtcDir();
    $files = glob($etcDir.DS.'*.xml');
    $this->loadFile(current($files));
    while ($file = next($files)) {
        $merge = clone $this->_prototype;
        $merge->loadFile($file);
        $this->extend($merge);
    }
    if (in_array($etcDir.DS.'local.xml', $files)) {
        $this->_isLocalConfigLoaded = true;
    }
    return $this;
}

Loads the individual module configs:

/**
 * Iterate all active modules "etc" folders and combine data from
 * specidied xml file name to one object
 *
 * @param   string $fileName
 * @param   null|Mage_Core_Model_Config_Base $mergeToObject
 * @return  Mage_Core_Model_Config_Base
 */
public function loadModulesConfiguration($fileName, $mergeToObject = null, $mergeModel=null)
{
    $disableLocalModules = !$this->_canUseLocalModules();

    if ($mergeToObject === null) {
        $mergeToObject = clone $this->_prototype;
        $mergeToObject->loadString('<config/>');
    }
    if ($mergeModel === null) {
        $mergeModel = clone $this->_prototype;
    }
    $modules = $this->getNode('modules')->children();
    foreach ($modules as $modName=>$module) {
        if ($module->is('active')) {
            if ($disableLocalModules && ('local' === (string)$module->codePool)) {
                continue;
            }
            $configFile = $this->getModuleDir('etc', $modName).DS.$fileName;
            if ($mergeModel->loadFile($configFile)) {
                $mergeToObject->extend($mergeModel, true);
            }
        }
    }
    return $mergeToObject;
}

Varien_Simplexml_Config (lib/Varien/Simplexml/Config.php)

What actually reads the individual module configs:

/**
 * Imports XML file
 *
 * @param string $filePath
 * @return boolean
 */
public function loadFile($filePath)
{
    if (!is_readable($filePath)) {
        //throw new Exception('Can not read xml file '.$filePath);
        return false;
    }

    $fileData = file_get_contents($filePath);
    $fileData = $this->processFileData($fileData);
    return $this->loadString($fileData, $this->_elementClass);
}

Dustin Oprea

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文