Mage_Core_Model_App Class Reference

List of all members.

Public Member Functions

 __construct ()
 init ($code, $type=null, $options=array())
 getCookie ()
 reinitStores ()
 isSingleStoreMode ()
 setCurrentStore ($store)
 setErrorHandler ($handler)
 loadArea ($code)
 loadAreaPart ($area, $part)
 getArea ($code)
 getStore ($id=null)
 getSafeStore ($id=null)
 getStores ($withDefault=false, $codeKey=false)
 getDefaultStoreView ()
 getDistroLocaleCode ()
 getWebsite ($id=null)
 getWebsites ($withDefault=false, $codeKey=false)
 getGroup ($id=null)
 getLocale ()
 getLayout ()
 getTranslator ()
 getHelper ($name)
 getBaseCurrencyCode ()
 getConfig ()
 getFrontController ()
 isInstalled ()
 prepareCacheId ($id)
 getCache ()
 loadCache ($id)
 saveCache ($data, $id, $tags=array(), $lifeTime=false)
 removeCache ($id)
 cleanCache ($tags=array())
 getUseCacheFilename ()
 useCache ($type=null)
 saveUseCache ($data)
 cleanAllSessions ()
 getRequest ()
 getResponse ()
 addEventArea ($area)
 dispatchEvent ($eventName, $args)
 setUpdateMode ($value)
 getUpdateMode ()
 throwStoreException ()
 setUseSessionVar ($var)
 getUseSessionVar ()
 getAnyStoreView ()
 setUseSessionInUrl ($flag=true)
 getUseSessionInUrl ()
 setIsSingleStoreModeAllowed ($value)

Public Attributes

const XML_PATH_INSTALL_DATE = 'global/install/date'
const DEFAULT_ERROR_HANDLER = 'mageCoreErrorHandler'
const DISTRO_LOCALE_CODE = 'en_US'
const CACHE_TAG = 'MAGE'
const DISTRO_STORE_ID = 1
const DISTRO_STORE_CODE = 'default'
const ADMIN_STORE_ID = 0

Protected Member Functions

 _checkGetStore ($type)
 _checkCookieStore ($type)
 _initStores ()
 _getStoreByGroup ($group)
 _getStoreByWebsite ($website)
 _initFrontController ()
 _getDefaultStore ()
 _getCacheId ($id=null)
 _getCacheTags ($tags=array())

Protected Attributes

 $_areas = array()
 $_store
 $_website
 $_locale
 $_translator
 $_design
 $_layout
 $_config
 $_frontController
 $_cache
 $_helpers = array()
 $_useCache
 $_websites = array()
 $_groups = array()
 $_stores = array()
 $_isSingleStore
 $_isSingleStoreAllowed = true
 $_currentStore
 $_request
 $_response
 $_events = array()
 $_updateMode = false
 $_useSessionInUrl = true
 $_useSessionVar = false
 $_isCacheLocked = null


Detailed Description

Definition at line 36 of file App.php.


Constructor & Destructor Documentation

__construct (  ) 

Constructor

Definition at line 242 of file App.php.

00242 {}


Member Function Documentation

_checkCookieStore ( type  )  [protected]

Check cookie store

Parameters:
string $type
Returns:
Mage_Core_Model_App

Definition at line 364 of file App.php.

00365     {
00366         if (!$this->getCookie()->get()) {
00367             return $this;
00368         }
00369 
00370         $store  = $this->getCookie()->get('store');
00371         if ($store && isset($this->_stores[$store])
00372             && $this->_stores[$store]->getId()
00373             && $this->_stores[$store]->getIsActive()) {
00374             if ($type == 'website'
00375                 && $this->_stores[$store]->getWebsiteId() == $this->_stores[$this->_currentStore]->getWebsiteId()) {
00376                 $this->_currentStore = $store;
00377             }
00378             if ($type == 'group'
00379                 && $this->_stores[$store]->getGroupId() == $this->_stores[$this->_currentStore]->getGroupId()) {
00380                 $this->_currentStore = $store;
00381             }
00382             if ($type == 'store') {
00383                 $this->_currentStore = $store;
00384             }
00385         }
00386         return $this;
00387     }

_checkGetStore ( type  )  [protected]

Check get store

Returns:
Mage_Core_Model_App

Todo:
check XML_PATH_STORE_IN_URL

prevent running a store from another website or store group, if website or store group was specified explicitly in Mage.run()

Definition at line 313 of file App.php.

