Mage_Core_Model_Config Class Reference

Inheritance diagram for Mage_Core_Model_Config:

Mage_Core_Model_Config_Base Varien_Simplexml_Config

List of all members.

Public Member Functions

 __construct ($sourceData=null)
 getResourceModel ()
 getOptions ()
 init ($options=array())
 reinit ($options=array())
 getCache ()
 saveCache ($tags=array())
 removeCache ()
 cleanCache ()
 getSectionNode ($path)
 getNode ($path=null, $scope='', $scopeCode=null)
 loadModulesConfiguration ($fileName, $mergeToObject=null, $mergeModel=null)
 getTempVarDir ()
 getDistroServerVars ()
 substDistroServerVars ($data)
 getModuleConfig ($moduleName='')
 getModuleSetup ($module='')
 getBaseDir ($type='base')
 getVarDir ($path=null, $type='var')
 createDirIfNotExists ($dir)
 getModuleDir ($type, $moduleName)
 loadEventObservers ($area)
 getPathVars ($args=null)
 getGroupedClassName ($groupType, $classId, $groupRootNode=null)
 getBlockClassName ($blockType)
 getHelperClassName ($helperName)
 getModelClassName ($modelClass)
 getModelInstance ($modelClass='', $constructArguments=array())
 getNodeClassInstance ($path)
 getResourceModelInstance ($modelClass='', $constructArguments=array())
 getResourceConfig ($name)
 getResourceConnectionConfig ($name)
 getResourceTypeConfig ($type)
 getStoresConfigByPath ($path, $allowValues=array(), $useAsKey= 'id')
 shouldUrlBeSecure ($url)
 getTablePrefix ()
 getEventConfig ($area, $eventName)
 saveConfig ($path, $value, $scope= 'default', $scopeId=0)
 deleteConfig ($path, $scope= 'default', $scopeId=0)
 getFieldset ($name, $root= 'global')
 getResourceModelClassName ($modelClass)

Public Attributes

const CACHE_TAG = 'CONFIG'

Protected Member Functions

 _canUseLocalModules ()
 _canUseCacheForInit ()
 _getCacheLockId ()
 _saveSectionCache ($idPrefix, $sectionName, $source, $recursionLevel=0, $tags=array())
 _loadSectionCache ($sectionName)
 _loadCache ($id)
 _saveCache ($data, $id, $tags=array(), $lifetime=false)
 _removeCache ($id)
 _getDeclaredModuleFiles ()
 _loadDeclaredModules ($mergeConfig=null)
 _sortModuleDepends ($modules)
 _getResourceModelFactoryClassName ($modelClass)

Protected Attributes

 $_useCache = false
 $_cacheSections
 $_cacheLoadedSections = array()
 $_options
 $_classNameCache = array()
 $_blockClassNameCache = array()
 $_secureUrlCache = array()
 $_distroServerVars
 $_substServerVars
 $_resourceModel
 $_eventAreas
 $_dirExists = array()
 $_allowCacheForInit = true
 $_cachePartsForSave = array()
 $_baseDirCache = array()
 $_customEtcDir = null
 $_canUseLocalModules = null


Detailed Description

Definition at line 35 of file Config.php.


Constructor & Destructor Documentation

__construct ( sourceData = null  ) 

Class construct

Parameters:
mixed $sourceData

Reimplemented from Mage_Core_Model_Config_Base.

Definition at line 169 of file Config.php.

00170     {
00171         $this->setCacheId('config_global');
00172         $this->_options = new Mage_Core_Model_Config_Options();
00173         parent::__construct($sourceData);
00174     }


Member Function Documentation

_canUseCacheForInit (  )  [protected]

Check if cache can be used for config initialization

Returns:
bool

Definition at line 331 of file Config.php.

00332     {
00333         return Mage::app()->useCache('config') && $this->_allowCacheForInit && !$this->_loadCache($this->_getCacheLockId());
00334     }

_canUseLocalModules (  )  [protected]

Check local modules enable/disable flag If local modules are disbled remove local modules path from include dirs

return true if local modules enabled and false if disabled

Returns:
bool

Definition at line 300 of file Config.php.

00301     {
00302         if ($this->_canUseLocalModules !== null) {
00303             return $this->_canUseLocalModules;
00304         }
00305 
00306         $disableLocalModules = (string)$this->getNode('global/disable_local_modules');
00307         if (!empty($disableLocalModules)) {
00308             $disableLocalModules = (('true' === $disableLocalModules) || ('1' === $disableLocalModules));
00309         } else {
00310             $disableLocalModules = false;
00311         }
00312 
00313         if ($disableLocalModules) {
00314             set_include_path(
00315                 // excluded '/app/code/local'
00316                 BP . DS . 'app' . DS . 'code' . DS . 'community' . PS .
00317                 BP . DS . 'app' . DS . 'code' . DS . 'core' . PS .
00318                 BP . DS . 'lib' . PS .
00319                 Mage::registry('original_include_path')
00320             );
00321         }
00322         $this->_canUseLocalModules = !$disableLocalModules;
00323         return $this->_canUseLocalModules;
00324     }

_getCacheLockId (  )  [protected]

Get lock flag cache identifier

Returns:
string

Definition at line 351 of file Config.php.

00352     {
00353         return $this->getCacheId().'.lock';
00354     }

