Mage_Core_Controller_Varien_Front Class Reference

Inheritance diagram for Mage_Core_Controller_Varien_Front:

Varien_Object

List of all members.

Public Member Functions

 setDefault ($key, $value=null)
 getDefault ($key=null)
 getRequest ()
 getResponse ()
 addRouter ($name, Mage_Core_Controller_Varien_Router_Abstract $router)
 getRouter ($name)
 init ()
 dispatch ()
 getRouterByRoute ($routeName)
 getRouterByFrontName ($frontName)
 rewrite ()

Public Attributes

const XML_STORE_ROUTERS_PATH = 'web/routers'

Protected Attributes

 $_defaults = array()
 $_routers = array()
 $_urlCache = array()


Detailed Description

Definition at line 28 of file Front.php.


Member Function Documentation

addRouter ( name,
Mage_Core_Controller_Varien_Router_Abstract router 
)

Adding new router

Parameters:
string $name
Mage_Core_Controller_Varien_Router_Abstract $router
Returns:
Mage_Core_Controller_Varien_Front

Definition at line 90 of file Front.php.

00091     {
00092         $router->setFront($this);
00093         $this->_routers[$name] = $router;
00094         return $this;
00095     }

dispatch (  ) 

Definition at line 141 of file Front.php.

00142     {
00143         $request = $this->getRequest();
00144         $request->setPathInfo()->setDispatched(false);
00145 
00146         Varien_Profiler::start('mage::dispatch::db_url_rewrite');
00147         Mage::getModel('core/url_rewrite')->rewrite();
00148         Varien_Profiler::stop('mage::dispatch::db_url_rewrite');
00149 
00150         Varien_Profiler::start('mage::dispatch::config_url_rewrite');
00151         $this->rewrite();
00152         Varien_Profiler::stop('mage::dispatch::config_url_rewrite');
00153 
00154         Varien_Profiler::start('mage::dispatch::routers_match');
00155         $i = 0;
00156         while (!$request->isDispatched() && $i++<100) {
00157             foreach ($this->_routers as $router) {
00158                 if ($router->match($this->getRequest())) {
00159                     break;
00160                 }
00161             }
00162         }
00163         Varien_Profiler::stop('mage::dispatch::routers_match');
00164         if ($i>100) {
00165             Mage::throwException('Front controller reached 100 router match iterations');
00166         }
00167 
00168         Varien_Profiler::start('mage::app::dispatch::send_response');
00169         $this->getResponse()->sendResponse();
00170         Varien_Profiler::stop('mage::app::dispatch::send_response');
00171 
00172         return $this;
00173     }

getDefault ( key = null  ) 

Definition at line 53 of file Front.php.

00054     {
00055         if (is_null($key)) {
00056             return $this->_defaults;
00057         } elseif (isset($this->_defaults[$key])) {
00058             return $this->_defaults[$key];
00059         }
00060         return false;
00061     }

getRequest (  ) 

Retrieve request object

Returns:
Mage_Core_Controller_Request_Http

Definition at line 68 of file Front.php.

00069     {
00070         return Mage::app()->getRequest();
00071     }

getResponse (  ) 

Retrieve response object

Returns:
Zend_Controller_Response_Http

Definition at line 78 of file Front.php.

00079     {
00080         return Mage::app()->getResponse();
00081     }

getRouter ( name  ) 

Retrieve router by name

Parameters:
string $name
Returns:
Mage_Core_Controller_Varien_Router_Abstract

Definition at line 103 of file Front.php.

00104     {
00105         if (isset($this->_routers[$name])) {
00106             return $this->_routers[$name];
00107         }
00108         return false;
00109     }

getRouterByFrontName ( frontName  ) 

Definition at line 196 of file Front.php.