00314     {
00315         if (empty($_GET)) {
00316             return $this;
00317         }
00318 
00319         /**
00320          * @todo check XML_PATH_STORE_IN_URL
00321          */
00322 
00323         if (!isset($_GET['___store'])) {
00324             return $this;
00325         }
00326 
00327         $store = $_GET['___store'];
00328         if (!isset($this->_stores[$store])) {
00329             return $this;
00330         }
00331 
00332         $storeObj = $this->_stores[$store];
00333         if (!$storeObj->getId() || !$storeObj->getIsActive()) {
00334             return $this;
00335         }
00336 
00337         /**
00338          * prevent running a store from another website or store group,
00339          * if website or store group was specified explicitly in Mage::run()
00340          */
00341         $curStoreObj = $this->_stores[$this->_currentStore];
00342         if ($type == 'website' && $storeObj->getWebsiteId() == $curStoreObj->getWebsiteId()) {
00343             $this->_currentStore = $store;
00344         }
00345         elseif ($type == 'group' && $storeObj->getGroupId() == $curStoreObj->getGroupId()) {
00346             $this->_currentStore = $store;
00347         }
00348         elseif ($type == 'store') {
00349             $this->_currentStore = $store;
00350         }
00351 
00352         if ($this->_currentStore == $store) {
00353             $this->getCookie()->set('store', $this->_currentStore, true);
00354         }
00355         return $this;
00356     }

_getCacheId ( id = null  )  [protected]

Generate cache id with application specific data

Parameters:
string $id
Returns:
string

Definition at line 912 of file App.php.

00913     {
00914         if ($id) {
00915             $id = $this->prepareCacheId($id);
00916         }
00917         return $id;
00918     }

_getCacheTags ( tags = array()  )  [protected]

Generate cache tags from cache id

Parameters:
string $id
array $tags
Returns:
array

Definition at line 940 of file App.php.

00941     {
00942         foreach ($tags as $index=>$value) {
00943             $tags[$index] = $this->_getCacheId($value);
00944         }
00945         return $tags;
00946     }

_getDefaultStore (  )  [protected]

Definition at line 688 of file App.php.

00689     {
00690         if (empty($this->_store)) {
00691             $this->_store = Mage::getModel('core/store')
00692                 ->setId(self::DISTRO_STORE_ID)
00693                 ->setCode(self::DISTRO_STORE_CODE);
00694         }
00695         return $this->_store;
00696     }

_getStoreByGroup ( group  )  [protected]

Retrive store code or null by store group

Parameters:
int $group
Returns:
string|null

Definition at line 492 of file App.php.

00493     {
00494         if (!isset($this->_groups[$group])) {
00495             return null;
00496         }
00497         if (!$this->_groups[$group]->getDefaultStoreId()) {
00498             return null;
00499         }
00500         return $this->_stores[$this->_groups[$group]->getDefaultStoreId()]->getCode();
00501     }

_getStoreByWebsite ( website  )  [protected]

Retrive store code or null by website

Parameters:
int|string $website
Returns:
string|null

Definition at line 509 of file App.php.

00510     {
00511         if (!isset($this->_websites[$website])) {
00512             return null;
00513         }
00514         if (!$this->_websites[$website]->getDefaultGroupId()) {
00515             return null;
00516         }
00517         return $this->_getStoreByGroup($this->_websites[$website]->getDefaultGroupId());
00518     }

_initFrontController (  )  [protected]

Initialize application front controller

Returns:
Mage_Core_Model_App

Definition at line 537 of file App.php.

00538     {
00539         $this->_frontController = new Mage_Core_Controller_Varien_Front();
00540         Mage::register('controller', $this->_frontController);
00541         Varien_Profiler::start('mage::app::init_front_controller');
00542         $this->_frontController->init();
00543         Varien_Profiler::stop('mage::app::init_front_controller');
00544         return $this;
00545     }

_initStores (  )  [protected]

Init store, group and website collections

Definition at line 398 of file App.php.

