上記の答えのデイビッドの助けがあれば、デイビッドは気にしないでしょう。
もっと詳しく説明してみます
Mage.phpから始めて、関数ヘルパーに移動します
public static function helper($name)
{
$registryKey = '_helper/' . $name;
if (!self::registry($registryKey)) {
$helperClass = self::getConfig()->getHelperClassName($name);
self::register($registryKey, new $helperClass);
}
return self::registry($registryKey);
}
a) $registryKey = '_helper/' . $name;
結果: $registryKey = _helper/sales
b)check now registry key exits ot not,if not then set a registry
変数
if (!self::registry($registryKey)) {
それtrue when system is first times
はセッションになります:
c) $helperClass = self::getConfig()->getHelperClassName($name);
つまり
$ name = sales Mage_Core_Model_Configクラス関数getHelperClassNameに送信して、ヘルパークラスの送信パラメーターを取得します
d)次にクラスname is registry variable
eを設定します
self::register($registryKey, new $helperClass);
結果: may be proper class name Mage_Sales_Helper_Data
Mage_Core_Model_ConfigクラスのgetHelperClassName関数に移動します
a)この関数は、ヘルパークラス名文字列$ name文字列を取得します。
public function getHelperClassName($helperName)
{
if (strpos($helperName, '/') === false) {
$helperName .= '/data';
}
return $this->getGroupedClassName('helper', $helperName);
}
機能の説明:
$helperName is sales
ロジック:
if (strpos($helperName, '/') === false) {
なる true as $helperName=sales then set $helperName=sales/data
b) return $this->getGroupedClassName('helper', $helperName);
詳細:
call function getGroupedClassName with params 'helper','sales/data'
and getGroupedClassName return class name of helper class
次にgoto関数 getGroupedClassName('helper','sales/data',null)
public function getGroupedClassName($groupType, $classId, $groupRootNode=null)
{
if (empty($groupRootNode)) {
$groupRootNode = 'global/'.$groupType.'s';
}
$classArr = explode('/', trim($classId));
$group = $classArr[0];
$class = !empty($classArr[1]) ? $classArr[1] : null;
if (isset($this->_classNameCache[$groupRootNode][$group][$class])) {
return $this->_classNameCache[$groupRootNode][$group][$class];
}
$config = $this->_xml->global->{$groupType.'s'}->{$group};
// First - check maybe the entity class was rewritten
$className = null;
if (isset($config->rewrite->$class)) {
$className = (string)$config->rewrite->$class;
} else {
/**
* Backwards compatibility for pre-MMDB extensions.
* In MMDB release resource nodes <..._mysql4> were renamed to <..._resource>. So <deprecatedNode> is left
* to keep name of previously used nodes, that still may be used by non-updated extensions.
*/
if ($config->deprecatedNode) {
$deprecatedNode = $config->deprecatedNode;
$configOld = $this->_xml->global->{$groupType.'s'}->$deprecatedNode;
if (isset($configOld->rewrite->$class)) {
$className = (string) $configOld->rewrite->$class;
}
}
}
// Second - if entity is not rewritten then use class prefix to form class name
if (empty($className)) {
if (!empty($config)) {
$className = $config->getClassName();
}
if (empty($className)) {
$className = 'mage_'.$group.'_'.$groupType;
}
if (!empty($class)) {
$className .= '_'.$class;
}
$className = uc_words($className);
}
$this->_classNameCache[$groupRootNode][$group][$class] = $className;
return $className;
}
**この関数タスク**
retrieve class name by class group
param string $groupType currently supported helper
param string $classId slash separated class identifier, ex. group/class
param string $groupRootNode optional config path for group config
return string
a)$classArr = explode('/', trim($classId));
結果:explode helper name(sales/data by /) for getting classs name in array $classArr
b)$class = !empty($classArr[1]) ? $classArr[1] : null;
結果:as $classArr[1] is data then value of $class is data
c) $config = $this->_xml->global->{$groupType.'s'}->{$group};
詳細:get config setting then $config = $this->_xml->global->helpers->sales;
d)$className = null;
詳細:set $className null
。
e)check rewrite class exits in config.xml files, check if class is rewrite then
you can easly get
コード:if(isset($ config-> rewrite-> $ class)){結果:if (isset($config->rewrite->data)) {
f)for default magento ,it false to goto else
if($ config-> deprecatedNode){
as deprecatedNode is for model($grouptype) and ,it only used for _mysql4
g) if (empty($className)) {
結果:
if sales helper not rewrite then if (empty($className)) { becomes true
h)if (!empty($config)) {
結果
:false
if (!empty($config)) { becomes false;`
i) if (empty($className)) {
結果:as $className is till
null then this code is true
j)クラスの$className = 'mage_'.$group.'_'.$groupType;
結果を作成します。
$group=sales
$groupTyp=helper
$className = 'mage_sales_helper';
k)
if (!empty($class)) {
$className .= '_'.$class;
}
結果:
as $class = data the this condition is true and $className = 'mage_sales_helper_data';
l)**大文字にする $className = uc_words($className)
; ここでreturn class return $ className; これはMage_Sales_Helper_Data **です
のおかげで
デビッドマナーズとラジーブKトミー