定义 Magento 类名称的字符串的名称

发布于 2024-10-05 07:11:35 字数 408 浏览 4 评论 0原文

Magento 使用工厂模式从类实例化对象。

$model  = Mage::getModel('catalog/product'); //Mage_Catalog_Model_Product by default
$helper = Mage::helper('catalog/data');   //Mage_Catalog_Helper_Data by default

这些字符串被扩展为类名,并且系统可以配置为替换默认值。

这些字符串应该被称为什么?我一直在滥用 URI 一词(有时用短语“类似 URI”来缓和这种滥用),但这并不完全正确。 “类名”似乎也不正确,因为它很容易引起混乱(您是在谈论工厂类名,还是实际的 PHP 类名?)

有人对此有任何权威吗?

Magento uses a factory pattern for instantiating objects from classes

$model  = Mage::getModel('catalog/product'); //Mage_Catalog_Model_Product by default
$helper = Mage::helper('catalog/data');   //Mage_Catalog_Helper_Data by default

These strings are expanded into classnames, and the System can be configured to replace the default values.

What are, or should, these strings be called? I've been abusing the term URI (sometimes tempering the abuse with the phrase "URI-like"), but that's not really right. "Class Name" doesn't seem right either, as it could easily cause confusion (Are you talking about the factory class name, or the actual PHP class name?)

Anyone have any stabs at authority on this?

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

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

发布评论

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

评论(6

一影成城 2024-10-12 07:11:36

在我的脑海中,我一直在使用“班级请求”这个词。您可以更进一步,将其设为“CRI”——类似于 URI,但不是“通用”。然而现在我想了一下,getModelcreateBlock不返回类,它们返回实例......

In my head I've been using the term "class request". You could go one step further and make that "CRI" - similar to URI but not 'Universal'. However now I think about it, getModel and createBlock don't return classes, they return instances...

两仪 2024-10-12 07:11:35

该字符串称为类(模型、块、助手 - 取决于使用上下文)别名。
别名命名规则为:组/实体

每个模块都可以定义自己的组或定义现有组的重写。

This string is called class (model, block, helper - depends from usage context) alias.
Alias naming rule is: group/entity.

Each module can define own group or define rewrites for existing one.

汹涌人海 2024-10-12 07:11:35

很好的问题艾伦。我很想知道其他使用工厂模式和“快捷方式”符号的框架如何称呼它。

我认为您对 URI 的“标识符”部分的理解是正确的。我认为“类标识符”或“模型标识符”有效。类标识符更通用一些,并且允许帮助程序场景。

Great question Alan. I'd be interested to hear what other frameworks that use Factory pattern and a "shortcut" notation call it.

I think you're on the right track with the "Identifier" part of URI. I would think "Class Identifier" or "model identifier" works. Class Identifier is a little more generic and allows for the helper scenario.

神妖 2024-10-12 07:11:35

我倾向于使用类句柄,因为它没有像“类路径”这样的包袱,而且它们似乎确实是某种类型的“句柄”。

I tend to use class handle, since it doesn't come with baggage like "class path", and they do seem to be "handles" of some type.

烂柯人 2024-10-12 07:11:35

坦率地说,这个进入特定类的内部快捷方式没有正式名称。

但我知道斜杠之前的第一部分称为“类组”,它不是模块名称,因为Magento可以共享同一组中不同模块的不同类(通过重写语句)。是的,有一个初始模块定义了默认的类前缀,但是您可以通过配置文件合并来更改此前缀。

第二部分我想调用模型/模型资源/块/助手名称。

一般来说,它可能被称为:

  • Mage::getModel() 的模型路径和 Mage::getSingleton()
  • Mage::getBlockSingleton() 的块路径Mage::helper()$layout->createBlock()
  • 辅助路径

,但此构造没有正式名称。所以这不是调用它的规则
这样:)


更新
Mage_Core_Model_Config::getGroupedClassName()中,这个构造被称为Class Id,所以也许这个名字更清楚。

Frankly speaking, there is no official name for this internal shortcut into a specific class.

But I know that the first part before slash is called "class group", it is not the module name, because Magento can share different classes from different modules in the same group (via rewrite statement). Yes, there is initial module which defines default class prefix, but you can change this prefix via config files merging.

The second part I would like to call a model/model resource/block/helper name.

And in general it might be called:

  • model path for Mage::getModel() and Mage::getSingleton()
  • block path for Mage::getBlockSingleton() and $layout->createBlock()
  • helper path for Mage::helper()

But there is no official name for this construction. So it is not the rule for calling it
that way :)


UPDATE:
In Mage_Core_Model_Config::getGroupedClassName() this construction is called Class Id, so maybe this name is more clear.

哽咽笑 2024-10-12 07:11:35

我会说“类路径”,但这可能会让一些使用过具有更正式含义和在语言/解释器/编译器内实现的语言的人感到困惑。

I would say a "class path" but that might confuse some who have worked in languages where that has a more formal meaning and an implementation within the language/interpreter/compiler.

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