00399     {
00400         $this->_stores   = array();
00401         $this->_groups   = array();
00402         $this->_website  = null;
00403         $this->_websites = array();
00404 
00405         $websiteCollection = Mage::getModel('core/website')->getCollection()
00406             ->initCache($this->getCache(), 'app', array(Mage_Core_Model_Website::CACHE_TAG))
00407             ->setLoadDefault(true);
00408         $groupCollection = Mage::getModel('core/store_group')->getCollection()
00409             ->initCache($this->getCache(), 'app', array(Mage_Core_Model_Store_Group::CACHE_TAG))
00410             ->setLoadDefault(true);
00411         $storeCollection = Mage::getModel('core/store')->getCollection()
00412             ->initCache($this->getCache(), 'app', array(Mage_Core_Model_Store::CACHE_TAG))
00413             ->setLoadDefault(true);
00414 
00415         $this->_isSingleStore = false;
00416         if ($this->_isSingleStoreAllowed) {
00417             $this->_isSingleStore = $storeCollection->count() < 3;
00418         }
00419 
00420         $websiteStores = array();
00421         $websiteGroups = array();
00422         $groupStores   = array();
00423 
00424         foreach ($storeCollection as $store) {
00425             /* @var $store Mage_Core_Model_Store */
00426             $store->initConfigCache();
00427             $store->setWebsite($websiteCollection->getItemById($store->getWebsiteId()));
00428             $store->setGroup($groupCollection->getItemById($store->getGroupId()));
00429 
00430             $this->_stores[$store->getId()] = $store;
00431             $this->_stores[$store->getCode()] = $store;
00432 
00433             $websiteStores[$store->getWebsiteId()][$store->getId()] = $store;
00434             $groupStores[$store->getGroupId()][$store->getId()] = $store;
00435 
00436             if (is_null($this->_store) && $store->getId()) {
00437                 $this->_store = $store;
00438             }
00439         }
00440 
00441         foreach ($groupCollection as $group) {
00442             /* @var $group Mage_Core_Model_Store_Group */
00443             if (!isset($groupStores[$group->getId()])) {
00444                 $groupStores[$group->getId()] = array();
00445             }
00446             $group->setStores($groupStores[$group->getId()]);
00447             $group->setWebsite($websiteCollection->getItemById($group->getWebsiteId()));
00448 
00449             $websiteGroups[$group->getWebsiteId()][$group->getId()] = $group;
00450 
00451             $this->_groups[$group->getId()] = $group;
00452         }
00453 
00454         foreach ($websiteCollection as $website) {
00455             /* @var $website Mage_Core_Model_Website */
00456             if (!isset($websiteGroups[$website->getId()])) {
00457                 $websiteGroups[$website->getId()] = array();
00458             }
00459             if (!isset($websiteStores[$website->getId()])) {
00460                 $websiteStores[$website->getId()] = array();
00461             }
00462             if ($website->getIsDefault()) {
00463                 $this->_website = $website;
00464             }
00465             $website->setGroups($websiteGroups[$website->getId()]);
00466             $website->setStores($websiteStores[$website->getId()]);
00467 
00468             $this->_websites[$website->getId()] = $website;
00469             $this->_websites[$website->getCode()] = $website;
00470         }
00471     }

addEventArea ( area  ) 

Definition at line 1186 of file App.php.

01187     {
01188         if (!isset($this->_events[$area])) {
01189             $this->_events[$area] = array();
01190         }
01191         return $this;
01192     }

cleanAllSessions (  ) 

Deletes all session files

Definition at line 1149 of file App.php.

01150     {
01151         if (session_module_name()=='files') {
01152             $dir = session_save_path();
01153             mageDelTree($dir);
01154         }
01155         return $this;
01156     }

cleanCache ( tags = array()  ) 

Cleaning cache

Parameters:
array $tags
Returns:
Mage_Core_Model_App

Clear configuration cache separately

Definition at line 1067 of file App.php.

01068     {
01069         if (!empty($tags)) {
01070             if (!is_array($tags)) {
01071                 $tags = array($tags);
01072             }
01073             $tags = $this->_getCacheTags($tags);
01074             $cacheTag = $this->_getCacheId(Mage_Core_Model_Config::CACHE_TAG);
01075             $this->getCache()->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, $tags);
01076         } else {
01077             $this->getCache()->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array(self::CACHE_TAG));
01078             /**
01079              * Clear configuration cache separately
01080              */
01081             Mage::getConfig()->cleanCache();
01082         }
01083 
01084         Mage::dispatchEvent('application_clean_cache', array('tags' => $tags));
01085         return $this;
01086     }

dispatchEvent ( eventName,
args 
)

Definition at line 1194 of file App.php.

01195     {
01196         foreach ($this->_events as $area=>$events) {
01197             if (!isset($events[$eventName])) {
01198                 $eventConfig = $this->getConfig()->getEventConfig($area, $eventName);
01199                 if (!$eventConfig) {
01200                     $this->_events[$area][$eventName] = false;
01201                     continue;
01202                 }
01203                 $observers = array();
01204                 foreach ($eventConfig->observers->children() as $obsName=>$obsConfig) {
01205                     $observers[$obsName] = array(
01206                         'type' => $obsConfig->type ? (string)$obsConfig->type : 'singleton',
01207                         'model' => $obsConfig->class ? (string)$obsConfig->class : $obsConfig->getClassName(),
01208                         'method' => (string)$obsConfig->method,
01209                         'args' => (array)$obsConfig->args,
01210                     );
01211                 }
01212                 $events[$eventName]['observers'] = $observers;
01213                 $this->_events[$area][$eventName]['observers'] = $observers;
01214             }
01215             if (false===$events[$eventName]) {
01216                 continue;
01217             } else {
01218                 $event = new Varien_Event($args);
01219                 $event->setName($eventName);
01220                 $observer = new Varien_Event_Observer();
01221             }
01222 
01223             foreach ($events[$eventName]['observers'] as $obsName=>$obs) {
01224                 $observer->setData(array('event'=>$event));
01225                 Varien_Profiler::start('OBSERVER: '.$obsName);
01226                 switch ($obs['type']) {
01227                     case 'singleton':
01228                         $method = $obs['method'];
01229                         $observer->addData($args);
01230                         $object = Mage::getSingleton($obs['model']);
01231                         $object->$method($observer);
01232                         break;
01233 
01234                     case 'object': case 'model':
01235                         $method = $obs['method'];
01236                         $observer->addData($args);
01237                         $object = Mage::getModel($obs['model']);
01238                         $object->$method($observer);
01239                         break;
01240                 }
01241                 Varien_Profiler::stop('OBSERVER: '.$obsName);
01242             }
01243         }
01244         return $this;
01245     }