_getDeclaredModuleFiles (  )  [protected]

Retrive Declared Module file list

Returns:
array

Definition at line 567 of file Config.php.

00568     {
00569         $etcDir = $this->getOptions()->getEtcDir();
00570         $moduleFiles = glob($etcDir . DS . 'modules' . DS . '*.xml');
00571 
00572         if (!$moduleFiles) {
00573             return false;
00574         }
00575 
00576         $collectModuleFiles = array(
00577             'base'   => array(),
00578             'mage'   => array(),
00579             'custom' => array()
00580         );
00581 
00582         foreach ($moduleFiles as $v) {
00583             $name = explode(DIRECTORY_SEPARATOR, $v);
00584             $name = substr($name[count($name) - 1], 0, -4);
00585 
00586             if ($name == 'Mage_All') {
00587                 $collectModuleFiles['base'][] = $v;
00588             }
00589             elseif (substr($name, 0, 5) == 'Mage_') {
00590                 $collectModuleFiles['mage'][] = $v;
00591             }
00592             else {
00593                 $collectModuleFiles['custom'][] = $v;
00594             }
00595         }
00596 
00597         return array_merge(
00598             $collectModuleFiles['base'],
00599             $collectModuleFiles['mage'],
00600             $collectModuleFiles['custom']
00601         );
00602     }

_getResourceModelFactoryClassName ( modelClass  )  [protected]

Get factory class name for for a resource

Parameters:
string $modelClass
Returns:
string|false

Definition at line 1311 of file Config.php.

01312     {
01313         $classArr = explode('/', $modelClass);
01314 
01315         $resourceModel = false;
01316 
01317         if (!isset($this->_xml->global->models->{$classArr[0]})) {
01318             return false;
01319         }
01320 
01321         $module = $this->_xml->global->models->{$classArr[0]};
01322 
01323         if ((count($classArr)==2)
01324             && isset($module->{$classArr[1]}->resourceModel)
01325             && $resourceInfo = $module->{$classArr[1]}->resourceModel) {
01326             $resourceModel = (string) $resourceInfo;
01327         }
01328         elseif (isset($module->resourceModel) && $resourceInfo = $module->resourceModel) {
01329             $resourceModel = (string) $resourceInfo;
01330         }
01331 
01332         if (!$resourceModel) {
01333             return false;
01334         }
01335         return $resourceModel . '/' . $classArr[1];
01336     }

_loadCache ( id  )  [protected]

Load cached data by identifier

Parameters:
string $id
Returns:
string

Reimplemented from Varien_Simplexml_Config.

Definition at line 443 of file Config.php.

00444     {
00445         return Mage::app()->loadCache($id);
00446     }

_loadDeclaredModules ( mergeConfig = null  )  [protected]

Load declared modules configuration

Parameters:
null $mergeConfig depricated
Returns:
Mage_Core_Model_Config

Definition at line 610 of file Config.php.

00611     {
00612         $moduleFiles = $this->_getDeclaredModuleFiles();
00613         if (!$moduleFiles) {
00614             return ;
00615         }
00616 
00617         Varien_Profiler::start('config/load-modules-declaration');
00618 
00619         $unsortedConfig = new Mage_Core_Model_Config_Base();
00620         $unsortedConfig->loadString('<config/>');
00621         $fileConfig = new Mage_Core_Model_Config_Base();
00622 
00623         // load modules declarations
00624         foreach ($moduleFiles as $file) {
00625             $fileConfig->loadFile($file);
00626             $unsortedConfig->extend($fileConfig);
00627         }
00628 
00629         $moduleDepends = array();
00630         foreach ($unsortedConfig->getNode('modules')->children() as $moduleName => $moduleNode) {
00631             $depends = array();
00632             if ($moduleNode->depends) {
00633                 foreach ($moduleNode->depends->children() as $depend) {
00634                     $depends[$depend->getName()] = true;
00635                 }
00636             }
00637             $moduleDepends[$moduleName] = array(
00638                 'module'    => $moduleName,
00639                 'depends'   => $depends,
00640                 'active'    => ('true' === (string)$moduleNode->active ? true : false),
00641             );
00642         }
00643 
00644         // check and sort module dependens
00645         $moduleDepends = $this->_sortModuleDepends($moduleDepends);
00646 
00647         // create sorted config
00648         $sortedConfig = new Mage_Core_Model_Config_Base();
00649         $sortedConfig->loadString('<config><modules/></config>');
00650 
00651         foreach ($unsortedConfig->getNode()->children() as $nodeName => $node) {
00652             if ($nodeName != 'modules') {
00653                 $sortedConfig->getNode()->appendChild($node);
00654             }
00655         }
00656 
00657         foreach ($moduleDepends as $moduleProp) {
00658             $node = $unsortedConfig->getNode('modules/'.$moduleProp['module']);
00659             $sortedConfig->getNode('modules')->appendChild($node);
00660         }
00661 
00662         $this->extend($sortedConfig);
00663 
00664         Varien_Profiler::stop('config/load-modules-declaration');
00665         return $this;
00666     }

_loadSectionCache ( sectionName  )  [protected]

Load config section cached data

Parameters:
string $sectionName
Returns:
Varien_Simplexml_Element

If we can't load section cache (problems with cache storage)

Definition at line 419 of file Config.php.

