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 area nodel
29: *
30: * @author Magento Core Team <core@magentocommerce.com>
31: */
32: class Mage_Core_Model_App_Area
33: {
34: const AREA_GLOBAL = 'global';
35: const AREA_FRONTEND = 'frontend';
36: const AREA_ADMIN = 'admin';
37: const AREA_ADMINHTML = 'adminhtml';
38:
39: const PART_CONFIG = 'config';
40: const PART_EVENTS = 'events';
41: const PART_TRANSLATE = 'translate';
42: const PART_DESIGN = 'design';
43:
44: /**
45: * Array of area loaded parts
46: *
47: * @var array
48: */
49: protected $_loadedParts;
50:
51: /**
52: * Area code
53: *
54: * @var string
55: */
56: protected $_code;
57:
58: /**
59: * Area application
60: *
61: * @var Mage_Core_Model_App
62: */
63: protected $_application;
64:
65: public function __construct($areaCode, $application)
66: {
67: $this->_code = $areaCode;
68: $this->_application = $application;
69: }
70:
71: /**
72: * Retrieve area application
73: *
74: * @return Mage_Core_Model_App
75: */
76: public function getApplication()
77: {
78: return $this->_application;
79: }
80:
81: /**
82: * Load area data
83: *
84: * @param string|null $part
85: * @return Mage_Core_Model_App_Area
86: */
87: public function load($part=null)
88: {
89: if (is_null($part)) {
90: $this->_loadPart(self::PART_CONFIG)
91: ->_loadPart(self::PART_EVENTS)
92: ->_loadPart(self::PART_DESIGN)
93: ->_loadPart(self::PART_TRANSLATE);
94: }
95: else {
96: $this->_loadPart($part);
97: }
98: return $this;
99: }
100:
101: /**
102: * Loading part of area
103: *
104: * @param string $part
105: * @return Mage_Core_Model_App_Area
106: */
107: protected function _loadPart($part)
108: {
109: if (isset($this->_loadedParts[$part])) {
110: return $this;
111: }
112: Varien_Profiler::start('mage::dispatch::controller::action::predispatch::load_area::'.$this->_code.'::'.$part);
113: switch ($part) {
114: case self::PART_CONFIG:
115: $this->_initConfig();
116: break;
117: case self::PART_EVENTS:
118: $this->_initEvents();
119: break;
120: case self::PART_TRANSLATE:
121: $this->_initTranslate();
122: break;
123: case self::PART_DESIGN:
124: $this->_initDesign();
125: break;
126: }
127: $this->_loadedParts[$part] = true;
128: Varien_Profiler::stop('mage::dispatch::controller::action::predispatch::load_area::'.$this->_code.'::'.$part);
129: return $this;
130: }
131:
132: protected function _initConfig()
133: {
134:
135: }
136:
137: protected function _initEvents()
138: {
139: Mage::app()->addEventArea($this->_code);
140: #Mage::app()->getConfig()->loadEventObservers($this->_code);
141: return $this;
142: }
143:
144: protected function _initTranslate()
145: {
146: Mage::app()->getTranslator()->init($this->_code);
147: return $this;
148: }
149:
150: protected function _initDesign()
151: {
152: if (Mage::app()->getRequest()->isStraight()) {
153: return $this;
154: }
155: $designPackage = Mage::getSingleton('core/design_package');
156: if ($designPackage->getArea() != self::AREA_FRONTEND)
157: return;
158:
159: $currentStore = Mage::app()->getStore()->getStoreId();
160:
161: $designChange = Mage::getSingleton('core/design')
162: ->loadChange($currentStore);
163:
164: if ($designChange->getData()) {
165: $designPackage->setPackageName($designChange->getPackage())
166: ->setTheme($designChange->getTheme());
167: }
168: }
169: }
170: