Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage
  • Mage_Adminhtml_Block_Html_Date
  • Mage_Adminhtml_Block_Html_Select
  • Mage_Api_Model_Wsdl_Config_Element
  • Mage_Captcha_Adminhtml_RefreshController
  • Mage_Captcha_RefreshController
  • Mage_Core_AjaxController
  • Mage_Core_Block_Abstract
  • Mage_Core_Block_Flush
  • Mage_Core_Block_Html_Calendar
  • Mage_Core_Block_Html_Date
  • Mage_Core_Block_Html_Link
  • Mage_Core_Block_Html_Select
  • Mage_Core_Block_Messages
  • Mage_Core_Block_Profiler
  • Mage_Core_Block_Store_Switcher
  • Mage_Core_Block_Template
  • Mage_Core_Block_Template_Facade
  • Mage_Core_Block_Template_Smarty
  • Mage_Core_Block_Template_Zend
  • Mage_Core_Block_Text
  • Mage_Core_Block_Text_List
  • Mage_Core_Block_Text_List_Item
  • Mage_Core_Block_Text_List_Link
  • Mage_Core_Block_Text_Tag
  • Mage_Core_Block_Text_Tag_Css
  • Mage_Core_Block_Text_Tag_Css_Admin
  • Mage_Core_Block_Text_Tag_Debug
  • Mage_Core_Block_Text_Tag_Js
  • Mage_Core_Block_Text_Tag_Meta
  • Mage_Core_Controller_Front_Action
  • Mage_Core_Controller_Front_Router
  • Mage_Core_Controller_Request_Http
  • Mage_Core_Controller_Response_Http
  • Mage_Core_Controller_Varien_Action
  • Mage_Core_Controller_Varien_Front
  • Mage_Core_Controller_Varien_Router_Abstract
  • Mage_Core_Controller_Varien_Router_Admin
  • Mage_Core_Controller_Varien_Router_Default
  • Mage_Core_Controller_Varien_Router_Standard
  • Mage_Core_Helper_Abstract
  • Mage_Core_Helper_Cookie
  • Mage_Core_Helper_Data
  • Mage_Core_Helper_File_Storage
  • Mage_Core_Helper_File_Storage_Database
  • Mage_Core_Helper_Hint
  • Mage_Core_Helper_Http
  • Mage_Core_Helper_Js
  • Mage_Core_Helper_String
  • Mage_Core_Helper_Translate
  • Mage_Core_Helper_Url
  • Mage_Core_Helper_Url_Rewrite
  • Mage_Core_IndexController
  • Mage_Core_Model_Abstract
  • Mage_Core_Model_App
  • Mage_Core_Model_App_Area
  • Mage_Core_Model_App_Emulation
  • Mage_Core_Model_Cache
  • Mage_Core_Model_Calculator
  • Mage_Core_Model_Config
  • Mage_Core_Model_Config_Base
  • Mage_Core_Model_Config_Data
  • Mage_Core_Model_Config_Element
  • Mage_Core_Model_Config_Options
  • Mage_Core_Model_Config_System
  • Mage_Core_Model_Cookie
  • Mage_Core_Model_Date
  • Mage_Core_Model_Design
  • Mage_Core_Model_Design_Package
  • Mage_Core_Model_Design_Source_Design
  • Mage_Core_Model_Email
  • Mage_Core_Model_Email_Info
  • Mage_Core_Model_Email_Template
  • Mage_Core_Model_Email_Template_Filter
  • Mage_Core_Model_Email_Template_Mailer
  • Mage_Core_Model_Email_Transport
  • Mage_Core_Model_Encryption
  • Mage_Core_Model_File_Storage
  • Mage_Core_Model_File_Storage_Abstract
  • Mage_Core_Model_File_Storage_Database
  • Mage_Core_Model_File_Storage_Database_Abstract
  • Mage_Core_Model_File_Storage_Directory_Database
  • Mage_Core_Model_File_Storage_File
  • Mage_Core_Model_File_Storage_Flag
  • Mage_Core_Model_File_Uploader
  • Mage_Core_Model_File_Validator_AvailablePath
  • Mage_Core_Model_File_Validator_NotProtectedExtension
  • Mage_Core_Model_Flag
  • Mage_Core_Model_Input_Filter
  • Mage_Core_Model_Input_Filter_MaliciousCode
  • Mage_Core_Model_Language
  • Mage_Core_Model_Layout
  • Mage_Core_Model_Layout_Data
  • Mage_Core_Model_Layout_Element
  • Mage_Core_Model_Layout_Update
  • Mage_Core_Model_Locale
  • Mage_Core_Model_Locale_Config
  • Mage_Core_Model_Log_Adapter
  • Mage_Core_Model_Magento_Api
  • Mage_Core_Model_Magento_Api_V2
  • Mage_Core_Model_Message
  • Mage_Core_Model_Message_Abstract
  • Mage_Core_Model_Message_Collection
  • Mage_Core_Model_Message_Error
  • Mage_Core_Model_Message_Notice
  • Mage_Core_Model_Message_Success
  • Mage_Core_Model_Message_Warning
  • Mage_Core_Model_Mysql4_Abstract
  • Mage_Core_Model_Mysql4_Cache
  • Mage_Core_Model_Mysql4_Collection_Abstract
  • Mage_Core_Model_Mysql4_Config
  • Mage_Core_Model_Mysql4_Config_Data
  • Mage_Core_Model_Mysql4_Config_Data_Collection
  • Mage_Core_Model_Mysql4_Design
  • Mage_Core_Model_Mysql4_Design_Collection
  • Mage_Core_Model_Mysql4_Design_Package_Collection
  • Mage_Core_Model_Mysql4_Design_Theme
  • Mage_Core_Model_Mysql4_Email_Template
  • Mage_Core_Model_Mysql4_Email_Template_Collection
  • Mage_Core_Model_Mysql4_File_Storage_Abstract
  • Mage_Core_Model_Mysql4_File_Storage_Database
  • Mage_Core_Model_Mysql4_File_Storage_Directory_Database
  • Mage_Core_Model_Mysql4_File_Storage_File
  • Mage_Core_Model_Mysql4_Flag
  • Mage_Core_Model_Mysql4_Language
  • Mage_Core_Model_Mysql4_Language_Collection
  • Mage_Core_Model_Mysql4_Layout
  • Mage_Core_Model_Mysql4_Resource
  • Mage_Core_Model_Mysql4_Session
  • Mage_Core_Model_Mysql4_Store
  • Mage_Core_Model_Mysql4_Store_Collection
  • Mage_Core_Model_Mysql4_Store_Group
  • Mage_Core_Model_Mysql4_Store_Group_Collection
  • Mage_Core_Model_Mysql4_Translate
  • Mage_Core_Model_Mysql4_Translate_String
  • Mage_Core_Model_Mysql4_Url_Rewrite
  • Mage_Core_Model_Mysql4_Url_Rewrite_Collection
  • Mage_Core_Model_Mysql4_Variable
  • Mage_Core_Model_Mysql4_Variable_Collection
  • Mage_Core_Model_Mysql4_Website
  • Mage_Core_Model_Mysql4_Website_Collection
  • Mage_Core_Model_Observer
  • Mage_Core_Model_Resource
  • Mage_Core_Model_Resource_Abstract
  • Mage_Core_Model_Resource_Cache
  • Mage_Core_Model_Resource_Config
  • Mage_Core_Model_Resource_Config_Data
  • Mage_Core_Model_Resource_Config_Data_Collection
  • Mage_Core_Model_Resource_Db_Abstract
  • Mage_Core_Model_Resource_Db_Collection_Abstract
  • Mage_Core_Model_Resource_Design
  • Mage_Core_Model_Resource_Design_Collection
  • Mage_Core_Model_Resource_Design_Package_Collection
  • Mage_Core_Model_Resource_Email_Template
  • Mage_Core_Model_Resource_Email_Template_Collection
  • Mage_Core_Model_Resource_Entity_Abstract
  • Mage_Core_Model_Resource_Entity_Table
  • Mage_Core_Model_Resource_File_Storage_Abstract
  • Mage_Core_Model_Resource_File_Storage_Database
  • Mage_Core_Model_Resource_File_Storage_Directory_Database
  • Mage_Core_Model_Resource_File_Storage_File
  • Mage_Core_Model_Resource_Flag
  • Mage_Core_Model_Resource_Helper_Abstract
  • Mage_Core_Model_Resource_Helper_Mysql4
  • Mage_Core_Model_Resource_Iterator
  • Mage_Core_Model_Resource_Language
  • Mage_Core_Model_Resource_Language_Collection
  • Mage_Core_Model_Resource_Layout
  • Mage_Core_Model_Resource_Resource
  • Mage_Core_Model_Resource_Session
  • Mage_Core_Model_Resource_Setup
  • Mage_Core_Model_Resource_Setup_Query_Modifier
  • Mage_Core_Model_Resource_Store
  • Mage_Core_Model_Resource_Store_Collection
  • Mage_Core_Model_Resource_Store_Group
  • Mage_Core_Model_Resource_Store_Group_Collection
  • Mage_Core_Model_Resource_Transaction
  • Mage_Core_Model_Resource_Translate
  • Mage_Core_Model_Resource_Translate_String
  • Mage_Core_Model_Resource_Type_Abstract
  • Mage_Core_Model_Resource_Type_Db
  • Mage_Core_Model_Resource_Type_Db_Mysqli
  • Mage_Core_Model_Resource_Type_Db_Mysqli_Setup
  • Mage_Core_Model_Resource_Type_Db_Pdo_Mysql
  • Mage_Core_Model_Resource_Url_Rewrite
  • Mage_Core_Model_Resource_Url_Rewrite_Collection
  • Mage_Core_Model_Resource_Variable
  • Mage_Core_Model_Resource_Variable_Collection
  • Mage_Core_Model_Resource_Website
  • Mage_Core_Model_Resource_Website_Collection
  • Mage_Core_Model_Session
  • Mage_Core_Model_Session_Abstract
  • Mage_Core_Model_Session_Abstract_Varien
  • Mage_Core_Model_Session_Abstract_Zend
  • Mage_Core_Model_Source_Email_Variables
  • Mage_Core_Model_Store
  • Mage_Core_Model_Store_Api
  • Mage_Core_Model_Store_Api_V2
  • Mage_Core_Model_Store_Group
  • Mage_Core_Model_Template
  • Mage_Core_Model_Translate
  • Mage_Core_Model_Translate_Expr
  • Mage_Core_Model_Translate_Inline
  • Mage_Core_Model_Translate_String
  • Mage_Core_Model_Url
  • Mage_Core_Model_Url_Rewrite
  • Mage_Core_Model_Url_Validator
  • Mage_Core_Model_Variable
  • Mage_Core_Model_Variable_Config
  • Mage_Core_Model_Variable_Observer
  • Mage_Core_Model_Website
  • Mage_Page_Block_Switch
  • Mage_Page_Block_Template_Container
  • Mage_Page_Block_Template_Links
  • Mage_Page_Block_Template_Links_Block
  • Mage_Sales_Model_Quote_Address_Total_Collector