getAnyStoreView (  ) 

Get either default or any store view

Returns:
Mage_Core_Model_Store

Definition at line 1289 of file App.php.

01290     {
01291         if ($store = $this->getDefaultStoreView()) {
01292             return $store;
01293         }
01294         foreach ($this->getStores() as $store) {
01295             return $store;
01296         }
01297     }

getArea ( code  ) 

Retrieve application area

Parameters:
string $code
Returns:
Mage_Core_Model_App_Area

Definition at line 590 of file App.php.

00591     {
00592         if (!isset($this->_areas[$code])) {
00593             $this->_areas[$code] = new Mage_Core_Model_App_Area($code, $this);
00594         }
00595         return $this->_areas[$code];
00596     }

getBaseCurrencyCode (  ) 

Retrieve application base currency code

Returns:
string

Definition at line 865 of file App.php.

00866     {
00867         //return Mage::getStoreConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE, 0);
00868         return (string) Mage::app()->getConfig()->getNode('default/'.Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE);
00869     }

getCache (  ) 

Retrieve cache object

Returns:
Zend_Cache_Core

Definition at line 953 of file App.php.

00954     {
00955         if (!$this->_cache) {
00956             $backend = strtolower((string)Mage::getConfig()->getNode('global/cache/backend'));
00957             if (!$cachePrefix = (string)Mage::getConfig()->getNode('global/cache/prefix')) {
00958                 $cachePrefix = md5(Mage::getConfig()->getBaseDir());
00959             }
00960             if (extension_loaded('apc') && ini_get('apc.enabled') && $backend == 'apc') {
00961                 $backend = 'Apc';
00962                 $backendAttributes = array(
00963                     'cache_prefix' => $cachePrefix
00964                 );
00965             } elseif (extension_loaded('eaccelerator') && ini_get('eaccelerator.enable') && $backend=='eaccelerator') {
00966                 $backend = 'Eaccelerator';
00967                 $backendAttributes = array(
00968                     'cache_prefix' => $cachePrefix
00969                 );
00970             } elseif ('memcached' == $backend && extension_loaded('memcache')) {
00971                 $backend = 'Memcached';
00972                 $memcachedConfig = Mage::getConfig()->getNode('global/cache/memcached');
00973                 $backendAttributes = array(
00974                     'compression'               => (bool)$memcachedConfig->compression,
00975                     'cache_dir'                 => (string)$memcachedConfig->cache_dir,
00976                     'hashed_directory_level'    => (string)$memcachedConfig->hashed_directory_level,
00977                     'hashed_directory_umask'    => (string)$memcachedConfig->hashed_directory_umask,
00978                     'file_name_prefix'          => (string)$memcachedConfig->file_name_prefix,
00979                     'servers'                   => array(),
00980                 );
00981                 foreach ($memcachedConfig->servers->children() as $serverConfig) {
00982                     $backendAttributes['servers'][] = array(
00983                         'host'          => (string)$serverConfig->host,
00984                         'port'          => (string)$serverConfig->port,
00985                         'persistent'    => (string)$serverConfig->persistent,
00986                     );
00987                 }
00988             } else {
00989                 $backend = 'File';
00990                 $backendAttributes = array(
00991                     'cache_dir'                 => Mage::getBaseDir('cache'),
00992                     'hashed_directory_level'    => 1,
00993                     'hashed_directory_umask'    => 0777,
00994                     'file_name_prefix'          => 'mage',
00995                 );
00996             }
00997             $lifetime = Mage::getConfig()->getNode('global/cache/lifetime');
00998             if ($lifetime !== false) {
00999                 $lifetime = (int) $lifetime;
01000             }
01001             else {
01002                 $lifetime = 7200;
01003             }
01004             $this->_cache = Zend_Cache::factory('Core', $backend,
01005                 array(
01006                     'caching'                   => true,
01007                     'lifetime'                  => $lifetime,
01008                     'automatic_cleaning_factor' => 0,
01009                 ),
01010                 $backendAttributes
01011             );
01012         }
01013         return $this->_cache;
01014     }

getConfig (  ) 

Retrieve configuration object

Returns:
Mage_Core_Model_Config

Definition at line 876 of file App.php.

00877     {
00878         return $this->_config;
00879     }

getCookie (  ) 

Retrieve cookie object

Returns:
Mage_Core_Model_Cookie

Definition at line 303 of file App.php.