00420     {
00421         $cacheId = $this->getCacheId() . '_' . $sectionName;
00422         $xmlString = $this->_loadCache($cacheId);
00423 
00424         /**
00425          * If we can't load section cache (problems with cache storage)
00426          */
00427         if (!$xmlString) {
00428             $this->_useCache = false;
00429             $this->reinit($this->_options);
00430             return false;
00431         } else {
00432             $xml = simplexml_load_string($xmlString, $this->_elementClass);
00433             return $xml;
00434         }
00435     }

_removeCache ( id  )  [protected]

Clear cache data by id

Parameters:
string $id
Returns:
Mage_Core_Model_Config

Reimplemented from Varien_Simplexml_Config.

Definition at line 468 of file Config.php.

00469     {
00470         return Mage::app()->removeCache($id);
00471     }

_saveCache ( data,
id,
tags = array(),
lifetime = false 
) [protected]

Save cache data

Parameters:
string $data
string $id
array $tags
false|int $lifetime
Returns:
Mage_Core_Model_Config

Reimplemented from Varien_Simplexml_Config.

Definition at line 457 of file Config.php.

00458     {
00459         return Mage::app()->saveCache($data, $id, $tags, $lifetime);
00460     }

_saveSectionCache ( idPrefix,
sectionName,
source,
recursionLevel = 0,
tags = array() 
) [protected]

Save cache of specified

Parameters:
string $idPrefix cache id prefix
string $sectionName
Varien_Simplexml_Element $source
int $recursionLevel
Returns:
Mage_Core_Model_Config

Definition at line 399 of file Config.php.

00400     {
00401         if ($source && $source->$sectionName) {
00402             $cacheId = $idPrefix . '_' . $sectionName;
00403             if ($recursionLevel > 0) {
00404                 foreach ($source->$sectionName->children() as $subSectionName => $node) {
00405                     $this->_saveSectionCache($cacheId, $subSectionName, $source->$sectionName, $recursionLevel-1, $tags);
00406                 }
00407             }
00408             $this->_cachePartsForSave[$cacheId] = $source->$sectionName->asNiceXml('', false);
00409         }
00410         return $this;
00411     }

_sortModuleDepends ( modules  )  [protected]

Sort modules and check depends

Parameters:
array $modules
Returns:
array

Definition at line 674 of file Config.php.

00675     {
00676         foreach ($modules as $moduleName => $moduleProps) {
00677             $depends = $moduleProps['depends'];
00678             foreach ($moduleProps['depends'] as $depend => $true) {
00679                 if ($moduleProps['active'] && ((!isset($modules[$depend])) || empty($modules[$depend]['active']))) {
00680                     Mage::throwException(Mage::helper('core')->__('Module "%1$s" requires module "%2$s"', $moduleName, $depend));
00681                 }
00682                 $depends = array_merge($depends, $modules[$depend]['depends']);
00683             }
00684             $modules[$moduleName]['depends'] = $depends;
00685         }
00686         $modules = array_values($modules);
00687 
00688         $size = count($modules) - 1;
00689         for ($i = $size; $i >= 0; $i--) {
00690             for ($j = $size; $i < $j; $j--) {
00691                 if (isset($modules[$i]['depends'][$modules[$j]['module']])) {
00692                     $value       = $modules[$i];
00693                     $modules[$i] = $modules[$j];
00694                     $modules[$j] = $value;
00695                 }
00696             }
00697         }
00698 
00699         $definedModules = array();
00700         foreach ($modules as $moduleProp) {
00701             foreach ($moduleProp['depends'] as $dependModule => $true) {
00702                 if (!isset($definedModules[$dependModule])) {
00703                     Mage::throwException(
00704                         Mage::helper('core')->__('Module "%1$s" can not be depended from "%2$s"', $moduleProp['module'], $dependModule)
00705                     );
00706                 }
00707             }
00708             $definedModules[$moduleProp['module']] = true;
00709         }
00710 
00711         return $modules;
00712     }

cleanCache (  ) 

Configuration cache clean process

Returns:
Mage_Core_Model_Config

Definition at line 489 of file Config.php.

00490     {
00491         return $this->reinit();
00492     }

createDirIfNotExists ( dir  ) 

Definition at line 878 of file Config.php.

00879     {
00880         return $this->getOptions()->createDirIfNotExists($dir);
00881     }

deleteConfig ( path,
scope = 'default',
scopeId = 0 
)

Delete config value from DB

Parameters:
string $path
string $scope
int $scopeId
Returns:
Mage_Core_Model_Config

Definition at line 1281 of file Config.php.

01282     {
01283         $resource = $this->getResourceModel();
01284         $resource->deleteConfig(rtrim($path, '/'), $scope, $scopeId);
01285 
01286         return $this;
01287     }

getBaseDir ( type = 'base'  ) 

Get base filesystem directory. depends on $type

If $moduleName is specified retrieves specific value for the module.

Deprecated:
in favor of Mage_Core_Model_Config_Options
Todo:
get global dir config
Parameters:
string $type
Returns:
string

Definition at line 857 of file Config.php.

00858     {
00859         return $this->getOptions()->getDir($type);
00860     }

getBlockClassName ( blockType  ) 

Retrieve block class name

Parameters:
string $blockType
Returns:
string

Definition at line 1032 of file Config.php.

