本文共 4776 字,大约阅读时间需要 15 分钟。
1
/ Core configuration class
mage_core_model_config
变量:
1.1
const CACHE_TAG = 'CONFIG';
1.2
/**
* Flag which allow use cache logic
*
* @var bool
*/
protected $_useCache = false;
1.3
/**
* Instructions for spitting config cache
* array(
* $sectionName => $recursionLevel
* )
* Recursion level provide availability cache subnodes separatly
*
* @var array
*/
protected $_cacheSections = array(
'admin' => 0,
'adminhtml' => 0,
'crontab' => 0,
'install' => 0,
'stores' => 1,
'websites' => 0
);
1.4
/**
* Loaded Configuration by cached sections
*
* @var array
*/
protected $_cacheLoadedSections = array();
1.5
/**
* Configuration options
*
* @var Mage_Core_Model_Config_Options
*/
protected $_options;
1.6
/**
* Storage for generated class names
*
* @var array
*/
protected $_classNameCache = array();
1.7
/**
* Storage for generated block class names
*
* @var unknown_type
*/
protected $_blockClassNameCache = array();
1.8
/**
* Storage of validated secure urls
*
* @var array
*/
protected $_secureUrlCache = array();
。。。。。。
**********************************************************
begin:
/**
* Class construct
*
* @param mixed $sourceData
*/
public function __construct($sourceData=null)
{
$this->setCacheId('config_global');
$this->_options = new Mage_Core_Model_Config_Options();
$this->_prototype = new Mage_Core_Model_Config_Base();
$this->_cacheChecksum = null;
parent::__construct($sourceData);
}
#继承顺序:
Mage_Core_Model_Config extends Mage_Core_Model_Config_Base
Mage_Core_Model_Config_Base extends Varien_Simplexml_Config
1
$this->setCacheId('config_global');
1.1
//文件地址:varien/simplexml/config.php
$this->setCacheId('config_global');
/**
* Enter description here...
*
* @param string $id
* @return Varien_Simplexml_Config
*/
public function setCacheId($id)
{
$this->_cacheId = $id;
return $this;
}
//总结
此函数的目的是:$this->_cacheId ='congif_global';
个人感觉是用来寻找cache在xml文件配置的配置信息的。
2
$this->_options = new Mage_Core_Model_Config_Options();
类Mage_core_Model_config_options类的初始化过程。
2.1
//age_core_Model_config_options的construct方法。
protected function _construct()
{
$appRoot= Mage::getRoot();
$root = dirname($appRoot);
$this->_data['app_dir'] = $appRoot;
$this->_data['base_dir'] = $root;
$this->_data['code_dir'] = $appRoot.DS.'code';
$this->_data['design_dir'] = $appRoot.DS.'design';
$this->_data['etc_dir'] = $appRoot.DS.'etc';
$this->_data['lib_dir'] = $root.DS.'lib';
$this->_data['locale_dir'] = $appRoot.DS.'locale';
$this->_data['media_dir'] = $root.DS.'media';
$this->_data['skin_dir'] = $root.DS.'skin';
$this->_data['var_dir'] = $this->getVarDir();
$this->_data['tmp_dir'] = $this->_data['var_dir'].DS.'tmp';
$this->_data['cache_dir'] = $this->_data['var_dir'].DS.'cache';
$this->_data['log_dir'] = $this->_data['var_dir'].DS.'log';
$this->_data['session_dir'] = $this->_data['var_dir'].DS.'session';
$this->_data['upload_dir'] = $this->_data['media_dir'].DS.'upload';
$this->_data['export_dir'] = $this->_data['var_dir'].DS.'export';
}
2.1.1
public static function getRoot()
{
return self::$_appRoot;
}
2.1.2
$root = dirname($appRoot);
反斜杠等问题的转换。形成规范的地址。
//总结
options类只要是为寻找文件的路径名服务的。
3
$this->_prototype = new Mage_Core_Model_Config_Base();
3.1
//Mage_Core_Model_Config_Base
public function __construct($sourceData=null)
{
$this->_elementClass = 'Mage_Core_Model_Config_Element';
parent::__construct($sourceData);
}
3.1.1
parent::__construct($sourceData);
/**
* Constructor
*
* Initializes XML for this configuration
*
* @see self::setXml
* @param string|Varien_Simplexml_Element $sourceData
* @param string $sourceType
*/
public function __construct($sourceData=null) {
if (is_null($sourceData)) {
return;
}
if ($sourceData instanceof Varien_Simplexml_Element) {
$this->setXml($sourceData);
} elseif (is_string($sourceData) && !empty($sourceData)) {
if (strlen($sourceData)<1000 && is_readable($sourceData)) {
$this->loadFile($sourceData);
} else {
$this->loadString($sourceData);
}
}
#$this->setCache(new Varien_Simplexml_Config_Cache_File());
#$this->getCache()->setConfig($this);
}
3.1.1.1
$this->setXml()
$this->loadFile()
$this->loadString()加载xml信息。
//总结
prototype:
1.指定elementClass ='Mage_Core_Model_Config_Element'.
2.如果有xml资源的赋值(也就是传入的值$sourceData),则加载。
4
$this->_cacheChecksum = null;
5
parent::__construct($sourceData);
//Mage_core_Model_config_base
public function __construct($sourceData=null)
{
$this->_elementClass = 'Mage_Core_Model_Config_Element';
parent::__construct($sourceData);
}
//如果有xml资源的赋值(也就是传入的值$sourceData),则加载。
总结:Mage_core_model_config的初始化,就是一系列变量的赋值
1。此函数的目的是:$this->_cacheId ='congif_global';
2.options类只要是为寻找文件的路径名服务的。
3.1.指定elementClass ='Mage_Core_Model_Config_Element'.
3.2.如果有xml资源的赋值(也就是传入的值$sourceData),则加载。
包括,映射文件对象名的赋值,文件地址寻找对象的赋值
初始化过程就是一个树的分叉工作,寻找自己的子功能的路径的赋值,子功能的初始化工作,完成的是:cache,options,element,xml(需要传入$sourceData)加载。
转载地址:http://lgdli.baihongyu.com/