00304     {
00305         return Mage::getSingleton('core/cookie');
00306     }

getDefaultStoreView (  ) 

Retrieve default store for default group and website

Returns:
Mage_Core_Model_Store

Definition at line 703 of file App.php.

00704     {
00705         foreach ($this->getWebsites() as $_website) {
00706             if ($_website->getIsDefault()) {
00707                 if ($_defaultStore = $this->getGroup($_website->getDefaultGroupId())->getDefaultStore()) {
00708                     return $_defaultStore;
00709                 }
00710             }
00711         }
00712         return null;
00713     }

getDistroLocaleCode (  ) 

Definition at line 715 of file App.php.

00716     {
00717         return self::DISTRO_LOCALE_CODE;
00718     }

getFrontController (  ) 

Retrieve front controller object

Returns:
Mage_Core_Controller_Varien_Front

Definition at line 886 of file App.php.

00887     {
00888         if (!$this->_frontController) {
00889             $this->_initFrontController();
00890         }
00891 
00892         return $this->_frontController;
00893     }

getGroup ( id = null  ) 

Retrieve application store group object

Returns:
Mage_Core_Model_Store_Group

Definition at line 781 of file App.php.

00782     {
00783         if (is_null($id)) {
00784             $id = $this->getStore()->getGroup()->getId();
00785         } elseif ($id instanceof Mage_Core_Model_Store_Group) {
00786             return $id;
00787         }
00788         if (empty($this->_groups[$id])) {
00789             $group = Mage::getModel('core/store_group');
00790             if (is_numeric($id)) {
00791                 $group->load($id);
00792                 if (!$group->hasGroupId()) {
00793                     throw Mage::exception('Mage_Core', 'Invalid store group id requested.');
00794                 }
00795             }
00796             $this->_groups[$group->getGroupId()] = $group;
00797         }
00798         return $this->_groups[$id];
00799     }

getHelper ( name  ) 

Retrieve helper object

Parameters:
helper name $name
Returns:
Mage_Core_Helper_Abstract

Definition at line 848 of file App.php.

00849     {
00850         if (strpos($name, '/') === false) {
00851             $name .= '/data';
00852         }
00853         if (!isset($this->_helpers[$name])) {
00854             $class = Mage::getConfig()->getHelperClassName($name);
00855             $this->_helpers[$name] = new $class();
00856         }
00857         return $this->_helpers[$name];
00858     }

getLayout (  ) 

Retrive layout object

Returns:
Mage_Core_Model_Layout

Definition at line 819 of file App.php.

00820     {
00821         if (!$this->_layout) {
00822             $this->_layout = ($this->getFrontController()->getAction()
00823                                     ?  $this->getFrontController()->getAction()->getLayout()
00824                                     :  Mage::getSingleton('core/layout'));
00825         }
00826         return $this->_layout;
00827     }

getLocale (  ) 

Retrieve application locale object

Returns:
Mage_Core_Model_Locale

Definition at line 806 of file App.php.

00807     {
00808         if (!$this->_locale) {
00809             $this->_locale = Mage::getSingleton('core/locale');
00810         }
00811         return $this->_locale;
00812     }

getRequest (  ) 

Retrieve request object

Returns:
Mage_Core_Controller_Request_Http

Definition at line 1163 of file App.php.

01164     {
01165         if (empty($this->_request)) {
01166             $this->_request = new Mage_Core_Controller_Request_Http();
01167         }
01168         return $this->_request;
01169     }

getResponse (  ) 

Retrieve response object

Returns:
Zend_Controller_Response_Http

Definition at line 1176 of file App.php.

01177     {
01178         if (empty($this->_response)) {
01179             $this->_response = new Mage_Core_Controller_Response_Http();
01180             $this->_response->headersSentThrowsException = Mage::$headersSentThrowsException;
01181             $this->_response->setHeader("Content-Type", "text/html; charset=UTF-8");
01182         }
01183         return $this->_response;
01184     }

getSafeStore ( id = null  ) 

Retrieve application store object without Store_Exception

Parameters:
string|int|Mage_Core_Model_Store $id
Returns:
Mage_Core_Model_Store

Definition at line 647 of file App.php.

00648     {
00649         try {
00650             return $this->getStore($id);
00651         }
00652         catch (Exception $e) {
00653             if ($this->_currentStore) {
00654                 $this->getRequest()->setActionName('noRoute');
00655                 return new Varien_Object();
00656             }
00657             else {
00658                 Mage::throwException(Mage::helper('core')->__('Requested invalid store "%s"', $id));
00659             }
00660         }
00661     }

getStore ( id = null  ) 

Retrieve application store object

Returns:
Mage_Core_Model_Store

Definition at line 603 of file App.php.