01033     {
01034         if (strpos($blockType, '/')===false) {
01035             return $blockType;
01036         }
01037         return $this->getGroupedClassName('block', $blockType);
01038     }

getCache (  ) 

Retrieve cache object

Returns:
Zend_Cache_Frontend_File

Reimplemented from Varien_Simplexml_Config.

Definition at line 341 of file Config.php.

00342     {
00343         return Mage::app()->getCache();
00344     }

getDistroServerVars (  ) 

Get default server variables values

Returns:
array

Definition at line 763 of file Config.php.

00764     {
00765         if (!$this->_distroServerVars) {
00766 
00767             if (isset($_SERVER['SCRIPT_NAME']) && isset($_SERVER['HTTP_HOST'])) {
00768                 $secure = (!empty($_SERVER['HTTPS']) && ($_SERVER['HTTPS']!='off')) || $_SERVER['SERVER_PORT']=='443';
00769                 $scheme = ($secure ? 'https' : 'http') . '://' ;
00770 
00771                 $hostArr = explode(':', $_SERVER['HTTP_HOST']);
00772                 $host = $hostArr[0];
00773                 $port = isset($hostArr[1]) && (!$secure && $hostArr[1]!=80 || $secure && $hostArr[1]!=443) ? ':'.$hostArr[1] : '';
00774                 $path = Mage::app()->getRequest()->getBasePath();
00775 
00776                 $baseUrl = $scheme.$host.$port.rtrim($path, '/').'/';
00777             } else {
00778                 $baseUrl = 'http://localhost/';
00779             }
00780 
00781             $options = $this->getOptions();
00782             $this->_distroServerVars = array(
00783                 'root_dir'  => $options->getBaseDir(),
00784                 'app_dir'   => $options->getAppDir(),
00785                 'var_dir'   => $options->getVarDir(),
00786                 'base_url'  => $baseUrl,
00787             );
00788 
00789             foreach ($this->_distroServerVars as $k=>$v) {
00790                 $this->_substServerVars['{{'.$k.'}}'] = $v;
00791             }
00792         }
00793         return $this->_distroServerVars;
00794     }

getEventConfig ( area,
eventName 
)

Get events configuration

Parameters:
string $area event area
string $eventName event name
Returns:
Mage_Core_Model_Config_Element

Definition at line 1247 of file Config.php.

01248     {
01249         //return $this->getNode($area)->events->{$eventName};
01250         if (!isset($this->_eventAreas[$area])) {
01251             $this->_eventAreas[$area] = $this->getNode($area)->events;
01252         }
01253         return $this->_eventAreas[$area]->{$eventName};
01254     }

getFieldset ( name,
root = 'global' 
)

Get fieldset from configuration

Parameters:
string $name fieldset name
string $root fieldset area, could be 'admin'
Returns:
null|array

Definition at line 1296 of file Config.php.

01297     {
01298         $rootNode = $this->getNode($root.'/fieldsets');
01299         if (!$rootNode) {
01300             return null;
01301         }
01302         return $rootNode->$name ? $rootNode->$name->children() : null;
01303     }

getGroupedClassName ( groupType,
classId,
groupRootNode = null 
)

Retrieve class name by class group

Parameters:
string $groupType currently supported model, block, helper
string $classId slash separated class identifier, ex. group/class
string $groupRootNode optional config path for group config
Returns:
string

Definition at line 990 of file Config.php.

00991     {
00992         if (empty($groupRootNode)) {
00993             $groupRootNode = 'global/'.$groupType.'s';
00994         }
00995 
00996         $classArr = explode('/', trim($classId));
00997         $group = $classArr[0];
00998         $class = !empty($classArr[1]) ? $classArr[1] : null;
00999 
01000         if (isset($this->_classNameCache[$groupRootNode][$group][$class])) {
01001             return $this->_classNameCache[$groupRootNode][$group][$class];
01002         }
01003 
01004         //$config = $this->getNode($groupRootNode.'/'.$group);
01005         $config = $this->_xml->global->{$groupType.'s'}->{$group};
01006 
01007         if (isset($config->rewrite->$class)) {
01008             $className = (string)$config->rewrite->$class;
01009         } else {
01010             if (!empty($config)) {
01011                 $className = $config->getClassName();
01012             }
01013             if (empty($className)) {
01014                 $className = 'mage_'.$group.'_'.$groupType;
01015             }
01016             if (!empty($class)) {
01017                 $className .= '_'.$class;
01018             }
01019             $className = uc_words($className);
01020         }
01021 
01022         $this->_classNameCache[$groupRootNode][$group][$class] = $className;
01023         return $className;
01024     }

getHelperClassName ( helperName  ) 

Retrieve helper class name

Parameters:
string $name
Returns:
string

Definition at line 1046 of file Config.php.

01047     {
01048         if (strpos($helperName, '/')===false) {
01049             $helperName .= '/data';
01050         }
01051         return $this->getGroupedClassName('helper', $helperName);
01052     }

getModelClassName ( modelClass  ) 

Retrieve modele class name

Parameters:
sting $modelClass
Returns:
string

Definition at line 1060 of file Config.php.

01061     {
01062         $modelClass = trim($modelClass);
01063         if (strpos($modelClass, '/')===false) {
01064             return $modelClass;
01065         }
01066         return $this->getGroupedClassName('model', $modelClass);
01067     }