00197     {
00198         // empty route supplied - return base url
00199         if (empty($frontName)) {
00200             $router = $this->getRouter('standard');
00201         } elseif ($this->getRouter('admin')->getRouteByFrontName($frontName)) {
00202             // try standard router url assembly
00203             $router = $this->getRouter('admin');
00204         } elseif ($this->getRouter('standard')->getRouteByFrontName($frontName)) {
00205             // try standard router url assembly
00206             $router = $this->getRouter('standard');
00207         } elseif ($router = $this->getRouter($frontName)) {
00208             // try custom router url assembly
00209         } else {
00210             // get default router url
00211             $router = $this->getRouter('default');
00212         }
00213 
00214         return $router;
00215     }

getRouterByRoute ( routeName  ) 

Definition at line 175 of file Front.php.

00176     {
00177         // empty route supplied - return base url
00178         if (empty($routeName)) {
00179             $router = $this->getRouter('standard');
00180         } elseif ($this->getRouter('admin')->getFrontNameByRoute($routeName)) {
00181             // try standard router url assembly
00182             $router = $this->getRouter('admin');
00183         } elseif ($this->getRouter('standard')->getFrontNameByRoute($routeName)) {
00184             // try standard router url assembly
00185             $router = $this->getRouter('standard');
00186         } elseif ($router = $this->getRouter($routeName)) {
00187             // try custom router url assembly
00188         } else {
00189             // get default router url
00190             $router = $this->getRouter('default');
00191         }
00192 
00193         return $router;
00194     }

init (  ) 

Definition at line 111 of file Front.php.

00112     {
00113         Mage::dispatchEvent('controller_front_init_before', array('front'=>$this));
00114 
00115         $routersInfo = Mage::app()->getStore()->getConfig(self::XML_STORE_ROUTERS_PATH);
00116 
00117         Varien_Profiler::start('mage::app::init_front_controller::collect_routers');
00118         foreach ($routersInfo as $routerCode => $routerInfo) {
00119             if (isset($routerInfo['disabled']) && $routerInfo['disabled']) {
00120                 continue;
00121             }
00122             if (isset($routerInfo['class'])) {
00123                 $router = new $routerInfo['class'];
00124                 if (isset($routerInfo['area'])) {
00125                     $router->collectRoutes($routerInfo['area'], $routerCode);
00126                 }
00127                 $this->addRouter($routerCode, $router);
00128             }
00129         }
00130         Varien_Profiler::stop('mage::app::init_front_controller::collect_routers');
00131 
00132         Mage::dispatchEvent('controller_front_init_routers', array('front'=>$this));
00133 
00134         // Add default router at the last
00135         $default = new Mage_Core_Controller_Varien_Router_Default();
00136         $this->addRouter('default', $default);
00137 
00138         return $this;
00139     }

rewrite (  ) 

Definition at line 217 of file Front.php.

00218     {
00219         $request = $this->getRequest();
00220         $config = Mage::getConfig()->getNode('global/rewrite');
00221         if (!$config) {
00222             return;
00223         }
00224         foreach ($config->children() as $rewrite) {
00225             $from = (string)$rewrite->from;
00226             $to = (string)$rewrite->to;
00227             if (empty($from) || empty($to)) {
00228                 continue;
00229             }
00230             $pathInfo = preg_replace($from, $to, $request->getPathInfo());
00231             $request->setPathInfo($pathInfo);
00232         }
00233     }

setDefault ( key,
value = null 
)

Definition at line 43 of file Front.php.

00044     {
00045         if (is_array($key)) {
00046             $this->_defaults = $key;
00047         } else {
00048             $this->_defaults[$key] = $value;
00049         }
00050         return $this;
00051     }


Member Data Documentation

$_defaults = array() [protected]

Definition at line 30 of file Front.php.

$_routers = array() [protected]

Definition at line 37 of file Front.php.

$_urlCache = array() [protected]

Definition at line 39 of file Front.php.

const XML_STORE_ROUTERS_PATH = 'web/routers'

Definition at line 41 of file Front.php.


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

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