00604     {
00605         if (!Mage::isInstalled() || $this->getUpdateMode()) {
00606             return $this->_getDefaultStore();
00607         }
00608 
00609         if ($id === true && $this->isSingleStoreMode()) {
00610             return $this->_store;
00611         }
00612 
00613         if (is_null($id) || ''===$id || $id === true) {
00614             $id = $this->_currentStore;
00615         }
00616         if ($id instanceof Mage_Core_Model_Store) {
00617             return $id;
00618         }
00619         if (is_null($id)) {
00620             $this->throwStoreException();
00621         }
00622 
00623         if (empty($this->_stores[$id])) {
00624             $store = Mage::getModel('core/store');
00625             /* @var $store Mage_Core_Model_Store */
00626             if (is_numeric($id)) {
00627                 $store->load($id);
00628             } elseif (is_string($id)) {
00629                 $store->load($id, 'code');
00630             }
00631 
00632             if (!$store->getCode()) {
00633                 $this->throwStoreException();
00634             }
00635             $this->_stores[$store->getStoreId()] = $store;
00636             $this->_stores[$store->getCode()] = $store;
00637         }
00638         return $this->_stores[$id];
00639     }

getStores ( withDefault = false,
codeKey = false 
)

Retrieve stores array

Parameters:
bool $withDefault
bool $codeKey
Returns:
array

Definition at line 670 of file App.php.

00671     {
00672         $stores = array();
00673         foreach ($this->_stores as $store) {
00674             if (!$withDefault && $store->getId() == 0) {
00675                 continue;
00676             }
00677             if ($codeKey) {
00678                 $stores[$store->getCode()] = $store;
00679             }
00680             else {
00681                 $stores[$store->getId()] = $store;
00682             }
00683         }
00684 
00685         return $stores;
00686     }

getTranslator (  ) 

Retrieve translate object

Returns:
Mage_Core_Model_Translate

Definition at line 834 of file App.php.

00835     {
00836         if (!$this->_translator) {
00837             $this->_translator = Mage::getSingleton('core/translate');
00838         }
00839         return $this->_translator;
00840     }

getUpdateMode (  ) 

Definition at line 1252 of file App.php.

01253     {
01254         return $this->_updateMode;
01255     }

getUseCacheFilename (  ) 

Get file name with cache configuration settings

Returns:
string

Definition at line 1093 of file App.php.

01094     {
01095         return Mage::getConfig()->getOptions()->getEtcDir().DS.'use_cache.ser';
01096     }

getUseSessionInUrl (  ) 

Retrieve use session in URL flag

Returns:
bool

Definition at line 1316 of file App.php.

01317     {
01318         return $this->_useSessionInUrl;
01319     }

getUseSessionVar (  ) 

Retrieve use flag session var instead of SID for URL

Returns:
bool

Definition at line 1279 of file App.php.

01280     {
01281         return $this->_useSessionVar;
01282     }

getWebsite ( id = null  ) 

Retrieve application website object

Returns:
Mage_Core_Model_Website

Definition at line 725 of file App.php.

00726     {
00727         if (is_null($id)) {
00728             $id = $this->getStore()->getWebsiteId();
00729         } elseif ($id instanceof Mage_Core_Model_Website) {
00730             return $id;
00731         } elseif ($id === true) {
00732             return $this->_website;
00733         }
00734 
00735         if (empty($this->_websites[$id])) {
00736             $website = Mage::getModel('core/website');
00737             if (is_numeric($id)) {
00738                 $website->load($id);
00739                 if (!$website->hasWebsiteId()) {
00740                     throw Mage::exception('Mage_Core', 'Invalid website id requested.');
00741                 }
00742             } elseif (is_string($id)) {
00743                 $websiteConfig = Mage::getConfig()->getNode('websites/'.$id);
00744                 if (!$websiteConfig) {
00745                     throw Mage::exception('Mage_Core', 'Invalid website code requested: '.$id);
00746                 }
00747                 $website->loadConfig($id);
00748             }
00749             $this->_websites[$website->getWebsiteId()] = $website;
00750             $this->_websites[$website->getCode()] = $website;
00751         }
00752         return $this->_websites[$id];
00753     }

getWebsites ( withDefault = false,
codeKey = false 
)

Definition at line 755 of file App.php.

00756     {
00757         $websites = array();
00758         if (is_array($this->_websites)) {
00759             foreach ($this->_websites as $website) {
00760                 if (!$withDefault && $website->getId() == 0) {
00761                     continue;
00762                 }
00763                 if ($codeKey) {
00764                     $websites[$website->getCode()] = $website;
00765                 }
00766                 else {
00767                     $websites[$website->getId()] = $website;
00768                 }
00769             }
00770         }
00771 
00772         return $websites;
00773     }

init ( code,
type = null,
options = array() 
)

Initialize application

Parameters:
string|array $code
string $type
string $etcDir
Returns:
Mage_Core_Model_App

Definition at line 252 of file App.php.