getModelInstance ( modelClass = '',
constructArguments = array() 
)

Get model class instance.

Example: $config->getModelInstance('catalog/product')

Will instantiate Mage_Catalog_Model_Mysql4_Product

Parameters:
string $modelClass
array|object $constructArguments
Returns:
Mage_Core_Model_Abstract

Definition at line 1081 of file Config.php.

01082     {
01083         $className = $this->getModelClassName($modelClass);
01084         if (class_exists($className)) {
01085             Varien_Profiler::start('CORE::create_object_of::'.$className);
01086             $obj = new $className($constructArguments);
01087             Varien_Profiler::stop('CORE::create_object_of::'.$className);
01088             return $obj;
01089         } else {
01090             #throw Mage::exception('Mage_Core', Mage::helper('core')->__('Model class does not exist: %s', $modelClass));
01091             return false;
01092         }
01093     }

getModuleConfig ( moduleName = ''  ) 

Get module config node

Parameters:
string $moduleName
Returns:
Varien_Simplexml_Object

Definition at line 812 of file Config.php.

00813     {
00814         $modules = $this->getNode('modules');
00815         if (''===$moduleName) {
00816             return $modules;
00817         } else {
00818             return $modules->$moduleName;
00819         }
00820     }

getModuleDir ( type,
moduleName 
)

Get module directory by directory type

Parameters:
string $type
string $moduleName
Returns:
string

Definition at line 890 of file Config.php.

00891     {
00892         $codePool = (string)$this->getModuleConfig($moduleName)->codePool;
00893         $dir = $this->getOptions()->getCodeDir().DS.$codePool.DS.uc_words($moduleName, DS);
00894 
00895         switch ($type) {
00896             case 'etc':
00897                 $dir .= DS.'etc';
00898                 break;
00899 
00900             case 'controllers':
00901                 $dir .= DS.'controllers';
00902                 break;
00903 
00904             case 'sql':
00905                 $dir .= DS.'sql';
00906                 break;
00907 
00908             case 'locale':
00909                 $dir .= DS.'locale';
00910                 break;
00911         }
00912 
00913         $dir = str_replace('/', DS, $dir);
00914         return $dir;
00915     }

getModuleSetup ( module = ''  ) 

Get module setup class instance.

Defaults to Mage_Core_Setup

Parameters:
string|Varien_Simplexml_Object $module
Returns:
object

Definition at line 830 of file Config.php.

00831     {
00832         $className = 'Mage_Core_Setup';
00833         if (''!==$module) {
00834             if (is_string($module)) {
00835                 $module = $this->getModuleConfig($module);
00836             }
00837             if (isset($module->setup)) {
00838                 $moduleClassName = $module->setup->getClassName();
00839                 if (!empty($moduleClassName)) {
00840                     $className = $moduleClassName;
00841                 }
00842             }
00843         }
00844         return new $className($module);
00845     }

getNode ( path = null,
scope = '',
scopeCode = null 
)

Returns node found by the $path and scope info

Parameters:
string $path
string $scope
string $scopeCode
Returns:
Mage_Core_Model_Config_Element

Check path cache loading

Definition at line 528 of file Config.php.

00529     {
00530         if ($scope !== '') {
00531             if (('store' === $scope) || ('website' === $scope)) {
00532                 $scope .= 's';
00533             }
00534             if (('default' !== $scope) && is_int($scopeCode)) {
00535                 if ('stores' == $scope) {
00536                     $scopeCode = Mage::app()->getStore($scopeCode)->getCode();
00537                 } elseif ('websites' == $scope) {
00538                     $scopeCode = Mage::app()->getWebsite($scopeCode)->getCode();
00539                 } else {
00540                     Mage::throwException(Mage::helper('core')->__('Unknown scope "%s"', $scope));
00541                 }
00542             }
00543             $path = $scope . ($scopeCode ? '/' . $scopeCode : '' ) . (empty($path) ? '' : '/' . $path);
00544         }
00545 
00546         /**
00547          * Check path cache loading
00548          */
00549         if ($this->_useCache && ($path !== null)) {
00550             $path   = explode('/', $path);
00551             $section= $path[0];
00552             if (isset($this->_cacheSections[$section])) {
00553                 $res = $this->getSectionNode($path);
00554                 if ($res !== false) {
00555                     return $res;
00556                 }
00557             }
00558         }
00559         return parent::getNode($path);
00560     }

getNodeClassInstance ( path  ) 

Definition at line 1095 of file Config.php.

01096     {
01097         $config = Mage::getConfig()->getNode($path);
01098         if (!$config) {
01099             return false;
01100         } else {
01101             $className = $config->getClassName();
01102             return new $className();
01103         }
01104     }

getOptions (  ) 

Get configuration options object

Returns:
Mage_Core_Model_Config_Options

Definition at line 194 of file Config.php.

00195     {
00196         return $this->_options;
00197     }

getPathVars ( args = null  ) 

Get standard path variables.

To be used in blocks, templates, etc.

Parameters:
array|string $args Module name if string
Returns:
array

Definition at line 972 of file Config.php.

00973     {
00974         $path = array();
00975 
00976         $path['baseUrl'] = Mage::getBaseUrl();
00977         $path['baseSecureUrl'] = Mage::getBaseUrl('link', true);
00978 
00979         return $path;
00980     }

