Public Member Functions | |
collectRoutes ($configArea, $useRouterName) | |
fetchDefault () | |
match (Zend_Controller_Request_Http $request) | |
addModule ($frontName, $moduleName, $routeName) | |
getModuleByFrontName ($frontName) | |
getModuleByName ($moduleName, $modules) | |
getFrontNameByRoute ($routeName) | |
getRouteByFrontName ($frontName) | |
getControllerFileName ($realModule, $controller) | |
validateControllerFileName ($fileName) | |
getControllerClassName ($realModule, $controller) | |
rewrite (array $p) | |
Protected Member Functions | |
_beforeModuleMatch () | |
_afterModuleMatch () | |
_noRouteShouldBeApplied () | |
_validateControllerClassName ($realModule, $controller) | |
_inludeControllerClass ($controllerFileName, $controllerClassName) | |
_checkShouldBeSecure ($request, $path='') | |
_getCurrentSecureUrl ($request) | |
_shouldBeSecure ($path) | |
Protected Attributes | |
$_modules = array() | |
$_routes = array() | |
$_dispatchData = array() |
Definition at line 27 of file Standard.php.
_afterModuleMatch | ( | ) | [protected] |
dummy call to pass through checking
Reimplemented in Mage_Core_Controller_Varien_Router_Admin.
Definition at line 100 of file Standard.php.
_beforeModuleMatch | ( | ) | [protected] |
checking if this admin if yes then we don't use this router
Reimplemented in Mage_Core_Controller_Varien_Router_Admin.
Definition at line 87 of file Standard.php.
00088 { 00089 if (Mage::app()->getStore()->isAdmin()) { 00090 return false; 00091 } 00092 return true; 00093 }
_checkShouldBeSecure | ( | $ | request, | |
$ | path = '' | |||
) | [protected] |
Definition at line 399 of file Standard.php.
00400 { 00401 if (!Mage::isInstalled() || $request->getPost()) { 00402 return; 00403 } 00404 00405 if ($this->_shouldBeSecure($path) && !Mage::app()->getStore()->isCurrentlySecure()) { 00406 $url = $this->_getCurrentSecureUrl($request); 00407 00408 Mage::app()->getFrontController()->getResponse() 00409 ->setRedirect($url) 00410 ->sendResponse(); 00411 exit; 00412 } 00413 }
_getCurrentSecureUrl | ( | $ | request | ) | [protected] |
Reimplemented in Mage_Core_Controller_Varien_Router_Admin.
Definition at line 415 of file Standard.php.
00416 { 00417 return Mage::getBaseUrl('link', true).ltrim($request->getPathInfo(), '/'); 00418 }
_inludeControllerClass | ( | $ | controllerFileName, | |
$ | controllerClassName | |||
) | [protected] |
Including controller class if checking of existense class before include
string | $controllerFileName | |
string | $controllerClassName |
Definition at line 297 of file Standard.php.
00298 { 00299 if (!class_exists($controllerClassName, false)) { 00300 if (!file_exists($controllerFileName)) { 00301 return false; 00302 } 00303 include $controllerFileName; 00304 00305 if (!class_exists($controllerClassName, false)) { 00306 throw Mage::exception('Mage_Core', Mage::helper('core')->__('Controller file was loaded but class does not exist')); 00307 } 00308 } 00309 return true; 00310 }
_noRouteShouldBeApplied | ( | ) | [protected] |
Allow to control if we need to enable norout functionality in current router
Reimplemented in Mage_Core_Controller_Varien_Router_Admin.
Definition at line 258 of file Standard.php.
_shouldBeSecure | ( | $ | path | ) | [protected] |
Reimplemented in Mage_Core_Controller_Varien_Router_Admin.
Definition at line 420 of file Standard.php.
00421 { 00422 return substr(Mage::getStoreConfig('web/unsecure/base_url'),0,5)==='https' 00423 || Mage::getStoreConfigFlag('web/secure/use_in_frontend') 00424 && substr(Mage::getStoreConfig('web/secure/base_url'),0,5)=='https' 00425 && Mage::getConfig()->shouldUrlBeSecure($path); 00426 }
_validateControllerClassName | ( | $ | realModule, | |
$ | controller | |||
) | [protected] |
Generating and validating class file name, class and if evrything ok do include if needed and return of class name
Definition at line 269 of file Standard.php.
00270 { 00271 $controllerFileName = $this->getControllerFileName($realModule, $controller); 00272 if (!$this->validateControllerFileName($controllerFileName)) { 00273 return false; 00274 } 00275 00276 $controllerClassName = $this->getControllerClassName($realModule, $controller); 00277 if (!$controllerClassName) { 00278 return false; 00279 } 00280 00281 // include controller file if needed 00282 if (!$this->_inludeControllerClass($controllerFileName, $controllerClassName)) { 00283 return false; 00284 } 00285 00286 return $controllerClassName; 00287 }
addModule | ( | $ | frontName, | |
$ | moduleName, | |||
$ | routeName | |||
) |
Definition at line 312 of file Standard.php.
00313 { 00314 $this->_modules[$frontName] = $moduleName; 00315 $this->_routes[$routeName] = $frontName; 00316 return $this; 00317 }
collectRoutes | ( | $ | configArea, | |
$ | useRouterName | |||
) |
Definition at line 33 of file Standard.php.
00034 { 00035 $routers = array(); 00036 $routersConfigNode = Mage::getConfig()->getNode($configArea.'/routers'); 00037 if($routersConfigNode) { 00038 $routers = $routersConfigNode->children(); 00039 } 00040 foreach ($routers as $routerName=>$routerConfig) { 00041 $use = (string)$routerConfig->use; 00042 if ($use == $useRouterName) { 00043 $modules = array((string)$routerConfig->args->module); 00044 if ($routerConfig->args->modules) { 00045 foreach ($routerConfig->args->modules->children() as $customModule) { 00046 if ($customModule) { 00047 if ($before = $customModule->getAttribute('before')) { 00048 $position = array_search($before, $modules); 00049 if ($position === false) { 00050 $position = 0; 00051 } 00052 array_splice($modules, $position, 0, (string)$customModule); 00053 } elseif ($after = $customModule->getAttribute('after')) { 00054 $position = array_search($after, $modules); 00055 if ($position === false) { 00056 $position = count($modules); 00057 } 00058 array_splice($modules, $position+1, 0, (string)$customModule); 00059 } else { 00060 $modules[] = (string)$customModule; 00061 } 00062 } 00063 } 00064 } 00065 00066 $frontName = (string)$routerConfig->args->frontName; 00067 $this->addModule($frontName, $modules, $routerName); 00068 } 00069 } 00070 }
fetchDefault | ( | ) |
Reimplemented in Mage_Core_Controller_Varien_Router_Admin.
Definition at line 72 of file Standard.php.
00073 { 00074 $d = explode('/', Mage::getStoreConfig('web/default/front')); 00075 $this->getFront()->setDefault(array( 00076 'module' => !empty($d[0]) ? $d[0] : 'core', 00077 'controller' => !empty($d[1]) ? $d[1] : 'index', 00078 'action' => !empty($d[2]) ? $d[2] : 'index' 00079 )); 00080 }
getControllerClassName | ( | $ | realModule, | |
$ | controller | |||
) |
Definition at line 371 of file Standard.php.
00372 { 00373 $class = $realModule.'_'.uc_words($controller).'Controller'; 00374 return $class; 00375 }
getControllerFileName | ( | $ | realModule, | |
$ | controller | |||
) |
Definition at line 351 of file Standard.php.
00352 { 00353 $parts = explode('_', $realModule); 00354 $realModule = implode('_', array_splice($parts, 0, 2)); 00355 $file = Mage::getModuleDir('controllers', $realModule); 00356 if (count($parts)) { 00357 $file .= DS . implode(DS, $parts); 00358 } 00359 $file .= DS.uc_words($controller, DS).'Controller.php'; 00360 return $file; 00361 }
getFrontNameByRoute | ( | $ | routeName | ) |
Reimplemented from Mage_Core_Controller_Varien_Router_Abstract.
Definition at line 338 of file Standard.php.
00339 { 00340 if (isset($this->_routes[$routeName])) { 00341 return $this->_routes[$routeName]; 00342 } 00343 return false; 00344 }
getModuleByFrontName | ( | $ | frontName | ) |
Definition at line 319 of file Standard.php.
00320 { 00321 if (isset($this->_modules[$frontName])) { 00322 return $this->_modules[$frontName]; 00323 } 00324 return false; 00325 }
getModuleByName | ( | $ | moduleName, | |
$ | modules | |||
) |
Definition at line 327 of file Standard.php.
00328 { 00329 foreach ($modules as $module) { 00330 if ($moduleName === $module || (is_array($module) 00331 && $this->getModuleByName($moduleName, $module))) { 00332 return true; 00333 } 00334 } 00335 return false; 00336 }
getRouteByFrontName | ( | $ | frontName | ) |
Reimplemented from Mage_Core_Controller_Varien_Router_Abstract.
Definition at line 346 of file Standard.php.
match | ( | Zend_Controller_Request_Http $ | request | ) |
Searching router args by module name from route using it as key
If we did not found anything we searching exact this module name in array values
Going through modules to find appropriate controller
if we did not found any siutibul
Reimplemented from Mage_Core_Controller_Varien_Router_Abstract.
Definition at line 105 of file Standard.php.
00106 { 00107 //checkings before even try to findout that current module 00108 //should use this router 00109 if (!$this->_beforeModuleMatch()) { 00110 return false; 00111 } 00112 00113 $this->fetchDefault(); 00114 00115 $front = $this->getFront(); 00116 00117 $p = explode('/', trim($request->getPathInfo(), '/')); 00118 00119 // get module name 00120 if ($request->getModuleName()) { 00121 $module = $request->getModuleName(); 00122 } else { 00123 if(!empty($p[0])) { 00124 $module = $p[0]; 00125 } else { 00126 $module = $this->getFront()->getDefault('module'); 00127 $request->setAlias(Mage_Core_Model_Url_Rewrite::REWRITE_REQUEST_PATH_ALIAS, ''); 00128 } 00129 } 00130 if (!$module) { 00131 if (Mage::app()->getStore()->isAdmin()) { 00132 $module = 'admin'; 00133 } else { 00134 return false; 00135 } 00136 } 00137 00138 /** 00139 * Searching router args by module name from route using it as key 00140 */ 00141 $modules = $this->getModuleByFrontName($module); 00142 00143 /** 00144 * If we did not found anything we searching exact this module 00145 * name in array values 00146 */ 00147 if ($modules === false) { 00148 if ($moduleFrontName = $this->getModuleByName($module, $this->_modules)) { 00149 $modules = array($module); 00150 $module = $moduleFrontName; 00151 } else { 00152 return false; 00153 } 00154 } 00155 00156 //checkings after we foundout that this router should be used for current module 00157 if (!$this->_afterModuleMatch()) { 00158 return false; 00159 } 00160 00161 /** 00162 * Going through modules to find appropriate controller 00163 */ 00164 $found = false; 00165 foreach ($modules as $realModule) { 00166 $request->setRouteName($this->getRouteByFrontName($module)); 00167 00168 // get controller name 00169 if ($request->getControllerName()) { 00170 $controller = $request->getControllerName(); 00171 } else { 00172 if (!empty($p[1])) { 00173 $controller = $p[1]; 00174 } else { 00175 $controller = $front->getDefault('controller'); 00176 $request->setAlias( 00177 Mage_Core_Model_Url_Rewrite::REWRITE_REQUEST_PATH_ALIAS, 00178 ltrim($request->getOriginalPathInfo(), '/') 00179 ); 00180 } 00181 } 00182 00183 // get action name 00184 if (empty($action)) { 00185 if ($request->getActionName()) { 00186 $action = $request->getActionName(); 00187 } else { 00188 $action = !empty($p[2]) ? $p[2] : $front->getDefault('action'); 00189 } 00190 } 00191 00192 //checking if this place should be secure 00193 $this->_checkShouldBeSecure($request, '/'.$module.'/'.$controller.'/'.$action); 00194 00195 $controllerClassName = $this->_validateControllerClassName($realModule, $controller); 00196 if (!$controllerClassName) { 00197 continue; 00198 } 00199 00200 // instantiate controller class 00201 $controllerInstance = new $controllerClassName($request, $front->getResponse()); 00202 00203 if (!$controllerInstance->hasAction($action)) { 00204 continue; 00205 } 00206 00207 $found = true; 00208 break; 00209 } 00210 00211 /** 00212 * if we did not found any siutibul 00213 */ 00214 if (!$found) { 00215 if ($this->_noRouteShouldBeApplied()) { 00216 $controller = 'index'; 00217 $action = 'noroute'; 00218 00219 $controllerClassName = $this->_validateControllerClassName($realModule, $controller); 00220 if (!$controllerClassName) { 00221 return false; 00222 } 00223 00224 // instantiate controller class 00225 $controllerInstance = new $controllerClassName($request, $front->getResponse()); 00226 00227 if (!$controllerInstance->hasAction($action)) { 00228 return false; 00229 } 00230 } else { 00231 return false; 00232 } 00233 } 00234 00235 // set values only after all the checks are done 00236 $request->setModuleName($module); 00237 $request->setControllerName($controller); 00238 $request->setActionName($action); 00239 $request->setControllerModule($realModule); 00240 00241 // set parameters from pathinfo 00242 for ($i=3, $l=sizeof($p); $i<$l; $i+=2) { 00243 $request->setParam($p[$i], isset($p[$i+1]) ? $p[$i+1] : ''); 00244 } 00245 00246 // dispatch action 00247 $request->setDispatched(true); 00248 $controllerInstance->dispatch($action); 00249 00250 return true; 00251 }
rewrite | ( | array $ | p | ) |
Definition at line 377 of file Standard.php.
00378 { 00379 $rewrite = Mage::getConfig()->getNode('global/rewrite'); 00380 if ($module = $rewrite->{$p[0]}) { 00381 if (!$module->children()) { 00382 $p[0] = trim((string)$module); 00383 } 00384 } 00385 if (isset($p[1]) && ($controller = $rewrite->{$p[0]}->{$p[1]})) { 00386 if (!$controller->children()) { 00387 $p[1] = trim((string)$controller); 00388 } 00389 } 00390 if (isset($p[2]) && ($action = $rewrite->{$p[0]}->{$p[1]}->{$p[2]})) { 00391 if (!$action->children()) { 00392 $p[2] = trim((string)$action); 00393 } 00394 } 00395 #echo "<pre>".print_r($p,1)."</pre>"; 00396 return $p; 00397 }
validateControllerFileName | ( | $ | fileName | ) |
Definition at line 363 of file Standard.php.
00364 { 00365 if ($fileName && is_readable($fileName) && false===strpos($fileName, '//')) { 00366 return true; 00367 } 00368 return false; 00369 }
$_dispatchData = array() [protected] |
Definition at line 31 of file Standard.php.
$_modules = array() [protected] |
Definition at line 29 of file Standard.php.
$_routes = array() [protected] |
Definition at line 30 of file Standard.php.