Exceptions

  • Mage_Core_Controller_Varien_Exception
  • Mage_Core_Exception
  • Mage_Core_Model_Session_Exception
  • Mage_Core_Model_Store_Exception

Functions

  • destruct
  • is_dir_writeable
  • is_empty_date
  • mageCoreErrorHandler
  • mageDebugBacktrace
  • mageDelTree
  • mageFindClassFile
  • mageParseCsv
  • mageSendErrorFooter
  • mageSendErrorHeader
  • mageUndoMagicQuotes
  • now
  • sys_get_temp_dir
  • uc_words
  • Overview
  • Package
  • Class
  • Tree
   1: <?php
   2: /**
   3:  * Magento
   4:  *
   5:  * NOTICE OF LICENSE
   6:  *
   7:  * This source file is subject to the Open Software License (OSL 3.0)
   8:  * that is bundled with this package in the file LICENSE.txt.
   9:  * It is also available through the world-wide-web at this URL:
  10:  * http://opensource.org/licenses/osl-3.0.php
  11:  * If you did not receive a copy of the license and are unable to
  12:  * obtain it through the world-wide-web, please send an email
  13:  * to license@magentocommerce.com so we can send you a copy immediately.
  14:  *
  15:  * DISCLAIMER
  16:  *
  17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
  18:  * versions in the future. If you wish to customize Magento for your
  19:  * needs please refer to http://www.magentocommerce.com for more information.
  20:  *
  21:  * @category    Mage
  22:  * @package     Mage_Core
  23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
  24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
  25:  */
  26: 
  27: 
  28: /**
  29:  * Core configuration class
  30:  *
  31:  * @category    Mage
  32:  * @package     Mage_Core
  33:  * @author      Magento Core Team <core@magentocommerce.com>
  34:  */
  35: class Mage_Core_Model_Config extends Mage_Core_Model_Config_Base
  36: {
  37:     const CACHE_TAG         = 'CONFIG';
  38: 
  39:     /**
  40:      * Flag which allow use cache logic
  41:      *
  42:      * @var bool
  43:      */
  44:     protected $_useCache = false;
  45: 
  46:     /**
  47:      * Instructions for spitting config cache
  48:      * array(
  49:      *      $sectionName => $recursionLevel
  50:      * )
  51:      * Recursion level provide availability cache subnodes separatly
  52:      *
  53:      * @var array
  54:      */
  55:     protected $_cacheSections = array(
  56:         'admin'     => 0,
  57:         'adminhtml' => 0,
  58:         'crontab'   => 0,
  59:         'install'   => 0,
  60:         'stores'    => 1,
  61:         'websites'  => 0
  62:     );
  63: 
  64:     /**
  65:      * Loaded Configuration by cached sections
  66:      *
  67:      * @var array
  68:      */
  69:     protected $_cacheLoadedSections = array();
  70: 
  71:     /**
  72:      * Configuration options
  73:      *
  74:      * @var Mage_Core_Model_Config_Options
  75:      */
  76:     protected $_options;
  77: 
  78:     /**
  79:      * Storage for generated class names
  80:      *
  81:      * @var array
  82:      */
  83:     protected $_classNameCache = array();
  84: 
  85:     /**
  86:      * Storage for generated block class names
  87:      *
  88:      * @var unknown_type
  89:      */
  90:     protected $_blockClassNameCache = array();
  91: 
  92:     /**
  93:      * Storage of validated secure urls
  94:      *
  95:      * @var array
  96:      */
  97:     protected $_secureUrlCache = array();
  98: 
  99:     /**
 100:      * System environment server variables
 101:      *
 102:      * @var array
 103:      */
 104:     protected $_distroServerVars;
 105: 
 106:     /**
 107:      * Array which is using for replace placeholders of server variables
 108:      *
 109:      * @var array
 110:      */
 111:     protected $_substServerVars;
 112: 
 113:     /**
 114:      * Resource model
 115:      * Used for operations with DB
 116:      *
 117:      * @var Mage_Core_Model_Mysql4_Config
 118:      */
 119:     protected $_resourceModel;
 120: 
 121:     /**
 122:      * Configuration for events by area
 123:      *
 124:      * @var array
 125:      */
 126:     protected $_eventAreas;
 127: 
 128:     /**
 129:      * Flag cache for existing or already created directories
 130:      *
 131:      * @var array
 132:      */
 133:     protected $_dirExists = array();
 134: 
 135:     /**
 136:      * Flach which allow using cache for config initialization
 137:      *
 138:      * @var bool
 139:      */
 140:     protected $_allowCacheForInit = true;
 141: 
 142:     /**
 143:      * Property used during cache save process
 144:      *
 145:      * @var array
 146:      */
 147:     protected $_cachePartsForSave = array();
 148: 
 149:     /**
 150:      * Empty configuration object for loading and megring configuration parts
 151:      *
 152:      * @var Mage_Core_Model_Config_Base
 153:      */
 154:     protected $_prototype;
 155: 
 156:     /**
 157:      * Flag which identify what local configuration is loaded
 158:      *
 159:      * @var bool
 160:      */
 161:     protected $_isLocalConfigLoaded = false;
 162: 
 163:     /**
 164:      * Depricated properties
 165:      *
 166:      * @deprecated
 167:      */
 168:     protected $_baseDirCache = array();
 169:     protected $_customEtcDir = null;
 170: 
 171:     /**
 172:      * Flag which allow to use modules from local code pool
 173:      *
 174:      * @var bool
 175:      */
 176:     protected $_canUseLocalModules = null;
 177: 
 178:     /**
 179:      * Active modules array per namespace
 180:      * @var array
 181:      */
 182:     private $_moduleNamespaces = null;
 183: 
 184:     /**
 185:      * Modules allowed to load
 186:      * If empty - all modules are allowed
 187:      *
 188:      * @var array
 189:      */
 190:     protected $_allowedModules = array();
 191: 
 192:     /**
 193:      * Class construct
 194:      *
 195:      * @param mixed $sourceData
 196:      */
 197:     public function __construct($sourceData=null)
 198:     {
 199:         $this->setCacheId('config_global');
 200:         $this->_options         = new Mage_Core_Model_Config_Options($sourceData);
 201:         $this->_prototype       = new Mage_Core_Model_Config_Base();
 202:         $this->_cacheChecksum   = null;
 203:         parent::__construct($sourceData);
 204:     }
 205: 
 206:     /**
 207:      * Get config resource model
 208:      *
 209:      * @return Mage_Core_Store_Mysql4_Config
 210:      */
 211:     public function getResourceModel()
 212:     {
 213:         if (is_null($this->_resourceModel)) {
 214:             $this->_resourceModel = Mage::getResourceModel('core/config');
 215:         }
 216:         return $this->_resourceModel;
 217:     }
 218: 
 219:     /**
 220:      * Get configuration options object
 221:      *
 222:      * @return Mage_Core_Model_Config_Options
 223:      */
 224:     public function getOptions()
 225:     {
 226:         return $this->_options;
 227:     }
 228: 
 229:     /**
 230:      * Set configuration options
 231:      *
 232:      * @param array $options
 233:      * @return Mage_Core_Model_Config
 234:      */
 235:     public function setOptions($options)
 236:     {
 237:         if (is_array($options)) {
 238:             $this->getOptions()->addData($options);
 239:         }
 240:         return $this;
 241:     }
 242: 
 243:     /**
 244:      * Initialization of core configuration
 245:      *
 246:      * @return Mage_Core_Model_Config
 247:      */
 248:     public function init($options=array())
 249:     {
 250:         $this->setCacheChecksum(null);
 251:         $this->_cacheLoadedSections = array();
 252:         $this->setOptions($options);
 253:         $this->loadBase();
 254: 
 255:         $cacheLoad = $this->loadModulesCache();
 256:         if ($cacheLoad) {
 257:             return $this;
 258:         }
 259:         $this->loadModules();
 260:         $this->loadDb();
 261:         $this->saveCache();
 262:         return $this;
 263:     }
 264: 
 265:     /**
 266:      * Load base system configuration (config.xml and local.xml files)
 267:      *
 268:      * @return Mage_Core_Model_Config
 269:      */
 270:     public function loadBase()
 271:     {
 272:         $etcDir = $this->getOptions()->getEtcDir();
 273:         $files = glob($etcDir.DS.'*.xml');
 274:         $this->loadFile(current($files));
 275:         while ($file = next($files)) {
 276:             $merge = clone $this->_prototype;
 277:             $merge->loadFile($file);
 278:             $this->extend($merge);
 279:         }
 280:         if (in_array($etcDir.DS.'local.xml', $files)) {
 281:             $this->_isLocalConfigLoaded = true;
 282:         }
 283:         return $this;
 284:     }
 285: 
 286:     /**
 287:      * Load cached modules configuration
 288:      *
 289:      * @return bool
 290:      */
 291:     public function loadModulesCache()
 292:     {
 293:         if (Mage::isInstalled(array('etc_dir' => $this->getOptions()->getEtcDir()))) {
 294:             if ($this->_canUseCacheForInit()) {
 295:                 Varien_Profiler::start('mage::app::init::config::load_cache');
 296:                 $loaded = $this->loadCache();
 297:                 Varien_Profiler::stop('mage::app::init::config::load_cache');
 298:                 if ($loaded) {
 299:                     $this->_useCache = true;
 300:                     return true;
 301:                 }
 302:             }
 303:         }
 304:         return false;
 305:     }
 306: 
 307:     /**
 308:      * Load modules configuration
 309:      *
 310:      * @return Mage_Core_Model_Config
 311:      */
 312:     public function loadModules()
 313:     {
 314:         Varien_Profiler::start('config/load-modules');
 315:         $this->_loadDeclaredModules();
 316: 
 317:         $resourceConfig = sprintf('config.%s.xml', $this->_getResourceConnectionModel('core'));
 318:         $this->loadModulesConfiguration(array('config.xml',$resourceConfig), $this);
 319: 
 320:         /**
 321:          * Prevent local.xml directives overwriting
 322:          */
 323:         $mergeConfig = clone $this->_prototype;
 324:         $this->_isLocalConfigLoaded = $mergeConfig->loadFile($this->getOptions()->getEtcDir().DS.'local.xml');
 325:         if ($this->_isLocalConfigLoaded) {
 326:             $this->extend($mergeConfig);
 327:         }
 328: 
 329:         $this->applyExtends();
 330:         Varien_Profiler::stop('config/load-modules');
 331:         return $this;
 332:     }
 333: 
 334:     /**
 335:      * Check if local configuration (DB connection, etc) is loaded
 336:      *
 337:      * @return bool
 338:      */
 339:     public function isLocalConfigLoaded()
 340:     {
 341:         return $this->_isLocalConfigLoaded;
 342:     }
 343: 
 344:     /**
 345:      * Load config data from DB
 346:      *
 347:      * @return Mage_Core_Model_Config
 348:      */
 349:     public function loadDb()
 350:     {
 351:         if ($this->_isLocalConfigLoaded && Mage::isInstalled()) {
 352:             Varien_Profiler::start('config/load-db');
 353:             $dbConf = $this->getResourceModel();
 354:             $dbConf->loadToXml($this);
 355:             Varien_Profiler::stop('config/load-db');
 356:         }
 357:         return $this;
 358:     }
 359: 
 360:     /**
 361:      * Reinitialize configuration
 362:      *
 363:      * @param   array $options
 364:      * @return  Mage_Core_Model_Config
 365:      */
 366:     public function reinit($options = array())
 367:     {
 368:         $this->_allowCacheForInit = false;
 369:         $this->_useCache = false;
 370:         return $this->init($options);
 371:     }
 372: 
 373:     /**
 374:      * Check local modules enable/disable flag
 375:      * If local modules are disbled remove local modules path from include dirs
 376:      *
 377:      * return true if local modules enabled and false if disabled
 378:      *
 379:      * @return bool
 380:      */
 381:     protected function _canUseLocalModules()
 382:     {
 383:         if ($this->_canUseLocalModules !== null) {
 384:             return $this->_canUseLocalModules;
 385:         }
 386: 
 387:         $disableLocalModules = (string)$this->getNode('global/disable_local_modules');
 388:         if (!empty($disableLocalModules)) {
 389:             $disableLocalModules = (('true' === $disableLocalModules) || ('1' === $disableLocalModules));
 390:         } else {
 391:             $disableLocalModules = false;
 392:         }
 393: 
 394:         if ($disableLocalModules && !defined('COMPILER_INCLUDE_PATH')) {
 395:             set_include_path(
 396:                 // excluded '/app/code/local'
 397:                 BP . DS . 'app' . DS . 'code' . DS . 'community' . PS .
 398:                 BP . DS . 'app' . DS . 'code' . DS . 'core' . PS .
 399:                 BP . DS . 'lib' . PS .
 400:                 Mage::registry('original_include_path')
 401:             );
 402:         }
 403:         $this->_canUseLocalModules = !$disableLocalModules;
 404:         return $this->_canUseLocalModules;
 405:     }
 406: 
 407:     /**
 408:      * Check if cache can be used for config initialization
 409:      *
 410:      * @return bool
 411:      */
 412:     protected function _canUseCacheForInit()
 413:     {
 414:         return Mage::app()->useCache('config') && $this->_allowCacheForInit
 415:             && !$this->_loadCache($this->_getCacheLockId());
 416:     }
 417: 
 418:     /**
 419:      * Retrieve cache object
 420:      *
 421:      * @return Zend_Cache_Frontend_File
 422:      */
 423:     public function getCache()
 424:     {
 425:         return Mage::app()->getCache();
 426:     }
 427: 
 428:     /**
 429:      * Get lock flag cache identifier
 430:      *
 431:      * @return string
 432:      */
 433:     protected function _getCacheLockId()
 434:     {
 435:         return $this->getCacheId().'.lock';
 436:     }
 437: 
 438:     /**
 439:      * Save configuration cache
 440:      *
 441:      * @param   array $tags cache tags
 442:      * @return  Mage_Core_Model_Config
 443:      */
 444:     public function saveCache($tags=array())
 445:     {
 446:         if (!Mage::app()->useCache('config')) {
 447:             return $this;
 448:         }
 449:         if (!in_array(self::CACHE_TAG, $tags)) {
 450:             $tags[] = self::CACHE_TAG;
 451:         }
 452:         $cacheLockId = $this->_getCacheLockId();
 453:         if ($this->_loadCache($cacheLockId)) {
 454:             return $this;
 455:         }
 456: 
 457:         if (!empty($this->_cacheSections)) {
 458:             $xml = clone $this->_xml;
 459:             foreach ($this->_cacheSections as $sectionName => $level) {
 460:                 $this->_saveSectionCache($this->getCacheId(), $sectionName, $xml, $level, $tags);
 461:                 unset($xml->$sectionName);
 462:             }
 463:             $this->_cachePartsForSave[$this->getCacheId()] = $xml->asNiceXml('', false);
 464:         } else {
 465:             return parent::saveCache($tags);
 466:         }
 467: 
 468:         $this->_saveCache(time(), $cacheLockId, array(), 60);
 469:         $this->removeCache();
 470:         foreach ($this->_cachePartsForSave as $cacheId => $cacheData) {
 471:             $this->_saveCache($cacheData, $cacheId, $tags, $this->getCacheLifetime());
 472:         }
 473:         unset($this->_cachePartsForSave);
 474:         $this->_removeCache($cacheLockId);
 475:         return $this;
 476:     }
 477: 
 478:     /**
 479:      * Save cache of specified
 480:      *
 481:      * @param   string $idPrefix cache id prefix
 482:      * @param   string $sectionName
 483:      * @param   Varien_Simplexml_Element $source
 484:      * @param   int $recursionLevel
 485:      * @return  Mage_Core_Model_Config
 486:      */
 487:     protected function _saveSectionCache($idPrefix, $sectionName, $source, $recursionLevel=0, $tags=array())
 488:     {
 489:         if ($source && $source->$sectionName) {
 490:             $cacheId = $idPrefix . '_' . $sectionName;
 491:             if ($recursionLevel > 0) {
 492:                 foreach ($source->$sectionName->children() as $subSectionName => $node) {
 493:                     $this->_saveSectionCache(
 494:                         $cacheId, $subSectionName, $source->$sectionName, $recursionLevel-1, $tags
 495:                     );
 496:                 }
 497:             }
 498:             $this->_cachePartsForSave[$cacheId] = $source->$sectionName->asNiceXml('', false);
 499:         }
 500:         return $this;
 501:     }
 502: 
 503:     /**
 504:      * Load config section cached data
 505:      *
 506:      * @param   string $sectionName
 507:      * @return  Varien_Simplexml_Element
 508:      */
 509:     protected function _loadSectionCache($sectionName)
 510:     {
 511:         $cacheId = $this->getCacheId() . '_' . $sectionName;
 512:         $xmlString = $this->_loadCache($cacheId);
 513: 
 514:         /**
 515:          * If we can't load section cache (problems with cache storage)
 516:          */
 517:         if (!$xmlString) {
 518:             $this->_useCache = false;
 519:             $this->reinit($this->_options);
 520:             return false;
 521:         } else {
 522:             $xml = simplexml_load_string($xmlString, $this->_elementClass);
 523:             return $xml;
 524:         }
 525:     }
 526: 
 527:     /**
 528:      * Load cached data by identifier
 529:      *
 530:      * @param   string $id
 531:      * @return  string
 532:      */
 533:     protected function _loadCache($id)
 534:     {
 535:         return Mage::app()->loadCache($id);
 536:     }
 537: 
 538:     /**
 539:      * Save cache data
 540:      *
 541:      * @param   string $data
 542:      * @param   string $id
 543:      * @param   array $tags
 544:      * @param   false|int $lifetime
 545:      * @return  Mage_Core_Model_Config
 546:      */
 547:     protected function _saveCache($data, $id, $tags=array(), $lifetime=false)
 548:     {
 549:         return Mage::app()->saveCache($data, $id, $tags, $lifetime);
 550:     }
 551: 
 552:     /**
 553:      * Clear cache data by id
 554:      *
 555:      * @param   string $id
 556:      * @return  Mage_Core_Model_Config
 557:      */
 558:     protected function _removeCache($id)
 559:     {
 560:         return Mage::app()->removeCache($id);
 561:     }
 562: 
 563:     /**
 564:      * Remove configuration cache
 565:      *
 566:      * @return Mage_Core_Model_Config
 567:      */
 568:     public function removeCache()
 569:     {
 570:         Mage::app()->cleanCache(array(self::CACHE_TAG));
 571:         return parent::removeCache();
 572:     }
 573: 
 574:     /**
 575:      * Configuration cache clean process
 576:      *
 577:      * @return Mage_Core_Model_Config
 578:      */
 579:     public function cleanCache()
 580:     {
 581:         return $this->reinit();
 582:     }
 583: 
 584:     /**
 585:      * Getter for section configuration object
 586:      *
 587:      * @param array $path
 588:      * @return Mage_Core_Model_Config_Element
 589:      */
 590:     protected function _getSectionConfig($path)
 591:     {
 592:         $section = $path[0];
 593:         if (!isset($this->_cacheSections[$section])) {
 594:             return false;
 595:         }
 596:         $sectionPath = array_slice($path, 0, $this->_cacheSections[$section]+1);
 597:         $sectionKey = implode('_', $sectionPath);
 598: 
 599:         if (!isset($this->_cacheLoadedSections[$sectionKey])) {
 600:             Varien_Profiler::start('init_config_section:' . $sectionKey);
 601:             $this->_cacheLoadedSections[$sectionKey] = $this->_loadSectionCache($sectionKey);
 602:             Varien_Profiler::stop('init_config_section:' . $sectionKey);
 603:         }
 604: 
 605:         if ($this->_cacheLoadedSections[$sectionKey] === false) {
 606:             return false;
 607:         }
 608:         return $this->_cacheLoadedSections[$sectionKey];
 609:     }
 610: 
 611:     /**
 612:      * Get node value from cached section data
 613:      *
 614:      * @param   array $path
 615:      * @return  Mage_Core_Model_Config
 616:      */
 617:     public function getSectionNode($path)
 618:     {
 619:         $section    = $path[0];
 620:         $config     = $this->_getSectionConfig($path);
 621:         $path       = array_slice($path, $this->_cacheSections[$section] + 1);
 622:         if ($config) {
 623:             return $config->descend($path);
 624:         }
 625:         return false;
 626:     }
 627: 
 628:     /**
 629:      * Returns node found by the $path and scope info
 630:      *
 631:      * @param   string $path
 632:      * @param   string $scope
 633:      * @param   string|int $scopeCode
 634:      * @return Mage_Core_Model_Config_Element
 635:      */
 636:     public function getNode($path=null, $scope='', $scopeCode=null)
 637:     {
 638:         if ($scope !== '') {
 639:             if (('store' === $scope) || ('website' === $scope)) {
 640:                 $scope .= 's';
 641:             }
 642:             if (('default' !== $scope) && is_int($scopeCode)) {
 643:                 if ('stores' == $scope) {
 644:                     $scopeCode = Mage::app()->getStore($scopeCode)->getCode();
 645:                 } elseif ('websites' == $scope) {
 646:                     $scopeCode = Mage::app()->getWebsite($scopeCode)->getCode();
 647:                 } else {
 648:                     Mage::throwException(Mage::helper('core')->__('Unknown scope "%s".', $scope));
 649:                 }
 650:             }
 651:             $path = $scope . ($scopeCode ? '/' . $scopeCode : '' ) . (empty($path) ? '' : '/' . $path);
 652:         }
 653: 
 654:         /**
 655:          * Check path cache loading
 656:          */
 657:         if ($this->_useCache && ($path !== null)) {
 658:             $path   = explode('/', $path);
 659:             $section= $path[0];
 660:             if (isset($this->_cacheSections[$section])) {
 661:                 $res = $this->getSectionNode($path);
 662:                 if ($res !== false) {
 663:                     return $res;
 664:                 }
 665:             }
 666:         }
 667:         return  parent::getNode($path);
 668:     }
 669: 
 670:     /**
 671:      * Create node by $path and set its value.
 672:      *
 673:      * @param string $path separated by slashes
 674:      * @param string $value
 675:      * @param bool $overwrite
 676:      * @return Varien_Simplexml_Config
 677:      */
 678:     public function setNode($path, $value, $overwrite = true)
 679:     {
 680:         if ($this->_useCache && ($path !== null)) {
 681:             $sectionPath = explode('/', $path);
 682:             $config = $this->_getSectionConfig($sectionPath);
 683:             if ($config) {
 684:                 $sectionPath = array_slice($sectionPath, $this->_cacheSections[$sectionPath[0]]+1);
 685:                 $sectionPath = implode('/', $sectionPath);
 686:                 $config->setNode($sectionPath, $value, $overwrite);
 687:             }
 688:         }
 689:         return parent::setNode($path, $value, $overwrite);
 690:     }
 691: 
 692: 
 693:     /**
 694:      * Retrive Declared Module file list
 695:      *
 696:      * @return array
 697:      */
 698:     protected function _getDeclaredModuleFiles()
 699:     {
 700:         $etcDir = $this->getOptions()->getEtcDir();
 701:         $moduleFiles = glob($etcDir . DS . 'modules' . DS . '*.xml');
 702: 
 703:         if (!$moduleFiles) {
 704:             return false;
 705:         }
 706: 
 707:         $collectModuleFiles = array(
 708:             'base'   => array(),
 709:             'mage'   => array(),
 710:             'custom' => array()
 711:         );
 712: 
 713:         foreach ($moduleFiles as $v) {
 714:             $name = explode(DIRECTORY_SEPARATOR, $v);
 715:             $name = substr($name[count($name) - 1], 0, -4);
 716: 
 717:             if ($name == 'Mage_All') {
 718:                 $collectModuleFiles['base'][] = $v;
 719:             } else if (substr($name, 0, 5) == 'Mage_') {
 720:                 $collectModuleFiles['mage'][] = $v;
 721:             } else {
 722:                 $collectModuleFiles['custom'][] = $v;
 723:             }
 724:         }
 725: 
 726:         return array_merge(
 727:             $collectModuleFiles['base'],
 728:             $collectModuleFiles['mage'],
 729:             $collectModuleFiles['custom']
 730:         );
 731:     }
 732: 
 733:     /**
 734:      * Add module(s) to allowed list
 735:      *
 736:      * @param  strung|array $module
 737:      * @return Mage_Core_Model_Config
 738:      */
 739:     public function addAllowedModules($module)
 740:     {
 741:         if (is_array($module)) {
 742:             foreach ($module as $moduleName) {
 743:                 $this->addAllowedModules($moduleName);
 744:             }
 745:         } elseif (!in_array($module, $this->_allowedModules)) {
 746:             $this->_allowedModules[] = $module;
 747:         }
 748: 
 749:         return $this;
 750:     }
 751: 
 752:     /**
 753:      * Define if module is allowed
 754:      *
 755:      * @param  string $moduleName
 756:      * @return bool
 757:      */
 758:     protected function _isAllowedModule($moduleName)
 759:     {
 760:         if (empty($this->_allowedModules)) {
 761:             return true;
 762:         } else {
 763:             return in_array($moduleName, $this->_allowedModules);
 764:         }
 765:     }
 766: 
 767:     /**
 768:      * Load declared modules configuration
 769:      *
 770:      * @param   null $mergeConfig depricated
 771:      * @return  Mage_Core_Model_Config
 772:      */
 773:     protected function _loadDeclaredModules($mergeConfig = null)
 774:     {
 775:         $moduleFiles = $this->_getDeclaredModuleFiles();
 776:         if (!$moduleFiles) {
 777:             return ;
 778:         }
 779: 
 780:         Varien_Profiler::start('config/load-modules-declaration');
 781: 
 782:         $unsortedConfig = new Mage_Core_Model_Config_Base();
 783:         $unsortedConfig->loadString('<config/>');
 784:         $fileConfig = new Mage_Core_Model_Config_Base();
 785: 
 786:         // load modules declarations
 787:         foreach ($moduleFiles as $file) {
 788:             $fileConfig->loadFile($file);
 789:             $unsortedConfig->extend($fileConfig);
 790:         }
 791: 
 792:         $moduleDepends = array();
 793:         foreach ($unsortedConfig->getNode('modules')->children() as $moduleName => $moduleNode) {
 794:             if (!$this->_isAllowedModule($moduleName)) {
 795:                 continue;
 796:             }
 797: 
 798:             $depends = array();
 799:             if ($moduleNode->depends) {
 800:                 foreach ($moduleNode->depends->children() as $depend) {
 801:                     $depends[$depend->getName()] = true;
 802:                 }
 803:             }
 804:             $moduleDepends[$moduleName] = array(
 805:                 'module'    => $moduleName,
 806:                 'depends'   => $depends,
 807:                 'active'    => ('true' === (string)$moduleNode->active ? true : false),
 808:             );
 809:         }
 810: 
 811:         // check and sort module dependence
 812:         $moduleDepends = $this->_sortModuleDepends($moduleDepends);
 813: 
 814:         // create sorted config
 815:         $sortedConfig = new Mage_Core_Model_Config_Base();
 816:         $sortedConfig->loadString('<config><modules/></config>');
 817: 
 818:         foreach ($unsortedConfig->getNode()->children() as $nodeName => $node) {
 819:             if ($nodeName != 'modules') {
 820:                 $sortedConfig->getNode()->appendChild($node);
 821:             }
 822:         }
 823: 
 824:         foreach ($moduleDepends as $moduleProp) {
 825:             $node = $unsortedConfig->getNode('modules/'.$moduleProp['module']);
 826:             $sortedConfig->getNode('modules')->appendChild($node);
 827:         }
 828: 
 829:         $this->extend($sortedConfig);
 830: 
 831:         Varien_Profiler::stop('config/load-modules-declaration');
 832:         return $this;
 833:     }
 834: 
 835:     /**
 836:      * Sort modules and check depends
 837:      *
 838:      * @param array $modules
 839:      * @return array
 840:      */
 841:     protected function _sortModuleDepends($modules)
 842:     {
 843:         foreach ($modules as $moduleName => $moduleProps) {
 844:             $depends = $moduleProps['depends'];
 845:             foreach ($moduleProps['depends'] as $depend => $true) {
 846:                 if ($moduleProps['active'] && ((!isset($modules[$depend])) || empty($modules[$depend]['active']))) {
 847:                     Mage::throwException(
 848:                         Mage::helper('core')->__('Module "%1$s" requires module "%2$s".', $moduleName, $depend)
 849:                     );
 850:                 }
 851:                 $depends = array_merge($depends, $modules[$depend]['depends']);
 852:             }
 853:             $modules[$moduleName]['depends'] = $depends;
 854:         }
 855:         $modules = array_values($modules);
 856: 
 857:         $size = count($modules) - 1;
 858:         for ($i = $size; $i >= 0; $i--) {
 859:             for ($j = $size; $i < $j; $j--) {
 860:                 if (isset($modules[$i]['depends'][$modules[$j]['module']])) {
 861:                     $value       = $modules[$i];
 862:                     $modules[$i] = $modules[$j];
 863:                     $modules[$j] = $value;
 864:                 }
 865:             }
 866:         }
 867: 
 868:         $definedModules = array();
 869:         foreach ($modules as $moduleProp) {
 870:             foreach ($moduleProp['depends'] as $dependModule => $true) {
 871:                 if (!isset($definedModules[$dependModule])) {
 872:                     Mage::throwException(
 873:                         Mage::helper('core')->__('Module "%1$s" cannot depend on "%2$s".', $moduleProp['module'], $dependModule)
 874:                     );
 875:                 }
 876:             }
 877:             $definedModules[$moduleProp['module']] = true;
 878:         }
 879: 
 880:         return $modules;
 881:     }
 882: 
 883:     /**
 884:      * Determine whether provided name begins from any available modules, according to namespaces priority
 885:      * If matched, returns as the matched module "factory" name or a fully qualified module name
 886:      *
 887:      * @param string $name
 888:      * @param bool $asFullModuleName
 889:      * @return string
 890:      */
 891:     public function determineOmittedNamespace($name, $asFullModuleName = false)
 892:     {
 893:         if (null === $this->_moduleNamespaces) {
 894:             $this->_moduleNamespaces = array();
 895:             foreach ($this->_xml->xpath('modules/*') as $m) {
 896:                 if ((string)$m->active == 'true') {
 897:                     $moduleName = $m->getName();
 898:                     $module = strtolower($moduleName);
 899:                     $this->_moduleNamespaces[substr($module, 0, strpos($module, '_'))][$module] = $moduleName;
 900:                 }
 901:             }
 902:         }
 903: 
 904:         $name = explode('_', strtolower($name));
 905:         $partsNum = count($name);
 906:         $defaultNamespaceFlag = false;
 907:         foreach ($this->_moduleNamespaces as $namespaceName => $namespace) {
 908:             // assume the namespace is omitted (default namespace only, which comes first)
 909:             if ($defaultNamespaceFlag === false) {
 910:                 $defaultNamespaceFlag = true;
 911:                 $defaultNS = $namespaceName . '_' . $name[0];
 912:                 if (isset($namespace[$defaultNS])) {
 913:                     return $asFullModuleName ? $namespace[$defaultNS] : $name[0]; // return omitted as well
 914:                 }
 915:             }
 916:             // assume namespace is qualified
 917:             if(isset($name[1])) {
 918:                 $fullNS = $name[0] . '_' . $name[1];
 919:                 if (2 <= $partsNum && isset($namespace[$fullNS])) {
 920:                     return $asFullModuleName ? $namespace[$fullNS] : $fullNS;
 921:                 }
 922:             }
 923:         }
 924:         return '';
 925:     }
 926: 
 927:     /**
 928:      * Iterate all active modules "etc" folders and combine data from
 929:      * specidied xml file name to one object
 930:      *
 931:      * @param   string $fileName
 932:      * @param   null|Mage_Core_Model_Config_Base $mergeToObject
 933:      * @return  Mage_Core_Model_Config_Base
 934:      */
 935:     public function loadModulesConfiguration($fileName, $mergeToObject = null, $mergeModel=null)
 936:     {
 937:         $disableLocalModules = !$this->_canUseLocalModules();
 938: 
 939:         if ($mergeToObject === null) {
 940:             $mergeToObject = clone $this->_prototype;
 941:             $mergeToObject->loadString('<config/>');
 942:         }
 943:         if ($mergeModel === null) {
 944:             $mergeModel = clone $this->_prototype;
 945:         }
 946:         $modules = $this->getNode('modules')->children();
 947:         foreach ($modules as $modName=>$module) {
 948:             if ($module->is('active')) {
 949:                 if ($disableLocalModules && ('local' === (string)$module->codePool)) {
 950:                     continue;
 951:                 }
 952:                 if (!is_array($fileName)) {
 953:                     $fileName = array($fileName);
 954:                 }
 955: 
 956:                 foreach ($fileName as $configFile) {
 957:                     $configFile = $this->getModuleDir('etc', $modName).DS.$configFile;
 958:                     if ($mergeModel->loadFile($configFile)) {
 959:                         $mergeToObject->extend($mergeModel, true);
 960:                     }
 961:                 }
 962:             }
 963:         }
 964:         return $mergeToObject;
 965:     }
 966: 
 967:     /**
 968:      * Retrieve temporary directory path
 969:      *
 970:      * @return string
 971:      */
 972:     public function getTempVarDir()
 973:     {
 974:         return $this->getOptions()->getVarDir();
 975:     }
 976: 
 977:     /**
 978:      * Get default server variables values
 979:      *
 980:      * @return array
 981:      */
 982:     public function getDistroServerVars()
 983:     {
 984:         if (!$this->_distroServerVars) {
 985: 
 986:             if (isset($_SERVER['SCRIPT_NAME']) && isset($_SERVER['HTTP_HOST'])) {
 987:                 $secure = (!empty($_SERVER['HTTPS']) && ($_SERVER['HTTPS']!='off')) || $_SERVER['SERVER_PORT']=='443';
 988:                 $scheme = ($secure ? 'https' : 'http') . '://' ;
 989: 
 990:                 $hostArr = explode(':', $_SERVER['HTTP_HOST']);
 991:                 $host = $hostArr[0];
 992:                 $port = isset(
 993:                     $hostArr[1]) && (!$secure && $hostArr[1]!=80 || $secure && $hostArr[1]!=443
 994:                 ) ? ':'.$hostArr[1] : '';
 995:                 $path = Mage::app()->getRequest()->getBasePath();
 996: 
 997:                 $baseUrl = $scheme.$host.$port.rtrim($path, '/').'/';
 998:             } else {
 999:                 $baseUrl = 'http://localhost/';
1000:             }
1001: 
1002:             $options = $this->getOptions();
1003:             $this->_distroServerVars = array(
1004:                 'root_dir'  => $options->getBaseDir(),
1005:                 'app_dir'   => $options->getAppDir(),
1006:                 'var_dir'   => $options->getVarDir(),
1007:                 'base_url'  => $baseUrl,
1008:             );
1009: 
1010:             foreach ($this->_distroServerVars as $k=>$v) {
1011:                 $this->_substServerVars['{{'.$k.'}}'] = $v;
1012:             }
1013:         }
1014:         return $this->_distroServerVars;
1015:     }
1016: 
1017:     public function substDistroServerVars($data)
1018:     {
1019:         $this->getDistroServerVars();
1020:         return str_replace(
1021:             array_keys($this->_substServerVars),
1022:             array_values($this->_substServerVars),
1023:             $data
1024:         );
1025:     }
1026: 
1027:     /**
1028:      * Get module config node
1029:      *
1030:      * @param string $moduleName
1031:      * @return Varien_Simplexml_Object
1032:      */
1033:     function getModuleConfig($moduleName='')
1034:     {
1035:         $modules = $this->getNode('modules');
1036:         if (''===$moduleName) {
1037:             return $modules;
1038:         } else {
1039:             return $modules->$moduleName;
1040:         }
1041:     }
1042: 
1043:     /**
1044:      * Get module setup class instance.
1045:      *
1046:      * Defaults to Mage_Core_Setup
1047:      *
1048:      * @param string|Varien_Simplexml_Object $module
1049:      * @return object
1050:      */
1051:     function getModuleSetup($module='')
1052:     {
1053:         $className = 'Mage_Core_Setup';
1054:         if (''!==$module) {
1055:             if (is_string($module)) {
1056:                 $module = $this->getModuleConfig($module);
1057:             }
1058:             if (isset($module->setup)) {
1059:                 $moduleClassName = $module->setup->getClassName();
1060:                 if (!empty($moduleClassName)) {
1061:                     $className = $moduleClassName;
1062:                 }
1063:             }
1064:         }
1065:         return new $className($module);
1066:     }
1067: 
1068:     /**
1069:      * Get base filesystem directory. depends on $type
1070:      *
1071:      * If $moduleName is specified retrieves specific value for the module.
1072:      *
1073:      * @deprecated in favor of Mage_Core_Model_Config_Options
1074:      * @todo get global dir config
1075:      * @param string $type
1076:      * @return string
1077:      */
1078:     public function getBaseDir($type='base')
1079:     {
1080:         return $this->getOptions()->getDir($type);
1081:     }
1082: 
1083:     /**
1084:      * Get temporary data directory name
1085:      *
1086:      * @param   string $path
1087:      * @param   string $type
1088:      * @return  string
1089:      */
1090:     public function getVarDir($path=null, $type='var')
1091:     {
1092:         $dir = Mage::getBaseDir($type).($path!==null ? DS.$path : '');
1093:         if (!$this->createDirIfNotExists($dir)) {
1094:             return false;
1095:         }
1096:         return $dir;
1097:     }
1098: 
1099:     public function createDirIfNotExists($dir)
1100:     {
1101:         return $this->getOptions()->createDirIfNotExists($dir);
1102:     }
1103: 
1104:     /**
1105:      * Get module directory by directory type
1106:      *
1107:      * @param   string $type
1108:      * @param   string $moduleName
1109:      * @return  string
1110:      */
1111:     public function getModuleDir($type, $moduleName)
1112:     {
1113:         $codePool = (string)$this->getModuleConfig($moduleName)->codePool;
1114:         $dir = $this->getOptions()->getCodeDir().DS.$codePool.DS.uc_words($moduleName, DS);
1115: 
1116:         switch ($type) {
1117:             case 'etc':
1118:                 $dir .= DS.'etc';
1119:                 break;
1120: 
1121:             case 'controllers':
1122:                 $dir .= DS.'controllers';
1123:                 break;
1124: 
1125:             case 'sql':
1126:                 $dir .= DS.'sql';
1127:                 break;
1128:             case 'data':
1129:                 $dir .= DS.'data';
1130:                 break;
1131: 
1132:             case 'locale':
1133:                 $dir .= DS.'locale';
1134:                 break;
1135:         }
1136: 
1137:         $dir = str_replace('/', DS, $dir);
1138:         return $dir;
1139:     }
1140: 
1141:     /**
1142:      * Load event observers for an area (front, admin)
1143:      *
1144:      * @param   string $area
1145:      * @return  boolean
1146:      */
1147:     public function loadEventObservers($area)
1148:     {
1149:         $events = $this->getNode("$area/events");
1150:         if ($events) {
1151:             $events = $events->children();
1152:         } else {
1153:             return false;
1154:         }
1155: 
1156:         foreach ($events as $event) {
1157:             $eventName = $event->getName();
1158:             $observers = $event->observers->children();
1159:             foreach ($observers as $observer) {
1160:                 switch ((string)$observer->type) {
1161:                     case 'singleton':
1162:                         $callback = array(
1163:                             Mage::getSingleton((string)$observer->class),
1164:                             (string)$observer->method
1165:                         );
1166:                         break;
1167:                     case 'object':
1168:                     case 'model':
1169:                         $callback = array(
1170:                             Mage::getModel((string)$observer->class),
1171:                             (string)$observer->method
1172:                         );
1173:                         break;
1174:                     default:
1175:                         $callback = array($observer->getClassName(), (string)$observer->method);
1176:                         break;
1177:                 }
1178: 
1179:                 $args = (array)$observer->args;
1180:                 $observerClass = $observer->observer_class ? (string)$observer->observer_class : '';
1181:                 Mage::addObserver($eventName, $callback, $args, $observer->getName(), $observerClass);
1182:             }
1183:         }
1184:         return true;
1185:     }
1186: 
1187:     /**
1188:      * Get standard path variables.
1189:      *
1190:      * To be used in blocks, templates, etc.
1191:      *
1192:      * @param array|string $args Module name if string
1193:      * @return array
1194:      */
1195:     public function getPathVars($args=null)
1196:     {
1197:         $path = array();
1198: 
1199:         $path['baseUrl'] = Mage::getBaseUrl();
1200:         $path['baseSecureUrl'] = Mage::getBaseUrl('link', true);
1201: 
1202:         return $path;
1203:     }
1204: 
1205:     /**
1206:      * Retrieve class name by class group
1207:      *
1208:      * @param   string $groupType currently supported model, block, helper
1209:      * @param   string $classId slash separated class identifier, ex. group/class
1210:      * @param   string $groupRootNode optional config path for group config
1211:      * @return  string
1212:      */
1213:     public function getGroupedClassName($groupType, $classId, $groupRootNode=null)
1214:     {
1215:         if (empty($groupRootNode)) {
1216:             $groupRootNode = 'global/'.$groupType.'s';
1217:         }
1218: 
1219:         $classArr = explode('/', trim($classId));
1220:         $group = $classArr[0];
1221:         $class = !empty($classArr[1]) ? $classArr[1] : null;
1222: 
1223:         if (isset($this->_classNameCache[$groupRootNode][$group][$class])) {
1224:             return $this->_classNameCache[$groupRootNode][$group][$class];
1225:         }
1226: 
1227:         $config = $this->_xml->global->{$groupType.'s'}->{$group};
1228: 
1229:         // First - check maybe the entity class was rewritten
1230:         $className = null;
1231:         if (isset($config->rewrite->$class)) {
1232:             $className = (string)$config->rewrite->$class;
1233:         } else {
1234:             /**
1235:              * Backwards compatibility for pre-MMDB extensions.
1236:              * In MMDB release resource nodes <..._mysql4> were renamed to <..._resource>. So <deprecatedNode> is left
1237:              * to keep name of previously used nodes, that still may be used by non-updated extensions.
1238:              */
1239:             if ($config->deprecatedNode) {
1240:                 $deprecatedNode = $config->deprecatedNode;
1241:                 $configOld = $this->_xml->global->{$groupType.'s'}->$deprecatedNode;
1242:                 if (isset($configOld->rewrite->$class)) {
1243:                     $className = (string) $configOld->rewrite->$class;
1244:                 }
1245:             }
1246:         }
1247: 
1248:         // Second - if entity is not rewritten then use class prefix to form class name
1249:         if (empty($className)) {
1250:             if (!empty($config)) {
1251:                 $className = $config->getClassName();
1252:             }
1253:             if (empty($className)) {
1254:                 $className = 'mage_'.$group.'_'.$groupType;
1255:             }
1256:             if (!empty($class)) {
1257:                 $className .= '_'.$class;
1258:             }
1259:             $className = uc_words($className);
1260:         }
1261: 
1262:         $this->_classNameCache[$groupRootNode][$group][$class] = $className;
1263:         return $className;
1264:     }
1265: 
1266:     /**
1267:      * Retrieve block class name
1268:      *
1269:      * @param   string $blockType
1270:      * @return  string
1271:      */
1272:     public function getBlockClassName($blockType)
1273:     {
1274:         if (strpos($blockType, '/')===false) {
1275:             return $blockType;
1276:         }
1277:         return $this->getGroupedClassName('block', $blockType);
1278:     }
1279: 
1280:     /**
1281:      * Retrieve helper class name
1282:      *
1283:      * @param   string $name
1284:      * @return  string
1285:      */
1286:     public function getHelperClassName($helperName)
1287:     {
1288:         if (strpos($helperName, '/') === false) {
1289:             $helperName .= '/data';
1290:         }
1291:         return $this->getGroupedClassName('helper', $helperName);
1292:     }
1293: 
1294:     /**
1295:      * Retreive resource helper instance
1296:      *
1297:      * Example:
1298:      * $config->getResourceHelper('cms')
1299:      * will instantiate Mage_Cms_Model_Resource_Helper_<db_adapter_name>
1300:      *
1301:      * @param string $moduleName
1302:      * @return Mage_Core_Model_Resource_Helper_Abstract|false
1303:      */
1304:     public function getResourceHelper($moduleName)
1305:     {
1306:         $connectionModel = $this->_getResourceConnectionModel($moduleName);
1307:         $helperClass     = sprintf('%s/helper_%s', $moduleName, $connectionModel);
1308:         $helperClassName = $this->_getResourceModelFactoryClassName($helperClass);
1309:         if ($helperClassName) {
1310:             return $this->getModelInstance($helperClassName, $moduleName);
1311:         }
1312: 
1313:         return false;
1314:     }
1315: 
1316:     /**
1317:      * Retrieve module class name
1318:      *
1319:      * @param   sting $modelClass
1320:      * @return  string
1321:      */
1322:     public function getModelClassName($modelClass)
1323:     {
1324:         $modelClass = trim($modelClass);
1325:         if (strpos($modelClass, '/')===false) {
1326:             return $modelClass;
1327:         }
1328:         return $this->getGroupedClassName('model', $modelClass);
1329:     }
1330: 
1331:     /**
1332:      * Get model class instance.
1333:      *
1334:      * Example:
1335:      * $config->getModelInstance('catalog/product')
1336:      *
1337:      * Will instantiate Mage_Catalog_Model_Mysql4_Product
1338:      *
1339:      * @param string $modelClass
1340:      * @param array|object $constructArguments
1341:      * @return Mage_Core_Model_Abstract|false
1342:      */
1343:     public function getModelInstance($modelClass='', $constructArguments=array())
1344:     {
1345:         $className = $this->getModelClassName($modelClass);
1346:         if (class_exists($className)) {
1347:             Varien_Profiler::start('CORE::create_object_of::'.$className);
1348:             $obj = new $className($constructArguments);
1349:             Varien_Profiler::stop('CORE::create_object_of::'.$className);
1350:             return $obj;
1351:         } else {
1352:             return false;
1353:         }
1354:     }
1355: 
1356:     public function getNodeClassInstance($path)
1357:     {
1358:         $config = Mage::getConfig()->getNode($path);
1359:         if (!$config) {
1360:             return false;
1361:         } else {
1362:             $className = $config->getClassName();
1363:             return new $className();
1364:         }
1365:     }
1366: 
1367:     /**
1368:      * Get resource model object by alias
1369:      *
1370:      * @param   string $modelClass
1371:      * @param   array $constructArguments
1372:      * @return  object
1373:      */
1374:     public function getResourceModelInstance($modelClass='', $constructArguments=array())
1375:     {
1376:         $factoryName = $this->_getResourceModelFactoryClassName($modelClass);
1377:         if (!$factoryName) {
1378:             return false;
1379:         }
1380:         return $this->getModelInstance($factoryName, $constructArguments);
1381:     }
1382: 
1383:     /**
1384:      * Get resource configuration for resource name
1385:      *
1386:      * @param string $name
1387:      * @return Varien_Simplexml_Object
1388:      */
1389:     public function getResourceConfig($name)
1390:     {
1391:         return $this->_xml->global->resources->{$name};
1392:     }
1393: 
1394:     /**
1395:      * Get connection configuration
1396:      *
1397:      * @param   string $name
1398:      * @return  Varien_Simplexml_Element
1399:      */
1400:     public function getResourceConnectionConfig($name)
1401:     {
1402:         $config = $this->getResourceConfig($name);
1403:         if ($config) {
1404:             $conn = $config->connection;
1405:             if ($conn) {
1406:                 if (!empty($conn->use)) {
1407:                     return $this->getResourceConnectionConfig((string)$conn->use);
1408:                 } else {
1409:                     return $conn;
1410:                 }
1411:             }
1412:         }
1413:         return false;
1414:     }
1415: 
1416:     /**
1417:      * Retrieve resource type configuration for resource name
1418:      *
1419:      * @param string $type
1420:      * @return Varien_Simplexml_Object
1421:      */
1422:     public function getResourceTypeConfig($type)
1423:     {
1424:         return $this->_xml->global->resource->connection->types->{$type};
1425:     }
1426: 
1427:     /**
1428:      * Retrieve store Ids for $path with checking
1429:      *
1430:      * if empty $allowValues then retrieve all stores values
1431:      *
1432:      * return array($storeId=>$pathValue)
1433:      *
1434:      * @param   string $path
1435:      * @param   array  $allowValues
1436:      * @return  array
1437:      */
1438:     public function getStoresConfigByPath($path, $allowValues = array(), $useAsKey = 'id')
1439:     {
1440:         $storeValues = array();
1441:         $stores = $this->getNode('stores');
1442:         foreach ($stores->children() as $code => $store) {
1443:             switch ($useAsKey) {
1444:                 case 'id':
1445:                     $key = (int) $store->descend('system/store/id');
1446:                     break;
1447: 
1448:                 case 'code':
1449:                     $key = $code;
1450:                     break;
1451: 
1452:                 case 'name':
1453:                     $key = (string) $store->descend('system/store/name');
1454:             }
1455:             if ($key === false) {
1456:                 continue;
1457:             }
1458: 
1459:             $pathValue = (string) $store->descend($path);
1460: 
1461:             if (empty($allowValues)) {
1462:                 $storeValues[$key] = $pathValue;
1463:             } else if (in_array($pathValue, $allowValues)) {
1464:                 $storeValues[$key] = $pathValue;
1465:             }
1466:         }
1467:         return $storeValues;
1468:     }
1469: 
1470:     /**
1471:      * Check whether given path should be secure according to configuration security requirements for URL
1472:      * "Secure" should not be confused with https protocol, it is about web/secure/*_url settings usage only
1473:      *
1474:      * @param string $url
1475:      * @return bool
1476:      */
1477:     public function shouldUrlBeSecure($url)
1478:     {
1479:         if (!Mage::getStoreConfigFlag(Mage_Core_Model_Store::XML_PATH_SECURE_IN_FRONTEND)) {
1480:             return false;
1481:         }
1482: 
1483:         if (!isset($this->_secureUrlCache[$url])) {
1484:             $this->_secureUrlCache[$url] = false;
1485:             $secureUrls = $this->getNode('frontend/secure_url');
1486:             foreach ($secureUrls->children() as $match) {
1487:                 if (strpos($url, (string)$match) === 0) {
1488:                     $this->_secureUrlCache[$url] = true;
1489:                     break;
1490:                 }
1491:             }
1492:         }
1493: 
1494:         return $this->_secureUrlCache[$url];
1495:     }
1496: 
1497:     /**
1498:      * Get DB table names prefix
1499:      *
1500:      * @return string
1501:      */
1502:     public function getTablePrefix()
1503:     {
1504:         return $this->_xml->global->resources->db->table_prefix;
1505:     }
1506: 
1507:     /**
1508:      * Get events configuration
1509:      *
1510:      * @param   string $area event area
1511:      * @param   string $eventName event name
1512:      * @return  Mage_Core_Model_Config_Element
1513:      */
1514:     public function getEventConfig($area, $eventName)
1515:     {
1516:         //return $this->getNode($area)->events->{$eventName};
1517:         if (!isset($this->_eventAreas[$area])) {
1518:             $this->_eventAreas[$area] = $this->getNode($area)->events;
1519:         }
1520:         return $this->_eventAreas[$area]->{$eventName};
1521:     }
1522: 
1523:     /**
1524:      * Save config value to DB
1525:      *
1526:      * @param string $path
1527:      * @param string $value
1528:      * @param string $scope
1529:      * @param int $scopeId
1530:      * @return Mage_Core_Store_Config
1531:      */
1532:     public function saveConfig($path, $value, $scope = 'default', $scopeId = 0)
1533:     {
1534:         $resource = $this->getResourceModel();
1535:         $resource->saveConfig(rtrim($path, '/'), $value, $scope, $scopeId);
1536: 
1537:         return $this;
1538:     }
1539: 
1540:     /**
1541:      * Delete config value from DB
1542:      *
1543:      * @param   string $path
1544:      * @param   string $scope
1545:      * @param   int $scopeId
1546:      * @return  Mage_Core_Model_Config
1547:      */
1548:     public function deleteConfig($path, $scope = 'default', $scopeId = 0)
1549:     {
1550:         $resource = $this->getResourceModel();
1551:         $resource->deleteConfig(rtrim($path, '/'), $scope, $scopeId);
1552: 
1553:         return $this;
1554:     }
1555: 
1556:     /**
1557:      * Get fieldset from configuration
1558:      *
1559:      * @param string $name fieldset name
1560:      * @param string $root fieldset area, could be 'admin'
1561:      * @return null|array
1562:      */
1563:     public function getFieldset($name, $root = 'global')
1564:     {
1565:         $rootNode = $this->getNode($root.'/fieldsets');
1566:         if (!$rootNode) {
1567:             return null;
1568:         }
1569:         return $rootNode->$name ? $rootNode->$name->children() : null;
1570:     }
1571: 
1572:     /**
1573:      * Retrieve resource connection model name
1574:      *
1575:      * @param string $moduleName
1576:      * @return string
1577:      */
1578:     protected function _getResourceConnectionModel($moduleName = null)
1579:     {
1580:         $config = null;
1581:         if (!is_null($moduleName)) {
1582:             $setupResource = $moduleName . '_setup';
1583:             $config        = $this->getResourceConnectionConfig($setupResource);
1584:         }
1585:         if (!$config) {
1586:             $config = $this->getResourceConnectionConfig(Mage_Core_Model_Resource::DEFAULT_SETUP_RESOURCE);
1587:         }
1588: 
1589:         return (string)$config->model;
1590:     }
1591: 
1592:     /**
1593:      * Get factory class name for a resource
1594:      *
1595:      * @param string $modelClass
1596:      * @return string|false
1597:      */
1598:     protected function _getResourceModelFactoryClassName($modelClass)
1599:     {
1600:         $classArray = explode('/', $modelClass);
1601:         if (count($classArray) != 2) {
1602:             return false;
1603:         }
1604: 
1605:         list($module, $model) = $classArray;
1606:         if (!isset($this->_xml->global->models->{$module})) {
1607:             return false;
1608:         }
1609: 
1610:         $moduleNode = $this->_xml->global->models->{$module};
1611:         if (!empty($moduleNode->resourceModel)) {
1612:             $resourceModel = (string)$moduleNode->resourceModel;
1613:         } else {
1614:             return false;
1615:         }
1616: 
1617:         return $resourceModel . '/' . $model;
1618:     }
1619: 
1620:     /**
1621:      * Get a resource model class name
1622:      *
1623:      * @param string $modelClass
1624:      * @return string|false
1625:      */
1626:     public function getResourceModelClassName($modelClass)
1627:     {
1628:         $factoryName = $this->_getResourceModelFactoryClassName($modelClass);
1629:         if ($factoryName) {
1630:             return $this->getModelClassName($factoryName);
1631:         }
1632:         return false;
1633:     }
1634: }
1635: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0