getResourceConfig ( name  ) 

Get resource configuration for resource name

Parameters:
string $name
Returns:
Varien_Simplexml_Object

Definition at line 1128 of file Config.php.

01129     {
01130         return $this->_xml->global->resources->{$name};
01131     }

getResourceConnectionConfig ( name  ) 

Get connection configuration

Parameters:
string $name
Returns:
Varien_Simplexml_Element

Definition at line 1139 of file Config.php.

01140     {
01141         $config = $this->getResourceConfig($name);
01142         if ($config) {
01143             $conn = $config->connection;
01144             if (!empty($conn->use)) {
01145                 return $this->getResourceConnectionConfig((string)$conn->use);
01146             } else {
01147                 return $conn;
01148             }
01149         }
01150         return false;
01151     }

getResourceModel (  ) 

Get config resource model

Returns:
Mage_Core_Store_Mysql4_Config

Definition at line 181 of file Config.php.

00182     {
00183         if (is_null($this->_resourceModel)) {
00184             $this->_resourceModel = Mage::getResourceModel('core/config');
00185         }
00186         return $this->_resourceModel;
00187     }

getResourceModelClassName ( modelClass  ) 

Get a resource model class name

Parameters:
string $modelClass
Returns:
string|false

Definition at line 1344 of file Config.php.

01345     {
01346         $factoryName = $this->_getResourceModelFactoryClassName($modelClass);
01347         if ($factoryName) {
01348             return $this->getModelClassName($factoryName);
01349         }
01350         return false;
01351     }

getResourceModelInstance ( modelClass = '',
constructArguments = array() 
)

Get resource model object by alias

Parameters:
string $modelClass
array $constructArguments
Returns:
object

Definition at line 1113 of file Config.php.

01114     {
01115         $factoryName = $this->_getResourceModelFactoryClassName($modelClass);
01116         if (!$factoryName) {
01117             return false;
01118         }
01119         return $this->getModelInstance($factoryName, $constructArguments);
01120     }

getResourceTypeConfig ( type  ) 

Retrieve resource type configuration for resource name

Parameters:
string $type
Returns:
Varien_Simplexml_Object

Definition at line 1159 of file Config.php.

01160     {
01161         return $this->_xml->global->resource->connection->types->{$type};
01162     }

getSectionNode ( path  ) 

Get node value from cached section data

Parameters:
array $path
Returns:
Mage_Core_Model_Config

Definition at line 500 of file Config.php.

00501     {
00502         $section    = $path[0];
00503         $recursion  = $this->_cacheSections[$section];
00504         $sectioPath = array_slice($path, 0, $recursion+1);
00505         $path       = array_slice($path, $recursion+1);
00506         $sectionKey = implode('_', $sectioPath);
00507 
00508         if (!isset($this->_cacheLoadedSections[$sectionKey])) {
00509             Varien_Profiler::start('mage::app::init::config::section::'.$sectionKey);
00510             $this->_cacheLoadedSections[$sectionKey] = $this->_loadSectionCache($sectionKey);
00511             Varien_Profiler::stop('mage::app::init::config::section::'.$sectionKey);
00512         }
00513 
00514         if ($this->_cacheLoadedSections[$sectionKey] === false) {
00515             return false;
00516         }
00517         return $this->_cacheLoadedSections[$sectionKey]->descend($path);
00518     }

getStoresConfigByPath ( path,
allowValues = array(),
useAsKey = 'id' 
)

Retrieve store Ids for $path with checking

if empty $allowValues then retrieve all stores values

return array($storeId=>$pathValue)

Parameters:
string $path
array $allowValues
Returns:
array

Definition at line 1175 of file Config.php.

01176     {
01177         $storeValues = array();
01178         $stores = $this->getNode('stores');
01179         foreach ($stores->children() as $code => $store) {
01180             switch ($useAsKey) {
01181                 case 'id':
01182                     $key = (int) $store->descend('system/store/id');
01183                     break;
01184 
01185                 case 'code':
01186                     $key = $code;
01187                     break;
01188 
01189                 case 'name':
01190                     $key = (string) $store->descend('system/store/name');
01191             }
01192             if ($key === false) {
01193                 continue;
01194             }
01195 
01196             $pathValue = (string) $store->descend($path);
01197 
01198             if (empty($allowValues)) {
01199                 $storeValues[$key] = $pathValue;
01200             }
01201             elseif(in_array($pathValue, $allowValues)) {
01202                 $storeValues[$key] = $pathValue;
01203             }
01204         }
01205         return $storeValues;
01206     }

getTablePrefix (  ) 

Get DB table names prefix

Returns:
string

Definition at line 1235 of file Config.php.

01236     {
01237         return $this->_xml->global->resources->db->table_prefix;
01238     }

getTempVarDir (  ) 

Retrieve temporary directory path

Returns:
string

Definition at line 753 of file Config.php.

00754     {
00755         return $this->getOptions()->getVarDir();
00756     }

getVarDir ( path = null,
type = 'var' 
)

Get temporary data directory name

Parameters:
string $path
string $type
Returns:
string

Definition at line 869 of file Config.php.

