Name for the Strings that Define Magento Class Names
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, an开发者_Go百科d 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?
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.
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.
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.
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()
andMage::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.
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.
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...
精彩评论