00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 class Mage_Core_Controller_Front_Router
00029 {
00030 protected $_config = null;
00031
00032 public function __construct($config)
00033 {
00034 $this->_config = $config;
00035 }
00036
00037 public function getConfig()
00038 {
00039 return $this->_config;
00040 }
00041
00042 public function addRoutes(Zend_Controller_Router_Interface $router)
00043 {
00044 $frontName = $this->_config->getName();
00045 $routeMatch = $frontName.'/:controller/:action/*';
00046 $moduleName = (string)$this->_config->module;
00047 $routeParams = array('module'=>$moduleName, 'controller'=>'index', 'action'=>'index', '_frontName'=>$frontName);
00048 $route = new Zend_Controller_Router_Route($routeMatch, $routeParams);
00049 $router->addRoute($moduleName, $route);
00050
00051 return $this;
00052 }
00053
00054 public function getUrl($params=array())
00055 {
00056 static $reservedKeys = array('module'=>1, 'controller'=>1, 'action'=>1, 'array'=>1);
00057
00058 if (is_string($params)) {
00059 $paramsArr = explode('/', $params);
00060 $params = array('controller'=>$paramsArr[0], 'action'=>$paramsArr[1]);
00061 }
00062
00063 $url = Mage::getBaseUrl($params);
00064
00065 if (!empty($params['frontName'])) {
00066 $url .= $params['frontName'].'/';
00067 } else {
00068 $url .= $this->_config->getName().'/';
00069 }
00070
00071 if (!empty($params)) {
00072 $paramsStr = '';
00073 foreach ($params as $key=>$value) {
00074 if (!isset($reservedKeys[$key]) && '_'!==$key{0} && !empty($value)) {
00075 $paramsStr .= $key.'/'.$value.'/';
00076 }
00077 }
00078
00079 if (empty($params['controller']) && !empty($paramsStr)) {
00080 $params['controller'] = 'index';
00081 }
00082 $url .= empty($params['controller']) ? '' : $params['controller'].'/';
00083
00084 if (empty($params['action']) && !empty($paramsStr)) {
00085 $params['action'] = 'index';
00086 }
00087 $url .= empty($params['action']) ? '' : $params['action'].'/';
00088
00089 $url .= $paramsStr;
00090
00091 $url .= empty($params['array']) ? '' : '?' . http_build_query($params['array']);
00092 }
00093
00094 return $url;
00095 }
00096 }