00870     {
00871         $dir = Mage::getBaseDir($type).($path!==null ? DS.$path : '');
00872         if (!$this->createDirIfNotExists($dir)) {
00873             return false;
00874         }
00875         return $dir;
00876     }

init ( options = array()  ) 

Initialization of core configuration

Returns:
Mage_Core_Model_Config

Load base configuration data

Load modules configuration data

Load local configuration data

Load configuration from DB

Definition at line 204 of file Config.php.

00205     {
00206         $this->setCacheChecksum(null);
00207         $this->_cacheLoadedSections = array();
00208         if (is_array($options)) {
00209             $this->getOptions()->addData($options);
00210         }
00211 
00212         $etcDir = $this->getOptions()->getEtcDir();
00213 
00214         $localConfigLoaded  = $this->loadFile($etcDir.DS.'local.xml');
00215 
00216         if (Mage::isInstalled()) {
00217             if ($this->_canUseCacheForInit()) {
00218                 Varien_Profiler::start('mage::app::init::config::load_cache');
00219                 $loaded = $this->loadCache();
00220                 Varien_Profiler::stop('mage::app::init::config::load_cache');
00221                 if ($loaded) {
00222                     $this->_useCache = true;
00223                     return $this;
00224                 }
00225             }
00226         }
00227 
00228         /**
00229          * Load base configuration data
00230          */
00231         $configFile = $etcDir.DS.'config.xml';
00232         $this->loadFile($configFile);
00233         $this->_loadDeclaredModules();
00234 
00235         /**
00236          * Load modules configuration data
00237          */
00238         Varien_Profiler::start('config/load-modules');
00239         $this->loadModulesConfiguration('config.xml', $this);
00240         Varien_Profiler::stop('config/load-modules');
00241 
00242         /**
00243          * Load local configuration data
00244          */
00245         Varien_Profiler::start('config/load-local');
00246 
00247         $mergeConfig = new Mage_Core_Model_Config_Base();
00248         $configFile  = $etcDir.DS.'local.xml';
00249         if (is_readable($configFile)) {
00250             $mergeConfig->loadFile($configFile);
00251             $this->extend($mergeConfig);
00252         }
00253 
00254         Varien_Profiler::stop('config/load-local');
00255 
00256         $this->applyExtends();
00257 
00258         /**
00259          * Load configuration from DB
00260          */
00261         if ($localConfigLoaded) {
00262             Varien_Profiler::start('dbUpdates');
00263             Mage_Core_Model_Resource_Setup::applyAllUpdates();
00264             Varien_Profiler::stop('dbUpdates');
00265 
00266             Varien_Profiler::start('config/load-db');
00267             $dbConf = $this->getResourceModel();
00268             $dbConf->loadToXml($this);
00269             Varien_Profiler::stop('config/load-db');
00270         }
00271 
00272         if (Mage::app()->useCache('config')) {
00273             $this->saveCache(array(self::CACHE_TAG));
00274         }
00275 
00276         return $this;
00277     }

loadEventObservers ( area  ) 

Load event observers for an area (front, admin)

Parameters:
string $area
Returns:
boolean

Definition at line 923 of file Config.php.

00924     {
00925         $events = $this->getNode("$area/events");
00926         if ($events) {
00927             $events = $events->children();
00928         }
00929         else {
00930             return false;
00931         }
00932 
00933         foreach ($events as $event) {
00934             $eventName = $event->getName();
00935             $observers = $event->observers->children();
00936             foreach ($observers as $observer) {
00937                 switch ((string)$observer->type) {
00938                     case 'singleton':
00939                         $callback = array(
00940                             Mage::getSingleton((string)$observer->class),
00941                             (string)$observer->method
00942                         );
00943                         break;
00944                     case 'object':
00945                     case 'model':
00946                         $callback = array(
00947                             Mage::getModel((string)$observer->class),
00948                             (string)$observer->method
00949                         );
00950                         break;
00951                     default:
00952                         $callback = array($observer->getClassName(), (string)$observer->method);
00953                         break;
00954                 }
00955 
00956                 $args = (array)$observer->args;
00957                 $observerClass = $observer->observer_class ? (string)$observer->observer_class : '';
00958                 Mage::addObserver($eventName, $callback, $args, $observer->getName(), $observerClass);
00959             }
00960         }
00961         return true;
00962     }

loadModulesConfiguration ( fileName,
mergeToObject = null,
mergeModel = null 
)

Iterate all active modules "etc" folders and combine data from specidied xml file name to one object

Parameters:
string $fileName
null|Mage_Core_Model_Config_Base $mergeToObject
Returns:
Mage_Core_Model_Config_Base

Definition at line 722 of file Config.php.

00723     {
00724         $disableLocalModules    = !$this->_canUseLocalModules();
00725 
00726         if ($mergeToObject === null) {
00727             $mergeToObject = new Mage_Core_Model_Config_Base();
00728             $mergeToObject->loadString('<config/>');
00729         }
00730         if ($mergeModel === null) {
00731             $mergeModel = new Mage_Core_Model_Config_Base();
00732         }
00733         $modules = $this->getNode('modules')->children();
00734         foreach ($modules as $modName=>$module) {
00735             if ($module->is('active')) {
00736                 if ($disableLocalModules && ('local' === (string)$module->codePool)) {
00737                     continue;
00738                 }
00739                 $configFile = $this->getModuleDir('etc', $modName).DS.$fileName;
00740                 if ($mergeModel->loadFile($configFile)) {
00741                     $mergeToObject->extend($mergeModel, true);
00742                 }
00743             }
00744         }
00745         return $mergeToObject;
00746     }

