-
Notifications
You must be signed in to change notification settings - Fork 9.3k
/
Default.php
255 lines (235 loc) · 7.43 KB
/
Default.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* @category Mage
* @package Mage_Core
* @copyright Copyright (c) 2012 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
class Mage_Backend_Controller_Router_Default extends Mage_Core_Controller_Varien_Router_Base
{
/**
* List of required request parameters
* Order sensitive
* @var array
*/
protected $_requiredParams = array(
'areaFrontName',
'moduleFrontName',
'controllerName',
'actionName',
);
/**
* Url key of area
*
* @var string
*/
protected $_areaFrontName;
/**
* @param Mage_Core_Controller_Varien_Action_Factory $controllerFactory
* @param Magento_ObjectManager $objectManager
* @param string $areaCode
* @param string $baseController
* @throws InvalidArgumentException
*/
public function __construct(
Mage_Core_Controller_Varien_Action_Factory $controllerFactory,
Magento_ObjectManager $objectManager,
$areaCode,
$baseController
) {
parent::__construct($controllerFactory, $objectManager, $areaCode, $baseController);
$this->_areaFrontName = Mage::helper('Mage_Backend_Helper_Data')->getAreaFrontName();
if (empty($this->_areaFrontName)) {
throw new InvalidArgumentException('Area Front Name should be defined');
}
}
/**
* Fetch default path
*/
public function fetchDefault()
{
$moduleFrontName = (string) Mage::getConfig()->getNode('admin/routers/adminhtml/args/frontName');
// set defaults
$pathParts = explode('/', $this->_getDefaultPath());
$this->getFront()->setDefault(array(
'area' => $this->_getParamWithDefaultValue($pathParts, 0, ''),
'module' => $this->_getParamWithDefaultValue($pathParts, 1, $moduleFrontName),
'controller' => $this->_getParamWithDefaultValue($pathParts, 2, 'index'),
'action' => $this->_getParamWithDefaultValue($pathParts, 3, 'index'),
));
}
/**
* Retrieve array param by key, or default value
*
* @param array $array
* @param string $key
* @param mixed $defaultValue
* @return mixed
*/
protected function _getParamWithDefaultValue($array, $key, $defaultValue)
{
return !empty($array[$key]) ? $array[$key] : $defaultValue;
}
/**
* Get router default request path
* @return string
*/
protected function _getDefaultPath()
{
return (string)Mage::getConfig()->getNode('default/web/default/admin');
}
/**
* Dummy call to pass through checking
*
* @return boolean
*/
protected function _beforeModuleMatch()
{
return true;
}
/**
* checking if we installed or not and doing redirect
*
* @return bool
* @SuppressWarnings(PHPMD.ExitExpression)
*/
protected function _afterModuleMatch()
{
if (!Mage::isInstalled()) {
Mage::app()->getFrontController()->getResponse()
->setRedirect(Mage::getUrl('install'))
->sendResponse();
exit;
}
return true;
}
/**
* We need to have noroute action in this router
* not to pass dispatching to next routers
*
* @return bool
*/
protected function _noRouteShouldBeApplied()
{
return true;
}
/**
* Check whether URL for corresponding path should use https protocol
*
* @param string $path
* @return bool
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
protected function _shouldBeSecure($path)
{
return substr((string)Mage::getConfig()->getNode('default/web/unsecure/base_url'), 0, 5) === 'https'
|| Mage::getStoreConfigFlag('web/secure/use_in_adminhtml', Mage_Core_Model_App::ADMIN_STORE_ID)
&& substr((string)Mage::getConfig()->getNode('default/web/secure/base_url'), 0, 5) === 'https';
}
/**
* Retrieve current secure url
*
* @param Mage_Core_Controller_Request_Http $request
* @return string
*/
protected function _getCurrentSecureUrl($request)
{
return Mage::app()->getStore(Mage_Core_Model_App::ADMIN_STORE_ID)
->getBaseUrl('link', true) . ltrim($request->getPathInfo(), '/');
}
/**
* Emulate custom admin url
*
* @param string $configArea
* @param bool $useRouterName
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function collectRoutes($configArea, $useRouterName)
{
parent::collectRoutes('admin', $useRouterName);
}
/**
* Check whether redirect should be used for secure routes
*
* @return bool
*/
protected function _shouldRedirectToSecure()
{
return false;
}
/**
* Build controller file name based on moduleName and controllerName
*
* @param string $realModule
* @param string $controller
* @return string
*/
public function getControllerFileName($realModule, $controller)
{
/**
* Start temporary block
* TODO: Sprint#27. Delete after adminhtml refactoring
*/
if ($realModule == 'Mage_Adminhtml') {
return parent::getControllerFileName($realModule, $controller);
}
/**
* End temporary block
*/
$parts = explode('_', $realModule);
$realModule = implode('_', array_splice($parts, 0, 2));
$file = Mage::getModuleDir('controllers', $realModule);
return $file . DS . ucfirst($this->_areaCode) . DS . uc_words($controller, DS) . 'Controller.php';
}
/**
* Build controller class name based on moduleName and controllerName
*
* @param string $realModule
* @param string $controller
* @return string
*/
public function getControllerClassName($realModule, $controller)
{
/**
* Start temporary block
* TODO: Sprint#27. Delete after adminhtml refactoring
*/
if ($realModule == 'Mage_Adminhtml') {
return parent::getControllerClassName($realModule, $controller);
}
/**
* End temporary block
*/
$parts = explode('_', $realModule);
$realModule = implode('_', array_splice($parts, 0, 2));
return $realModule . '_' . ucfirst($this->_areaCode) . '_' . uc_words($controller) . 'Controller';
}
/**
* Check whether this router should process given request
*
* @param array $params
* @return bool
*/
protected function _canProcess(array $params)
{
return $params['areaFrontName'] == $this->_areaFrontName;
}
}