00253     {
00254         $this->setErrorHandler(self::DEFAULT_ERROR_HANDLER);
00255         date_default_timezone_set(Mage_Core_Model_Locale::DEFAULT_TIMEZONE);
00256 
00257         if (is_string($options)) {
00258             $options = array('etc_dir'=>$options);
00259         }
00260 
00261         Varien_Profiler::start('mage::app::init::config');
00262         $this->_config = Mage::getConfig();
00263         $this->_config->init($options);
00264         Varien_Profiler::stop('mage::app::init::config');
00265 
00266         if (Mage::isInstalled($options)) {
00267             Varien_Profiler::start('mage::app::init::stores');
00268             $this->_initStores();
00269             Varien_Profiler::stop('mage::app::init::stores');
00270 
00271             if (empty($code) && !is_null($this->_website)) {
00272                 $code = $this->_website->getCode();
00273                 $type = 'website';
00274             }
00275             switch ($type) {
00276                 case 'store':
00277                     $this->_currentStore = $code;
00278                     break;
00279                 case 'group':
00280                     $this->_currentStore = $this->_getStoreByGroup($code);
00281                     break;
00282                 case 'website':
00283                     $this->_currentStore = $this->_getStoreByWebsite($code);
00284                     break;
00285                 default:
00286                     $this->throwStoreException();
00287             }
00288 
00289             if (!empty($this->_currentStore)) {
00290                 $this->_checkCookieStore($type);
00291                 $this->_checkGetStore($type);
00292             }
00293             $this->getRequest()->setPathInfo();
00294         }
00295         return $this;
00296     }

isInstalled (  ) 

Retrieve application installation flag

Deprecated:
since 1.2
Returns:
bool

Definition at line 901 of file App.php.

00902     {
00903         return Mage::isInstalled();
00904     }

isSingleStoreMode (  ) 

Is single Store mode (only one store without default)

Returns:
bool

Definition at line 478 of file App.php.

00479     {
00480         if (!Mage::isInstalled()) {
00481             return false;
00482         }
00483         return $this->_isSingleStore;
00484     }

loadArea ( code  ) 

Loading application area

Parameters:
string $code
Returns:
Mage_Core_Model_App

Definition at line 565 of file App.php.

00566     {
00567         $this->getArea($code)->load();
00568         return $this;
00569     }

loadAreaPart ( area,
part 
)

Loding part of area data

Parameters:
string $area
string $part
Returns:
Mage_Core_Model_App

Definition at line 578 of file App.php.

00579     {
00580         $this->getArea($area)->load($part);
00581         return $this;
00582     }

loadCache ( id  ) 

Loading cache data

Parameters:
string $id
Returns:
mixed

Definition at line 1022 of file App.php.

01023     {
01024         return $this->getCache()->load($this->_getCacheId($id));
01025     }

prepareCacheId ( id  ) 

Prepare identifier which can be used as cache id or cache tag

Parameters:
string $id
Returns:
string

Definition at line 926 of file App.php.

00927     {
00928         $id = strtoupper($id);
00929         $id = preg_replace('/([^a-zA-Z0-9_]{1,1})/', '_', $id);
00930         return $id;
00931     }

reinitStores (  ) 

Definition at line 389 of file App.php.

00390     {
00391         return $this->_initStores();
00392     }

removeCache ( id  ) 

Remove cache

Parameters:
string $id
Returns:
Mage_Core_Model_App

Definition at line 1055 of file App.php.

01056     {
01057         $this->getCache()->remove($this->_getCacheId($id));
01058         return $this;
01059     }

saveCache ( data,
id,
tags = array(),
lifeTime = false 
)

Saving cache data

Parameters:
mixed $data
string $id
array $tags
Returns:
Mage_Core_Model_App

Add global magento cache tag to all cached data excluding config cache

Definition at line 1035 of file App.php.

01036     {
01037         $tags = $this->_getCacheTags($tags);
01038 
01039         /**
01040          * Add global magento cache tag to all cached data excluding config cache
01041          */
01042         if (!in_array($this->_getCacheId(Mage_Core_Model_Config::CACHE_TAG), $tags)) {
01043             $tags[] = self::CACHE_TAG;
01044         }
01045         $this->getCache()->save((string)$data, $this->_getCacheId($id), $tags, $lifeTime);
01046         return $this;
01047     }

saveUseCache ( data  ) 

Definition at line 1131 of file App.php.

01132     {
01133         //Mage::app()->saveCache(serialize($cacheData), 'use_cache', array(), null);
01134 
01135         $filename = $this->getUseCacheFilename();
01136         if (!$fp = @fopen($filename, 'w')) {
01137             Mage::throwException($filename.' is not writable, unable to save cache settings');
01138         }
01139         @fwrite($fp, serialize($data));
01140         @fclose($fp);
01141         @chmod($filename, 0666);
01142         return $this;
01143     }

setCurrentStore ( store  ) 

Set current default store

Parameters:
string $store
Returns:
Mage_Core_Model_App

Definition at line 526 of file App.php.