reinit ( options = array()  ) 

Reinitialize configuration

Parameters:
array $options
Returns:
Mage_Core_Model_Config

Definition at line 285 of file Config.php.

00286     {
00287         $this->_allowCacheForInit = false;
00288         $this->_useCache = false;
00289         return $this->init($options);
00290     }

removeCache (  ) 

Remove configuration cache

Returns:
Mage_Core_Model_Config

Reimplemented from Varien_Simplexml_Config.

Definition at line 478 of file Config.php.

00479     {
00480         Mage::app()->cleanCache(array(self::CACHE_TAG));
00481         return parent::removeCache();
00482     }

saveCache ( tags = array()  ) 

Save configuration cache

Parameters:
array $tags cache tags
Returns:
Mage_Core_Model_Config

Reimplemented from Varien_Simplexml_Config.

Definition at line 362 of file Config.php.

00363     {
00364         $cacheLockId = $this->_getCacheLockId();
00365         if ($this->_loadCache($cacheLockId)) {
00366             return $this;
00367         }
00368 
00369         if (!empty($this->_cacheSections)) {
00370             $xml = clone $this->_xml;
00371             foreach ($this->_cacheSections as $sectionName => $level) {
00372                 $this->_saveSectionCache($this->getCacheId(), $sectionName, $xml, $level, $tags);
00373                 unset($xml->$sectionName);
00374             }
00375             $this->_cachePartsForSave[$this->getCacheId()] = $xml->asNiceXml('', false);
00376         } else {
00377             return parent::saveCache($tags);
00378         }
00379 
00380         $this->_saveCache(time(), $cacheLockId, array(), 60);
00381         $this->removeCache();
00382         foreach ($this->_cachePartsForSave as $cacheId => $cacheData) {
00383             $this->_saveCache($cacheData, $cacheId, $tags, $this->getCacheLifetime());
00384         }
00385         unset($this->_cachePartsForSave);
00386         $this->_removeCache($cacheLockId);
00387         return $this;
00388     }

saveConfig ( path,
value,
scope = 'default',
scopeId = 0 
)

Save config value to DB

Parameters:
string $path
string $value
string $scope
int $scopeId
Returns:
Mage_Core_Store_Config

Definition at line 1265 of file Config.php.

01266     {
01267         $resource = $this->getResourceModel();
01268         $resource->saveConfig(rtrim($path, '/'), $value, $scope, $scopeId);
01269 
01270         return $this;
01271     }

shouldUrlBeSecure ( url  ) 

Check security requirements for url

Parameters:
string $url
Returns:
bool

Definition at line 1214 of file Config.php.

01215     {
01216         if (!isset($this->_secureUrlCache[$url])) {
01217             $this->_secureUrlCache[$url] = false;
01218             $secureUrls = $this->getNode('frontend/secure_url');
01219             foreach ($secureUrls->children() as $match) {
01220                 if (strpos($url, (string)$match)===0) {
01221                     $this->_secureUrlCache[$url] = true;
01222                     break;
01223                 }
01224             }
01225         }
01226 
01227         return $this->_secureUrlCache[$url];
01228     }

substDistroServerVars ( data  ) 

Definition at line 796 of file Config.php.

00797     {
00798         $this->getDistroServerVars();
00799         return str_replace(
00800             array_keys($this->_substServerVars),
00801             array_values($this->_substServerVars),
00802             $data
00803         );
00804     }


Member Data Documentation

$_allowCacheForInit = true [protected]

Definition at line 140 of file Config.php.

$_baseDirCache = array() [protected]

Depricated properties

Deprecated:

Definition at line 154 of file Config.php.

$_blockClassNameCache = array() [protected]

Definition at line 90 of file Config.php.

$_cacheLoadedSections = array() [protected]

Definition at line 69 of file Config.php.

$_cachePartsForSave = array() [protected]

Definition at line 147 of file Config.php.

$_cacheSections [protected]

Initial value:

 array(
        'admin'     => 0,
        'adminhtml' => 0,
        'crontab'   => 0,
        'install'   => 0,
        'stores'    => 1,
        'websites'  => 0
    )

Definition at line 55 of file Config.php.

$_canUseLocalModules = null [protected]

Definition at line 162 of file Config.php.

$_classNameCache = array() [protected]

Definition at line 83 of file Config.php.

$_customEtcDir = null [protected]

Definition at line 155 of file Config.php.

$_dirExists = array() [protected]

Definition at line 133 of file Config.php.

$_distroServerVars [protected]

Definition at line 104 of file Config.php.

$_eventAreas [protected]

Definition at line 126 of file Config.php.

$_options [protected]

Definition at line 76 of file Config.php.

$_resourceModel [protected]

Definition at line 119 of file Config.php.

$_secureUrlCache = array() [protected]

Definition at line 97 of file Config.php.

$_substServerVars [protected]

Definition at line 111 of file Config.php.

$_useCache = false [protected]

Definition at line 44 of file Config.php.

const CACHE_TAG = 'CONFIG'

Definition at line 37 of file Config.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:56 2009 for Magento by  doxygen 1.5.8