singleton - meaning and location of string inside Magento's Mage:getSingleton -


here string see lot of similar in magento:

mage::getsingleton('checkout/type_onepage'); 

however, i'm trying find out class located, , meaning of string specifically. can explain me?

1/ model

you have know mage::getsingleton() going send singleton (which common development design pattern). magento, models can instantiated singleton

snippet app/mage.php can see magento using getmodel behind scene, , register have single instance of model if call twice via getsingleton (the purpose of singleton pattern itself, may know)

public static function getsingleton($modelclass='', array $arguments=array()) {     $registrykey = '_singleton/'.$modelclass;     if (!self::registry($registrykey)) {         self::register($registrykey, self::getmodel($modelclass, $arguments));     }     return self::registry($registrykey); } 

2/ handle

magento going map components classes via call handles. defined in config.xml of modules.

snippet app/code/core/mage/checkout/etc/config.xml stripped lot of xml

<?xml version="1.0"?> <config>     <modules>         <mage_checkout>             <version>1.6.0.0</version>         </mage_checkout>     </modules>     <global>         <models>             <checkout>                 <class>mage_checkout_model</class>             </checkout>         </models>     </global> </config> 

this snippet instruct magento add @ global configuration, models knows new set of model referenced through handle checkout maps classes beginning mage_checkout_model.

3/ right file or class

magento inherit zend framework mapping of class_to_file_path

class names may contain alphanumeric characters. numbers permitted in class names discouraged in cases. underscores permitted in place of path separator; filename "zend/db/table.php" must map class name "zend_db_table".

source : http://framework.zend.com/manual/1.12/en/coding-standard.naming-conventions.html

that means type of construction type_onepage map file having in path type/onepage.php , class name type_onepage

4/ 1 handle rule them all

(i had place pun somehow, sorry.)

now have handle model map mage_checkout_model , class type_onepage magento can assemble 2 in class being mage_checkout_model_type_onepage , file being mage/checkout/model/type/onepage.php. whole handle (checkout/type_onepage) constructed 2 part, first 1 before slash handle model (in case, helper or block... controller little different) , second one, after slash being path file folder / class prefix defined handle.

5/ , thought ?

to extensive in explanation have know modules defined via xml stands on app/etc/modules. since asking core module, file @ mage_all.xml i, once again stripped of lot of code.

<?xml version="1.0"?> <config>     <modules>         <mage_checkout>             <active>true</active>             <codepool>core</codepool>             <depends>                 <mage_sales/>                 <mage_cataloginventory/>             </depends>         </mage_checkout>     </modules> </config> 

for other module recommended way having file app/code/mage_checkout.xml name of file name of handle beside <modules> node in xml. core, since there lot of module grouped lot of them in mage_all.xml.

in file can see has same start config.xml of our module saw earlier, magento able match fact config.xml belongs module defined in mage_all.xml file. see codepool of module. in case, core, stock modules of magento. have there community or local.

for on, magento can map file correctly.
file in
app/code/ -- fixed, code there.
core/ -- codepool of module
mage/checkout/model/ -- handle mapped right class defined in config.xml , translated path based on zend framework convention
type/onepage.php -- file mapped type_onepage, following once again type/onepage convention.

all in 1 :

echo get_class(mage::getsingleton('checkout/type_onepage')); // output mage_checkout_model_type_onepage // located @ app/code/core/mage/checkout/model/type/onepage.php 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -