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:  * Application model
  29:  *
  30:  * Application should have: areas, store, locale, translator, design package
  31:  *
  32:  * @category    Mage
  33:  * @package     Mage_Core
  34:  * @author      Magento Core Team <core@magentocommerce.com>
  35:  */
  36: class Mage_Core_Model_App
  37: {
  38: 
  39:     const XML_PATH_INSTALL_DATE = 'global/install/date';
  40: 
  41:     const XML_PATH_SKIP_PROCESS_MODULES_UPDATES = 'global/skip_process_modules_updates';
  42: 
  43:     /**
  44:      * if this node set to true, we will ignore Developer Mode for applying updates
  45:      */
  46:     const XML_PATH_IGNORE_DEV_MODE = 'global/skip_process_modules_updates_ignore_dev_mode';
  47: 
  48:     const DEFAULT_ERROR_HANDLER = 'mageCoreErrorHandler';
  49: 
  50:     const DISTRO_LOCALE_CODE = 'en_US';
  51: 
  52:     /**
  53:      * Cache tag for all cache data exclude config cache
  54:      *
  55:      */
  56:     const CACHE_TAG = 'MAGE';
  57: 
  58:     /**
  59:      * Default store Id (for install)
  60:      */
  61:     const DISTRO_STORE_ID       = 1;
  62: 
  63:     /**
  64:      * Default store code (for install)
  65:      *
  66:      */
  67:     const DISTRO_STORE_CODE     = 'default';
  68: 
  69:     /**
  70:      * Admin store Id
  71:      *
  72:      */
  73:     const ADMIN_STORE_ID = 0;
  74: 
  75:     /**
  76:      * Application loaded areas array
  77:      *
  78:      * @var array
  79:      */
  80:     protected $_areas = array();
  81: 
  82:     /**
  83:      * Application store object
  84:      *
  85:      * @var Mage_Core_Model_Store
  86:      */
  87:     protected $_store;
  88: 
  89:     /**
  90:      * Application website object
  91:      *
  92:      * @var Mage_Core_Model_Website
  93:      */
  94:     protected $_website;
  95: 
  96:     /**
  97:      * Application location object
  98:      *
  99:      * @var Mage_Core_Model_Locale
 100:      */
 101:     protected $_locale;
 102: 
 103:     /**
 104:      * Application translate object
 105:      *
 106:      * @var Mage_Core_Model_Translate
 107:      */
 108:     protected $_translator;
 109: 
 110:     /**
 111:      * Application design package object
 112:      *
 113:      * @var Mage_Core_Model_Design_Package
 114:      */
 115:     protected $_design;
 116: 
 117:     /**
 118:      * Application layout object
 119:      *
 120:      * @var Mage_Core_Model_Layout
 121:      */
 122:     protected $_layout;
 123: 
 124:     /**
 125:      * Application configuration object
 126:      *
 127:      * @var Mage_Core_Model_Config
 128:      */
 129:     protected $_config;
 130: 
 131:     /**
 132:      * Application front controller
 133:      *
 134:      * @var Mage_Core_Controller_Varien_Front
 135:      */
 136:     protected $_frontController;
 137: 
 138:     /**
 139:      * Cache object
 140:      *
 141:      * @var Zend_Cache_Core
 142:      */
 143:     protected $_cache;
 144: 
 145:     /**
 146:     * Use Cache
 147:     *
 148:     * @var array
 149:     */
 150:     protected $_useCache;
 151: 
 152:     /**
 153:      * Websites cache
 154:      *
 155:      * @var array
 156:      */
 157:     protected $_websites = array();
 158: 
 159:     /**
 160:      * Groups cache
 161:      *
 162:      * @var array
 163:      */
 164:     protected $_groups = array();
 165: 
 166:     /**
 167:      * Stores cache
 168:      *
 169:      * @var array
 170:      */
 171:     protected $_stores = array();
 172: 
 173:     /**
 174:      * is a single store mode
 175:      *
 176:      * @var bool
 177:      */
 178:     protected $_isSingleStore;
 179: 
 180:     /**
 181:      * @var bool
 182:      */
 183:     protected $_isSingleStoreAllowed = true;
 184: 
 185:     /**
 186:      * Default store code
 187:      *
 188:      * @var string
 189:      */
 190:     protected $_currentStore;
 191: 
 192:     /**
 193:      * Request object
 194:      *
 195:      * @var Zend_Controller_Request_Http
 196:      */
 197:     protected $_request;
 198: 
 199:     /**
 200:      * Response object
 201:      *
 202:      * @var Zend_Controller_Response_Http
 203:      */
 204:     protected $_response;
 205: 
 206: 
 207:     /**
 208:      * Events cache
 209:      *
 210:      * @var array
 211:      */
 212:     protected $_events = array();
 213: 
 214:     /**
 215:      * Update process run flag
 216:      *
 217:      * @var bool
 218:      */
 219:     protected $_updateMode = false;
 220: 
 221:     /**
 222:      * Use session in URL flag
 223:      *
 224:      * @see Mage_Core_Model_Url
 225:      * @var bool
 226:      */
 227:     protected $_useSessionInUrl = true;
 228: 
 229:     /**
 230:      * Use session var instead of SID for session in URL
 231:      *
 232:      * @var bool
 233:      */
 234:     protected $_useSessionVar = false;
 235: 
 236:     /**
 237:      * Cache locked flag
 238:      *
 239:      * @var null|bool
 240:      */
 241:     protected $_isCacheLocked = null;
 242: 
 243:     /**
 244:      * Constructor
 245:      */
 246:     public function __construct()
 247:     {
 248:     }
 249: 
 250:     /**
 251:      * Initialize application without request processing
 252:      *
 253:      * @param  string|array $code
 254:      * @param  string $type
 255:      * @param  string|array $options
 256:      * @return Mage_Core_Model_App
 257:      */
 258:     public function init($code, $type = null, $options = array())
 259:     {
 260:         $this->_initEnvironment();
 261:         if (is_string($options)) {
 262:             $options = array('etc_dir'=>$options);
 263:         }
 264: 
 265:         Varien_Profiler::start('mage::app::init::config');
 266:         $this->_config = Mage::getConfig();
 267:         $this->_config->setOptions($options);
 268:         $this->_initBaseConfig();
 269:         $this->_initCache();
 270:         $this->_config->init($options);
 271:         Varien_Profiler::stop('mage::app::init::config');
 272: 
 273:         if (Mage::isInstalled($options)) {
 274:             $this->_initCurrentStore($code, $type);
 275:             $this->_initRequest();
 276:         }
 277:         return $this;
 278:     }
 279: 
 280:     /**
 281:      * Common logic for all run types
 282:      *
 283:      * @param  string|array $options
 284:      * @return Mage_Core_Model_App
 285:      */
 286:     public function baseInit($options)
 287:     {
 288:         $this->_initEnvironment();
 289: 
 290:         $this->_config = Mage::getConfig();
 291:         $this->_config->setOptions($options);
 292: 
 293:         $this->_initBaseConfig();
 294:         $cacheInitOptions = is_array($options) && array_key_exists('cache', $options) ? $options['cache'] : array();
 295:         $this->_initCache($cacheInitOptions);
 296: 
 297:         return $this;
 298:     }
 299: 
 300:     /**
 301:      * Run light version of application with specified modules support
 302:      *
 303:      * @see Mage_Core_Model_App->run()
 304:      *
 305:      * @param  string|array $scopeCode
 306:      * @param  string $scopeType
 307:      * @param  string|array $options
 308:      * @param  string|array $modules
 309:      * @return Mage_Core_Model_App
 310:      */
 311:     public function initSpecified($scopeCode, $scopeType = null, $options = array(), $modules = array())
 312:     {
 313:         $this->baseInit($options);
 314: 
 315:         if (!empty($modules)) {
 316:             $this->_config->addAllowedModules($modules);
 317:         }
 318:         $this->_initModules();
 319:         $this->_initCurrentStore($scopeCode, $scopeType);
 320: 
 321:         return $this;
 322:     }
 323: 
 324:     /**
 325:      * Run application. Run process responsible for request processing and sending response.
 326:      * List of supported parameters:
 327:      *  scope_code - code of default scope (website/store_group/store code)
 328:      *  scope_type - type of default scope (website/group/store)
 329:      *  options    - configuration options
 330:      *
 331:      * @param  array $params application run parameters
 332:      * @return Mage_Core_Model_App
 333:      */
 334:     public function run($params)
 335:     {
 336:         $options = isset($params['options']) ? $params['options'] : array();
 337:         $this->baseInit($options);
 338:         Mage::register('application_params', $params);
 339: 
 340:         if ($this->_cache->processRequest()) {
 341:             $this->getResponse()->sendResponse();
 342:         } else {
 343:             $this->_initModules();
 344:             $this->loadAreaPart(Mage_Core_Model_App_Area::AREA_GLOBAL, Mage_Core_Model_App_Area::PART_EVENTS);
 345: 
 346:             if ($this->_config->isLocalConfigLoaded()) {
 347:                 $scopeCode = isset($params['scope_code']) ? $params['scope_code'] : '';
 348:                 $scopeType = isset($params['scope_type']) ? $params['scope_type'] : 'store';
 349:                 $this->_initCurrentStore($scopeCode, $scopeType);
 350:                 $this->_initRequest();
 351:                 Mage_Core_Model_Resource_Setup::applyAllDataUpdates();
 352:             }
 353: 
 354:             $this->getFrontController()->dispatch();
 355:         }
 356:         return $this;
 357:     }
 358: 
 359:     /**
 360:      * Initialize PHP environment
 361:      *
 362:      * @return Mage_Core_Model_App
 363:      */
 364:     protected function _initEnvironment()
 365:     {
 366:         $this->setErrorHandler(self::DEFAULT_ERROR_HANDLER);
 367:         date_default_timezone_set(Mage_Core_Model_Locale::DEFAULT_TIMEZONE);
 368:         return $this;
 369:     }
 370: 
 371:     /**
 372:      * Initialize base system configuration (local.xml and config.xml files).
 373:      * Base configuration provide ability initialize DB connection and cache backend
 374:      *
 375:      * @return Mage_Core_Model_App
 376:      */
 377:     protected function _initBaseConfig()
 378:     {
 379:         Varien_Profiler::start('mage::app::init::system_config');
 380:         $this->_config->loadBase();
 381:         Varien_Profiler::stop('mage::app::init::system_config');
 382:         return $this;
 383:     }
 384: 
 385:     /**
 386:      * Initialize application cache instance
 387:      *
 388:      * @param array $cacheInitOptions
 389:      * @return Mage_Core_Model_App
 390:      */
 391:     protected function _initCache(array $cacheInitOptions = array())
 392:     {
 393:         $this->_isCacheLocked = true;
 394:         $options = $this->_config->getNode('global/cache');
 395:         if ($options) {
 396:             $options = $options->asArray();
 397:         } else {
 398:             $options = array();
 399:         }
 400:         $options = array_merge($options, $cacheInitOptions);
 401:         $this->_cache = Mage::getModel('core/cache', $options);
 402:         $this->_isCacheLocked = false;
 403:         return $this;
 404:     }
 405: 
 406:     /**
 407:      * Initialize active modules configuration and data
 408:      *
 409:      * @return Mage_Core_Model_App
 410:      */
 411:     protected function _initModules()
 412:     {
 413:         if (!$this->_config->loadModulesCache()) {
 414:             $this->_config->loadModules();
 415:             if ($this->_config->isLocalConfigLoaded() && !$this->_shouldSkipProcessModulesUpdates()) {
 416:                 Varien_Profiler::start('mage::app::init::apply_db_schema_updates');
 417:                 Mage_Core_Model_Resource_Setup::applyAllUpdates();
 418:                 Varien_Profiler::stop('mage::app::init::apply_db_schema_updates');
 419:             }
 420:             $this->_config->loadDb();
 421:             $this->_config->saveCache();
 422:         }
 423:         return $this;
 424:     }
 425: 
 426:     /**
 427:      * Check whether modules updates processing should be skipped
 428:      *
 429:      * @return bool
 430:      */
 431:     protected function _shouldSkipProcessModulesUpdates()
 432:     {
 433:         if (!Mage::isInstalled()) {
 434:             return false;
 435:         }
 436: 
 437:         $ignoreDevelopmentMode = (bool)(string)$this->_config->getNode(self::XML_PATH_IGNORE_DEV_MODE);
 438:         if (Mage::getIsDeveloperMode() && !$ignoreDevelopmentMode) {
 439:             return false;
 440:         }
 441: 
 442:         return (bool)(string)$this->_config->getNode(self::XML_PATH_SKIP_PROCESS_MODULES_UPDATES);
 443:     }
 444: 
 445:     /**
 446:      * Init request object
 447:      *
 448:      * @return Mage_Core_Model_App
 449:      */
 450:     protected function _initRequest()
 451:     {
 452:         $this->getRequest()->setPathInfo();
 453:         return $this;
 454:     }
 455: 
 456:     /**
 457:      * Initialize currently ran store
 458:      *
 459:      * @param string $scopeCode code of default scope (website/store_group/store code)
 460:      * @param string $scopeType type of default scope (website/group/store)
 461:      * @return unknown_type
 462:      */
 463:     protected function _initCurrentStore($scopeCode, $scopeType)
 464:     {
 465:         Varien_Profiler::start('mage::app::init::stores');
 466:         $this->_initStores();
 467:         Varien_Profiler::stop('mage::app::init::stores');
 468: 
 469:         if (empty($scopeCode) && !is_null($this->_website)) {
 470:             $scopeCode = $this->_website->getCode();
 471:             $scopeType = 'website';
 472:         }
 473:         switch ($scopeType) {
 474:             case 'store':
 475:                 $this->_currentStore = $scopeCode;
 476:                 break;
 477:             case 'group':
 478:                 $this->_currentStore = $this->_getStoreByGroup($scopeCode);
 479:                 break;
 480:             case 'website':
 481:                 $this->_currentStore = $this->_getStoreByWebsite($scopeCode);
 482:                 break;
 483:             default:
 484:                 $this->throwStoreException();
 485:         }
 486: 
 487:         if (!empty($this->_currentStore)) {
 488:             $this->_checkCookieStore($scopeType);
 489:             $this->_checkGetStore($scopeType);
 490:         }
 491:         $this->_useSessionInUrl = $this->getStore()->getConfig(
 492:             Mage_Core_Model_Session_Abstract::XML_PATH_USE_FRONTEND_SID);
 493:         return $this;
 494:     }
 495: 
 496:     /**
 497:      * Retrieve cookie object
 498:      *
 499:      * @return Mage_Core_Model_Cookie
 500:      */
 501:     public function getCookie()
 502:     {
 503:         return Mage::getSingleton('core/cookie');
 504:     }
 505: 
 506:     /**
 507:      * Check get store
 508:      *
 509:      * @return Mage_Core_Model_App
 510:      */
 511:     protected function _checkGetStore($type)
 512:     {
 513:         if (empty($_GET)) {
 514:             return $this;
 515:         }
 516: 
 517:         /**
 518:          * @todo check XML_PATH_STORE_IN_URL
 519:          */
 520:         if (!isset($_GET['___store'])) {
 521:             return $this;
 522:         }
 523: 
 524:         $store = $_GET['___store'];
 525:         if (!isset($this->_stores[$store])) {
 526:             return $this;
 527:         }
 528: 
 529:         $storeObj = $this->_stores[$store];
 530:         if (!$storeObj->getId() || !$storeObj->getIsActive()) {
 531:             return $this;
 532:         }
 533: 
 534:         /**
 535:          * prevent running a store from another website or store group,
 536:          * if website or store group was specified explicitly in Mage::run()
 537:          */
 538:         $curStoreObj = $this->_stores[$this->_currentStore];
 539:         if ($type == 'website' && $storeObj->getWebsiteId() == $curStoreObj->getWebsiteId()) {
 540:             $this->_currentStore = $store;
 541:         }
 542:         elseif ($type == 'group' && $storeObj->getGroupId() == $curStoreObj->getGroupId()) {
 543:             $this->_currentStore = $store;
 544:         }
 545:         elseif ($type == 'store') {
 546:             $this->_currentStore = $store;
 547:         }
 548: 
 549:         if ($this->_currentStore == $store) {
 550:             $store = $this->getStore($store);
 551:             if ($store->getWebsite()->getDefaultStore()->getId() == $store->getId()) {
 552:                 $this->getCookie()->delete(Mage_Core_Model_Store::COOKIE_NAME);
 553:             } else {
 554:                 $this->getCookie()->set(Mage_Core_Model_Store::COOKIE_NAME, $this->_currentStore, true);
 555:             }
 556:         }
 557:         return $this;
 558:     }
 559: 
 560:     /**
 561:      * Check cookie store
 562:      *
 563:      * @param string $type
 564:      * @return Mage_Core_Model_App
 565:      */
 566:     protected function _checkCookieStore($type)
 567:     {
 568:         if (!$this->getCookie()->get()) {
 569:             return $this;
 570:         }
 571: 
 572:         $store = $this->getCookie()->get(Mage_Core_Model_Store::COOKIE_NAME);
 573:         if ($store && isset($this->_stores[$store])
 574:             && $this->_stores[$store]->getId()
 575:             && $this->_stores[$store]->getIsActive()) {
 576:             if ($type == 'website'
 577:                 && $this->_stores[$store]->getWebsiteId() == $this->_stores[$this->_currentStore]->getWebsiteId()) {
 578:                 $this->_currentStore = $store;
 579:             }
 580:             if ($type == 'group'
 581:                 && $this->_stores[$store]->getGroupId() == $this->_stores[$this->_currentStore]->getGroupId()) {
 582:                 $this->_currentStore = $store;
 583:             }
 584:             if ($type == 'store') {
 585:                 $this->_currentStore = $store;
 586:             }
 587:         }
 588:         return $this;
 589:     }
 590: 
 591:     public function reinitStores()
 592:     {
 593:         return $this->_initStores();
 594:     }
 595: 
 596:     /**
 597:      * Init store, group and website collections
 598:      *
 599:      */
 600:     protected function _initStores()
 601:     {
 602:         $this->_stores   = array();
 603:         $this->_groups   = array();
 604:         $this->_website  = null;
 605:         $this->_websites = array();
 606: 
 607:         /** @var $websiteCollection Mage_Core_Model_Website */
 608:         $websiteCollection = Mage::getModel('core/website')->getCollection()
 609:                 ->initCache($this->getCache(), 'app', array(Mage_Core_Model_Website::CACHE_TAG))
 610:                 ->setLoadDefault(true);
 611: 
 612:         /** @var $websiteCollection Mage_Core_Model_Store_Group */
 613:         $groupCollection = Mage::getModel('core/store_group')->getCollection()
 614:                 ->initCache($this->getCache(), 'app', array(Mage_Core_Model_Store_Group::CACHE_TAG))
 615:                 ->setLoadDefault(true);
 616: 
 617:         /** @var $websiteCollection Mage_Core_Model_Store */
 618:         $storeCollection = Mage::getModel('core/store')->getCollection()
 619:             ->initCache($this->getCache(), 'app', array(Mage_Core_Model_Store::CACHE_TAG))
 620:             ->setLoadDefault(true);
 621: 
 622:         $this->_isSingleStore = false;
 623:         if ($this->_isSingleStoreAllowed) {
 624:             $this->_isSingleStore = $storeCollection->count() < 3;
 625:         }
 626: 
 627:         $websiteStores = array();
 628:         $websiteGroups = array();
 629:         $groupStores   = array();
 630: 
 631:         foreach ($storeCollection as $store) {
 632:             /** @var $store Mage_Core_Model_Store */
 633:             $store->initConfigCache();
 634:             $store->setWebsite($websiteCollection->getItemById($store->getWebsiteId()));
 635:             $store->setGroup($groupCollection->getItemById($store->getGroupId()));
 636: 
 637:             $this->_stores[$store->getId()] = $store;
 638:             $this->_stores[$store->getCode()] = $store;
 639: 
 640:             $websiteStores[$store->getWebsiteId()][$store->getId()] = $store;
 641:             $groupStores[$store->getGroupId()][$store->getId()] = $store;
 642: 
 643:             if (is_null($this->_store) && $store->getId()) {
 644:                 $this->_store = $store;
 645:             }
 646:         }
 647: 
 648:         foreach ($groupCollection as $group) {
 649:             /* @var $group Mage_Core_Model_Store_Group */
 650:             if (!isset($groupStores[$group->getId()])) {
 651:                 $groupStores[$group->getId()] = array();
 652:             }
 653:             $group->setStores($groupStores[$group->getId()]);
 654:             $group->setWebsite($websiteCollection->getItemById($group->getWebsiteId()));
 655: 
 656:             $websiteGroups[$group->getWebsiteId()][$group->getId()] = $group;
 657: 
 658:             $this->_groups[$group->getId()] = $group;
 659:         }
 660: 
 661:         foreach ($websiteCollection as $website) {
 662:             /* @var $website Mage_Core_Model_Website */
 663:             if (!isset($websiteGroups[$website->getId()])) {
 664:                 $websiteGroups[$website->getId()] = array();
 665:             }
 666:             if (!isset($websiteStores[$website->getId()])) {
 667:                 $websiteStores[$website->getId()] = array();
 668:             }
 669:             if ($website->getIsDefault()) {
 670:                 $this->_website = $website;
 671:             }
 672:             $website->setGroups($websiteGroups[$website->getId()]);
 673:             $website->setStores($websiteStores[$website->getId()]);
 674: 
 675:             $this->_websites[$website->getId()] = $website;
 676:             $this->_websites[$website->getCode()] = $website;
 677:         }
 678:     }
 679: 
 680:     /**
 681:      * Is single Store mode (only one store without default)
 682:      *
 683:      * @return bool
 684:      */
 685:     public function isSingleStoreMode()
 686:     {
 687:         if (!Mage::isInstalled()) {
 688:             return false;
 689:         }
 690:         return $this->_isSingleStore;
 691:     }
 692: 
 693:     /**
 694:      * Retrieve store code or null by store group
 695:      *
 696:      * @param int $group
 697:      * @return string|null
 698:      */
 699:     protected function _getStoreByGroup($group)
 700:     {
 701:         if (!isset($this->_groups[$group])) {
 702:             return null;
 703:         }
 704:         if (!$this->_groups[$group]->getDefaultStoreId()) {
 705:             return null;
 706:         }
 707:         return $this->_stores[$this->_groups[$group]->getDefaultStoreId()]->getCode();
 708:     }
 709: 
 710:     /**
 711:      * Retrieve store code or null by website
 712:      *
 713:      * @param int|string $website
 714:      * @return string|null
 715:      */
 716:     protected function _getStoreByWebsite($website)
 717:     {
 718:         if (!isset($this->_websites[$website])) {
 719:             return null;
 720:         }
 721:         if (!$this->_websites[$website]->getDefaultGroupId()) {
 722:             return null;
 723:         }
 724:         return $this->_getStoreByGroup($this->_websites[$website]->getDefaultGroupId());
 725:     }
 726: 
 727:     /**
 728:      * Set current default store
 729:      *
 730:      * @param string $store
 731:      * @return Mage_Core_Model_App
 732:      */
 733:     public function setCurrentStore($store)
 734:     {
 735:         $this->_currentStore = $store;
 736:         return $this;
 737:     }
 738: 
 739:     /**
 740:      * Initialize application front controller
 741:      *
 742:      * @return Mage_Core_Model_App
 743:      */
 744:     protected function _initFrontController()
 745:     {
 746:         $this->_frontController = new Mage_Core_Controller_Varien_Front();
 747:         Mage::register('controller', $this->_frontController);
 748:         Varien_Profiler::start('mage::app::init_front_controller');
 749:         $this->_frontController->init();
 750:         Varien_Profiler::stop('mage::app::init_front_controller');
 751:         return $this;
 752:     }
 753: 
 754:     /**
 755:      * Redeclare custom error handler
 756:      *
 757:      * @param   string $handler
 758:      * @return  Mage_Core_Model_App
 759:      */
 760:     public function setErrorHandler($handler)
 761:     {
 762:         set_error_handler($handler);
 763:         return $this;
 764:     }
 765: 
 766:     /**
 767:      * Loading application area
 768:      *
 769:      * @param   string $code
 770:      * @return  Mage_Core_Model_App
 771:      */
 772:     public function loadArea($code)
 773:     {
 774:         $this->getArea($code)->load();
 775:         return $this;
 776:     }
 777: 
 778:     /**
 779:      * Loding part of area data
 780:      *
 781:      * @param   string $area
 782:      * @param   string $part
 783:      * @return  Mage_Core_Model_App
 784:      */
 785:     public function loadAreaPart($area, $part)
 786:     {
 787:         $this->getArea($area)->load($part);
 788:         return $this;
 789:     }
 790: 
 791:     /**
 792:      * Retrieve application area
 793:      *
 794:      * @param   string $code
 795:      * @return  Mage_Core_Model_App_Area
 796:      */
 797:     public function getArea($code)
 798:     {
 799:         if (!isset($this->_areas[$code])) {
 800:             $this->_areas[$code] = new Mage_Core_Model_App_Area($code, $this);
 801:         }
 802:         return $this->_areas[$code];
 803:     }
 804: 
 805:     /**
 806:      * Retrieve application store object
 807:      *
 808:      * @param null|string|bool|int|Mage_Core_Model_Store $id
 809:      * @return Mage_Core_Model_Store
 810:      * @throws Mage_Core_Model_Store_Exception
 811:      */
 812:     public function getStore($id = null)
 813:     {
 814:         if (!Mage::isInstalled() || $this->getUpdateMode()) {
 815:             return $this->_getDefaultStore();
 816:         }
 817: 
 818:         if ($id === true && $this->isSingleStoreMode()) {
 819:             return $this->_store;
 820:         }
 821: 
 822:         if (!isset($id) || ''===$id || $id === true) {
 823:             $id = $this->_currentStore;
 824:         }
 825:         if ($id instanceof Mage_Core_Model_Store) {
 826:             return $id;
 827:         }
 828:         if (!isset($id)) {
 829:             $this->throwStoreException();
 830:         }
 831: 
 832:         if (empty($this->_stores[$id])) {
 833:             $store = Mage::getModel('core/store');
 834:             /* @var $store Mage_Core_Model_Store */
 835:             if (is_numeric($id)) {
 836:                 $store->load($id);
 837:             } elseif (is_string($id)) {
 838:                 $store->load($id, 'code');
 839:             }
 840: 
 841:             if (!$store->getCode()) {
 842:                 $this->throwStoreException();
 843:             }
 844:             $this->_stores[$store->getStoreId()] = $store;
 845:             $this->_stores[$store->getCode()] = $store;
 846:         }
 847:         return $this->_stores[$id];
 848:     }
 849: 
 850:     /**
 851:      * Retrieve application store object without Store_Exception
 852:      *
 853:      * @param string|int|Mage_Core_Model_Store $id
 854:      * @return Mage_Core_Model_Store
 855:      */
 856:     public function getSafeStore($id = null)
 857:     {
 858:         try {
 859:             return $this->getStore($id);
 860:         }
 861:         catch (Exception $e) {
 862:             if ($this->_currentStore) {
 863:                 $this->getRequest()->setActionName('noRoute');
 864:                 return new Varien_Object();
 865:             }
 866:             else {
 867:                 Mage::throwException(Mage::helper('core')->__('Requested invalid store "%s"', $id));
 868:             }
 869:         }
 870:     }
 871: 
 872:     /**
 873:      * Retrieve stores array
 874:      *
 875:      * @param bool $withDefault
 876:      * @param bool $codeKey
 877:      * @return array
 878:      */
 879:     public function getStores($withDefault = false, $codeKey = false)
 880:     {
 881:         $stores = array();
 882:         foreach ($this->_stores as $store) {
 883:             if (!$withDefault && $store->getId() == 0) {
 884:                 continue;
 885:             }
 886:             if ($codeKey) {
 887:                 $stores[$store->getCode()] = $store;
 888:             }
 889:             else {
 890:                 $stores[$store->getId()] = $store;
 891:             }
 892:         }
 893: 
 894:         return $stores;
 895:     }
 896: 
 897:     protected function _getDefaultStore()
 898:     {
 899:         if (empty($this->_store)) {
 900:             $this->_store = Mage::getModel('core/store')
 901:                 ->setId(self::DISTRO_STORE_ID)
 902:                 ->setCode(self::DISTRO_STORE_CODE);
 903:         }
 904:         return $this->_store;
 905:     }
 906: 
 907:     /**
 908:      * Retrieve default store for default group and website
 909:      *
 910:      * @return Mage_Core_Model_Store
 911:      */
 912:     public function getDefaultStoreView()
 913:     {
 914:         foreach ($this->getWebsites() as $_website) {
 915:             if ($_website->getIsDefault()) {
 916:                 $_defaultStore = $this->getGroup($_website->getDefaultGroupId())->getDefaultStore();
 917:                 if ($_defaultStore) {
 918:                     return $_defaultStore;
 919:                 }
 920:             }
 921:         }
 922:         return null;
 923:     }
 924: 
 925:     public function getDistroLocaleCode()
 926:     {
 927:         return self::DISTRO_LOCALE_CODE;
 928:     }
 929: 
 930:     /**
 931:      * Retrieve application website object
 932:      *
 933:      * @return Mage_Core_Model_Website
 934:      */
 935:     public function getWebsite($id=null)
 936:     {
 937:         if (is_null($id)) {
 938:             $id = $this->getStore()->getWebsiteId();
 939:         } elseif ($id instanceof Mage_Core_Model_Website) {
 940:             return $id;
 941:         } elseif ($id === true) {
 942:             return $this->_website;
 943:         }
 944: 
 945:         if (empty($this->_websites[$id])) {
 946:             $website = Mage::getModel('core/website');
 947:             if (is_numeric($id)) {
 948:                 $website->load($id);
 949:                 if (!$website->hasWebsiteId()) {
 950:                     throw Mage::exception('Mage_Core', 'Invalid website id requested.');
 951:                 }
 952:             } elseif (is_string($id)) {
 953:                 $websiteConfig = $this->_config->getNode('websites/'.$id);
 954:                 if (!$websiteConfig) {
 955:                     throw Mage::exception('Mage_Core', 'Invalid website code requested: '.$id);
 956:                 }
 957:                 $website->loadConfig($id);
 958:             }
 959:             $this->_websites[$website->getWebsiteId()] = $website;
 960:             $this->_websites[$website->getCode()] = $website;
 961:         }
 962:         return $this->_websites[$id];
 963:     }
 964: 
 965:     public function getWebsites($withDefault = false, $codeKey = false)
 966:     {
 967:         $websites = array();
 968:         if (is_array($this->_websites)) {
 969:             foreach ($this->_websites as $website) {
 970:                 if (!$withDefault && $website->getId() == 0) {
 971:                     continue;
 972:                 }
 973:                 if ($codeKey) {
 974:                     $websites[$website->getCode()] = $website;
 975:                 }
 976:                 else {
 977:                     $websites[$website->getId()] = $website;
 978:                 }
 979:             }
 980:         }
 981: 
 982:         return $websites;
 983:     }
 984: 
 985:     /**
 986:      * Retrieve application store group object
 987:      *
 988:      * @return Mage_Core_Model_Store_Group
 989:      */
 990:     public function getGroup($id=null)
 991:     {
 992:         if (is_null($id)) {
 993:             $id = $this->getStore()->getGroup()->getId();
 994:         } elseif ($id instanceof Mage_Core_Model_Store_Group) {
 995:             return $id;
 996:         }
 997:         if (empty($this->_groups[$id])) {
 998:             $group = Mage::getModel('core/store_group');
 999:             if (is_numeric($id)) {
1000:                 $group->load($id);
1001:                 if (!$group->hasGroupId()) {
1002:                     throw Mage::exception('Mage_Core', 'Invalid store group id requested.');
1003:                 }
1004:             }
1005:             $this->_groups[$group->getGroupId()] = $group;
1006:         }
1007:         return $this->_groups[$id];
1008:     }
1009: 
1010:     /**
1011:      * Retrieve application locale object
1012:      *
1013:      * @return Mage_Core_Model_Locale
1014:      */
1015:     public function getLocale()
1016:     {
1017:         if (!$this->_locale) {
1018:             $this->_locale = Mage::getSingleton('core/locale');
1019:         }
1020:         return $this->_locale;
1021:     }
1022: 
1023:     /**
1024:      * Retrive layout object
1025:      *
1026:      * @return Mage_Core_Model_Layout
1027:      */
1028:     public function getLayout()
1029:     {
1030:         if (!$this->_layout) {
1031:             if ($this->getFrontController()->getAction()) {
1032:                 $this->_layout = $this->getFrontController()->getAction()->getLayout();
1033:             } else {
1034:                 $this->_layout = Mage::getSingleton('core/layout');
1035:             }
1036:         }
1037:         return $this->_layout;
1038:     }
1039: 
1040:     /**
1041:      * Retrieve translate object
1042:      *
1043:      * @return Mage_Core_Model_Translate
1044:      */
1045:     public function getTranslator()
1046:     {
1047:         if (!$this->_translator) {
1048:             $this->_translator = Mage::getSingleton('core/translate');
1049:         }
1050:         return $this->_translator;
1051:     }
1052: 
1053:     /**
1054:      * Retrieve helper object
1055:      *
1056:      * @param string $name
1057:      * @return Mage_Core_Helper_Abstract
1058:      */
1059:     public function getHelper($name)
1060:     {
1061:         return Mage::helper($name);
1062:     }
1063: 
1064:     /**
1065:      * Retrieve application base currency code
1066:      *
1067:      * @return string
1068:      */
1069:     public function getBaseCurrencyCode()
1070:     {
1071:         //return Mage::getStoreConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE, 0);
1072:         return (string) Mage::app()->getConfig()
1073:             ->getNode('default/' . Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE);
1074:     }
1075: 
1076:     /**
1077:      * Retrieve configuration object
1078:      *
1079:      * @return Mage_Core_Model_Config
1080:      */
1081:     public function getConfig()
1082:     {
1083:         return $this->_config;
1084:     }
1085: 
1086:     /**
1087:      * Retrieve front controller object
1088:      *
1089:      * @return Mage_Core_Controller_Varien_Front
1090:      */
1091:     public function getFrontController()
1092:     {
1093:         if (!$this->_frontController) {
1094:             $this->_initFrontController();
1095:         }
1096: 
1097:         return $this->_frontController;
1098:     }
1099: 
1100:     /**
1101:      * Get core cache model
1102:      *
1103:      * @return Mage_Core_Model_Cache
1104:      */
1105:     public function getCacheInstance()
1106:     {
1107:         if (!$this->_cache) {
1108:             $this->_initCache();
1109:         }
1110:         return $this->_cache;
1111:     }
1112: 
1113:     /**
1114:      * Retrieve cache object
1115:      *
1116:      * @return Zend_Cache_Core
1117:      */
1118:     public function getCache()
1119:     {
1120:         if (!$this->_cache) {
1121:             $this->_initCache();
1122:         }
1123:         return $this->_cache->getFrontend();
1124:     }
1125: 
1126:     /**
1127:      * Loading cache data
1128:      *
1129:      * @param   string $id
1130:      * @return  mixed
1131:      */
1132:     public function loadCache($id)
1133:     {
1134:         return $this->_cache->load($id);
1135:     }
1136: 
1137:     /**
1138:      * Saving cache data
1139:      *
1140:      * @param   mixed $data
1141:      * @param   string $id
1142:      * @param   array $tags
1143:      * @return  Mage_Core_Model_App
1144:      */
1145:     public function saveCache($data, $id, $tags=array(), $lifeTime=false)
1146:     {
1147:         $this->_cache->save($data, $id, $tags, $lifeTime);
1148:         return $this;
1149:     }
1150: 
1151:     /**
1152:      * Remove cache
1153:      *
1154:      * @param   string $id
1155:      * @return  Mage_Core_Model_App
1156:      */
1157:     public function removeCache($id)
1158:     {
1159:         $this->_cache->remove($id);
1160:         return $this;
1161:     }
1162: 
1163:     /**
1164:      * Cleaning cache
1165:      *
1166:      * @param   array $tags
1167:      * @return  Mage_Core_Model_App
1168:      */
1169:     public function cleanCache($tags=array())
1170:     {
1171:         $this->_cache->clean($tags);
1172:         Mage::dispatchEvent('application_clean_cache', array('tags' => $tags));
1173:         return $this;
1174:     }
1175: 
1176:     /**
1177:     * Check whether to use cache for specific component
1178:     *
1179:     * @return boolean
1180:     */
1181:     public function useCache($type=null)
1182:     {
1183:         return $this->_cache->canUse($type);
1184:     }
1185: 
1186:     /**
1187:      * Save cache usage settings
1188:      *
1189:      * @param array $data
1190:      * @return Mage_Core_Model_App
1191:      */
1192:     public function saveUseCache($data)
1193:     {
1194:         $this->_cache->saveOptions($data);
1195:         return $this;
1196:     }
1197: 
1198:     /**
1199:      * Deletes all session files
1200:      *
1201:      */
1202:     public function cleanAllSessions()
1203:     {
1204:         if (session_module_name()=='files') {
1205:             $dir = session_save_path();
1206:             mageDelTree($dir);
1207:         }
1208:         return $this;
1209:     }
1210: 
1211:     /**
1212:      * Retrieve request object
1213:      *
1214:      * @return Mage_Core_Controller_Request_Http
1215:      */
1216:     public function getRequest()
1217:     {
1218:         if (empty($this->_request)) {
1219:             $this->_request = new Mage_Core_Controller_Request_Http();
1220:         }
1221:         return $this->_request;
1222:     }
1223: 
1224:     /**
1225:      * Request setter
1226:      *
1227:      * @param Mage_Core_Controller_Request_Http $request
1228:      * @return Mage_Core_Model_App
1229:      */
1230:     public function setRequest(Mage_Core_Controller_Request_Http $request)
1231:     {
1232:         $this->_request = $request;
1233:         return $this;
1234:     }
1235: 
1236:     /**
1237:      * Retrieve response object
1238:      *
1239:      * @return Zend_Controller_Response_Http
1240:      */
1241:     public function getResponse()
1242:     {
1243:         if (empty($this->_response)) {
1244:             $this->_response = new Mage_Core_Controller_Response_Http();
1245:             $this->_response->headersSentThrowsException = Mage::$headersSentThrowsException;
1246:             $this->_response->setHeader("Content-Type", "text/html; charset=UTF-8");
1247:         }
1248:         return $this->_response;
1249:     }
1250: 
1251:     /**
1252:      * Response setter
1253:      *
1254:      * @param Mage_Core_Controller_Response_Http $response
1255:      * @return Mage_Core_Model_App
1256:      */
1257:     public function setResponse(Mage_Core_Controller_Response_Http $response)
1258:     {
1259:         $this->_response = $response;
1260:         return $this;
1261:     }
1262: 
1263:     public function addEventArea($area)
1264:     {
1265:         if (!isset($this->_events[$area])) {
1266:             $this->_events[$area] = array();
1267:         }
1268:         return $this;
1269:     }
1270: 
1271:     public function dispatchEvent($eventName, $args)
1272:     {
1273:         foreach ($this->_events as $area=>$events) {
1274:             if (!isset($events[$eventName])) {
1275:                 $eventConfig = $this->getConfig()->getEventConfig($area, $eventName);
1276:                 if (!$eventConfig) {
1277:                     $this->_events[$area][$eventName] = false;
1278:                     continue;
1279:                 }
1280:                 $observers = array();
1281:                 foreach ($eventConfig->observers->children() as $obsName=>$obsConfig) {
1282:                     $observers[$obsName] = array(
1283:                         'type'  => (string)$obsConfig->type,
1284:                         'model' => $obsConfig->class ? (string)$obsConfig->class : $obsConfig->getClassName(),
1285:                         'method'=> (string)$obsConfig->method,
1286:                         'args'  => (array)$obsConfig->args,
1287:                     );
1288:                 }
1289:                 $events[$eventName]['observers'] = $observers;
1290:                 $this->_events[$area][$eventName]['observers'] = $observers;
1291:             }
1292:             if (false===$events[$eventName]) {
1293:                 continue;
1294:             } else {
1295:                 $event = new Varien_Event($args);
1296:                 $event->setName($eventName);
1297:                 $observer = new Varien_Event_Observer();
1298:             }
1299: 
1300:             foreach ($events[$eventName]['observers'] as $obsName=>$obs) {
1301:                 $observer->setData(array('event'=>$event));
1302:                 Varien_Profiler::start('OBSERVER: '.$obsName);
1303:                 switch ($obs['type']) {
1304:                     case 'disabled':
1305:                         break;
1306:                     case 'object':
1307:                     case 'model':
1308:                         $method = $obs['method'];
1309:                         $observer->addData($args);
1310:                         $object = Mage::getModel($obs['model']);
1311:                         $this->_callObserverMethod($object, $method, $observer);
1312:                         break;
1313:                     default:
1314:                         $method = $obs['method'];
1315:                         $observer->addData($args);
1316:                         $object = Mage::getSingleton($obs['model']);
1317:                         $this->_callObserverMethod($object, $method, $observer);
1318:                         break;
1319:                 }
1320:                 Varien_Profiler::stop('OBSERVER: '.$obsName);
1321:             }
1322:         }
1323:         return $this;
1324:     }
1325: 
1326:     /**
1327:      * Performs non-existent observer method calls protection
1328:      *
1329:      * @param object $object
1330:      * @param string $method
1331:      * @param Varien_Event_Observer $observer
1332:      * @return Mage_Core_Model_App
1333:      * @throws Mage_Core_Exception
1334:      */
1335:     protected function _callObserverMethod($object, $method, $observer)
1336:     {
1337:         if (method_exists($object, $method)) {
1338:             $object->$method($observer);
1339:         } elseif (Mage::getIsDeveloperMode()) {
1340:             Mage::throwException('Method "'.$method.'" is not defined in "'.get_class($object).'"');
1341:         }
1342:         return $this;
1343:     }
1344: 
1345:     public function setUpdateMode($value)
1346:     {
1347:         $this->_updateMode = $value;
1348:     }
1349: 
1350:     public function getUpdateMode()
1351:     {
1352:         return $this->_updateMode;
1353:     }
1354: 
1355:     public function throwStoreException()
1356:     {
1357:         throw new Mage_Core_Model_Store_Exception('');
1358:     }
1359: 
1360:     /**
1361:      * Set use session var instead of SID for URL
1362:      *
1363:      * @param bool $var
1364:      * @return Mage_Core_Model_App
1365:      */
1366:     public function setUseSessionVar($var)
1367:     {
1368:         $this->_useSessionVar = (bool)$var;
1369:         return $this;
1370:     }
1371: 
1372:     /**
1373:      * Retrieve use flag session var instead of SID for URL
1374:      *
1375:      * @return bool
1376:      */
1377:     public function getUseSessionVar()
1378:     {
1379:         return $this->_useSessionVar;
1380:     }
1381: 
1382:     /**
1383:      * Get either default or any store view
1384:      *
1385:      * @return Mage_Core_Model_Store
1386:      */
1387:     public function getAnyStoreView()
1388:     {
1389:         $store = $this->getDefaultStoreView();
1390:         if ($store) {
1391:             return $store;
1392:         }
1393:         foreach ($this->getStores() as $store) {
1394:             return $store;
1395:         }
1396:     }
1397: 
1398:     /**
1399:      * Set Use session in URL flag
1400:      *
1401:      * @param bool $flag
1402:      * @return Mage_Core_Model_App
1403:      */
1404:     public function setUseSessionInUrl($flag = true)
1405:     {
1406:         $this->_useSessionInUrl = (bool)$flag;
1407:         return $this;
1408:     }
1409: 
1410:     /**
1411:      * Retrieve use session in URL flag
1412:      *
1413:      * @return bool
1414:      */
1415:     public function getUseSessionInUrl()
1416:     {
1417:         return $this->_useSessionInUrl;
1418:     }
1419: 
1420:     /**
1421:      * Allow or disallow single store mode
1422:      *
1423:      * @param bool $value
1424:      * @return Mage_Core_Model_App
1425:      */
1426:     public function setIsSingleStoreModeAllowed($value)
1427:     {
1428:         $this->_isSingleStoreAllowed = (bool)$value;
1429:         return $this;
1430:     }
1431: 
1432:     /**
1433:      * Prepare array of store groups
1434:      * can be filtered to contain default store group or not by $withDefault flag
1435:      * depending on flag $codeKey array keys can be group id or group code
1436:      *
1437:      * @param bool $withDefault
1438:      * @param bool $codeKey
1439:      * @return array
1440:      */
1441:     public function getGroups($withDefault = false, $codeKey = false)
1442:     {
1443:         $groups = array();
1444:         if (is_array($this->_groups)) {
1445:             foreach ($this->_groups as $group) {
1446:                 if (!$withDefault && $group->getId() == 0) {
1447:                     continue;
1448:                 }
1449:                 if ($codeKey) {
1450:                     $groups[$group->getCode()] = $group;
1451:                 }
1452:                 else {
1453:                     $groups[$group->getId()] = $group;
1454:                 }
1455:             }
1456:         }
1457: 
1458:         return $groups;
1459:     }
1460: 
1461: 
1462: 
1463: 
1464:     /**
1465:      * Retrieve application installation flag
1466:      *
1467:      * @deprecated since 1.2
1468:      * @return bool
1469:      */
1470:     public function isInstalled()
1471:     {
1472:         return Mage::isInstalled();
1473:     }
1474: 
1475:     /**
1476:      * Generate cache tags from cache id
1477:      *
1478:      * @deprecated after 1.4.0.0-alpha3, functionality implemented in Mage_Core_Model_Cache
1479:      * @param   string $id
1480:      * @param   array $tags
1481:      * @return  array
1482:      */
1483:     protected function _getCacheTags($tags=array())
1484:     {
1485:         foreach ($tags as $index=>$value) {
1486:             $tags[$index] = $this->_getCacheId($value);
1487:         }
1488:         return $tags;
1489:     }
1490: 
1491:     /**
1492:      * Get file name with cache configuration settings
1493:      *
1494:      * @deprecated after 1.4.0.0-alpha3, functionality implemented in Mage_Core_Model_Cache
1495:      * @return string
1496:      */
1497:     public function getUseCacheFilename()
1498:     {
1499:         return $this->_config->getOptions()->getEtcDir().DS.'use_cache.ser';
1500:     }
1501: 
1502:     /**
1503:      * Generate cache id with application specific data
1504:      *
1505:      * @deprecated after 1.4.0.0-alpha3, functionality implemented in Mage_Core_Model_Cache
1506:      * @param   string $id
1507:      * @return  string
1508:      */
1509:     protected function _getCacheId($id=null)
1510:     {
1511:         if ($id) {
1512:             $id = $this->prepareCacheId($id);
1513:         }
1514:         return $id;
1515:     }
1516: 
1517:     /**
1518:      * Prepare identifier which can be used as cache id or cache tag
1519:      *
1520:      * @deprecated after 1.4.0.0-alpha3, functionality implemented in Mage_Core_Model_Cache
1521:      * @param   string $id
1522:      * @return  string
1523:      */
1524:     public function prepareCacheId($id)
1525:     {
1526:         $id = strtoupper($id);
1527:         $id = preg_replace('/([^a-zA-Z0-9_]{1,1})/', '_', $id);
1528:         return $id;
1529:     }
1530: 
1531:     /**
1532:      * Get is cache locked
1533:      *
1534:      * @return bool
1535:      */
1536:     public function getIsCacheLocked()
1537:     {
1538:         return (bool)$this->_isCacheLocked;
1539:     }
1540: 
1541:     /**
1542:      *  Unset website by id from app cache
1543:      *
1544:      * @param null|bool|int|string|Mage_Core_Model_Website $id
1545:      * @return void
1546:      */
1547:     public function clearWebsiteCache($id = null)
1548:     {
1549:         if (is_null($id)) {
1550:             $id = $this->getStore()->getWebsiteId();
1551:         } elseif ($id instanceof Mage_Core_Model_Website) {
1552:             $id = $id->getId();
1553:         } elseif ($id === true) {
1554:             $id = $this->_website->getId();
1555:         }
1556: 
1557:         if (!empty($this->_websites[$id])) {
1558:             $website = $this->_websites[$id];
1559: 
1560:             unset($this->_websites[$website->getWebsiteId()]);
1561:             unset($this->_websites[$website->getCode()]);
1562:         }
1563:     }
1564: }
1565: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0