00527     {
00528         $this->_currentStore = $store;
00529         return $this;
00530     }

setErrorHandler ( handler  ) 

Redeclare custom error handler

Parameters:
string $handler
Returns:
Mage_Core_Model_App

Definition at line 553 of file App.php.

00554     {
00555         set_error_handler($handler);
00556         return $this;
00557     }

setIsSingleStoreModeAllowed ( value  ) 

Allow or disallow single store mode

Parameters:
bool $value
Returns:
Mage_Core_Model_App

Definition at line 1327 of file App.php.

01328     {
01329         $this->_isSingleStoreAllowed = (bool)$value;
01330         return $this;
01331     }

setUpdateMode ( value  ) 

Definition at line 1247 of file App.php.

01248     {
01249         $this->_updateMode = $value;
01250     }

setUseSessionInUrl ( flag = true  ) 

Set Use session in URL flag

Parameters:
bool $flag
Returns:
Mage_Core_Model_App

Definition at line 1305 of file App.php.

01306     {
01307         $this->_useSessionInUrl = (bool)$flag;
01308         return $this;
01309     }

setUseSessionVar ( var  ) 

Set use session var instead of SID for URL

Parameters:
bool $var
Returns:
Mage_Core_Model_App

Definition at line 1268 of file App.php.

01269     {
01270         $this->_useSessionVar = (bool)$var;
01271         return $this;
01272     }

throwStoreException (  ) 

Definition at line 1257 of file App.php.

01258     {
01259         throw new Mage_Core_Model_Store_Exception('');
01260     }

useCache ( type = null  ) 

Check whether to use cache for specific component

Components:

  • config
  • layout
  • eav
  • translate

Returns:
boolean

Definition at line 1109 of file App.php.

01110     {
01111         if (is_null($this->_useCache)) {
01112             $filename = $this->getUseCacheFilename();
01113             if (is_readable($filename)) {
01114                 $this->_useCache = unserialize(file_get_contents($filename));
01115             } else {
01116                 $data = Mage::getConfig()->getNode('global/use_cache');
01117                 if (!empty($data)) {
01118                     $this->_useCache = (array)$data;
01119                 } else {
01120                     $this->_useCache = array();
01121                 }
01122             }
01123         }
01124         if (empty($type)) {
01125             return $this->_useCache;
01126         } else {
01127             return isset($this->_useCache[$type]) ? (bool)$this->_useCache[$type] : false;
01128         }
01129     }


Member Data Documentation

$_areas = array() [protected]

Definition at line 73 of file App.php.

$_cache [protected]

Definition at line 136 of file App.php.

$_config [protected]

Definition at line 122 of file App.php.

$_currentStore [protected]

Definition at line 190 of file App.php.

$_design [protected]

Definition at line 108 of file App.php.

$_events = array() [protected]

Definition at line 212 of file App.php.

$_frontController [protected]

Definition at line 129 of file App.php.

$_groups = array() [protected]

Definition at line 164 of file App.php.

$_helpers = array() [protected]

Definition at line 143 of file App.php.

$_isCacheLocked = null [protected]

Definition at line 236 of file App.php.

$_isSingleStore [protected]

Definition at line 178 of file App.php.

$_isSingleStoreAllowed = true [protected]

Definition at line 183 of file App.php.

$_layout [protected]

Definition at line 115 of file App.php.

$_locale [protected]

Definition at line 94 of file App.php.

$_request [protected]

Definition at line 197 of file App.php.

$_response [protected]

Definition at line 204 of file App.php.

$_store [protected]

Definition at line 80 of file App.php.

$_stores = array() [protected]

Definition at line 171 of file App.php.

$_translator [protected]

Definition at line 101 of file App.php.

$_updateMode = false [protected]

Definition at line 219 of file App.php.

$_useCache [protected]

Definition at line 150 of file App.php.

$_useSessionInUrl = true [protected]

Definition at line 227 of file App.php.

$_useSessionVar = false [protected]

Definition at line 234 of file App.php.

$_website [protected]

Definition at line 87 of file App.php.

$_websites = array() [protected]

Definition at line 157 of file App.php.

const ADMIN_STORE_ID = 0

Admin store Id

Definition at line 66 of file App.php.

const CACHE_TAG = 'MAGE'

Cache tag for all cache data exclude config cache

Definition at line 49 of file App.php.

const DEFAULT_ERROR_HANDLER = 'mageCoreErrorHandler'

Definition at line 41 of file App.php.

const DISTRO_LOCALE_CODE = 'en_US'

Definition at line 43 of file App.php.

const DISTRO_STORE_CODE = 'default'

Default store code (for install)

Definition at line 60 of file App.php.

const DISTRO_STORE_ID = 1

Default store Id (for install)

Definition at line 54 of file App.php.

const XML_PATH_INSTALL_DATE = 'global/install/date'

Definition at line 39 of file App.php.


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

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