Show
Ignore:
Timestamp:
12/02/2006 01:20:40 PM (2 years ago)
Author:
xue
Message:

added TUrlManager and fixed #451.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/3.0/framework/Web/TUrlMapping.php

    r1511 r1539  
    1111 */ 
    1212 
     13Prado::using('System.Web.TUrlManager'); 
     14 
    1315/** 
    1416 * TUrlMapping Class 
     
    1820 * before a service is initialized, thus this module should be configured 
    1921 * globally in the <tt>application.xml</tt> file and before any services. 
    20  * 
    21  * The mapping format is as follows. 
    2222 * <code> 
    2323 *  <module id="friendly-url" class="System.Web.TUrlMapping"> 
     
    2626 *    <url ServiceParameter="Posts.ListPost" pattern="category/{cat}/?" parameters.cat="\d+" /> 
    2727 *  </module> 
     28 *  <module id="request" class="THttpRequest" UrlManager="friendly-url" /> 
    2829 * </code> 
    2930 * 
     
    3839 * The mapping can be load from an external file by specifying a configuration 
    3940 * file using the {@link setConfigFile ConfigFile} property. 
     41 * 
     42 * Since TUrlMapping is a URL manager extending from {@link TUrlManager}, 
     43 * you may override {@link TUrlManager::constructUrl} to support your pattern-based 
     44 * URL scheme. 
    4045 * 
    4146 * @author Wei Zhuo <weizhuo[at]gmail[dot]com> 
     
    4449 * @since 3.0.5 
    4550 */ 
    46 class TUrlMapping extends TModule 
     51class TUrlMapping extends TUrlManager 
    4752{ 
    4853        /** 
     54         * File extension of external configuration file 
     55         */ 
     56        const CONFIG_FILE_EXT='.xml'; 
     57        /** 
    4958         * @var string default pattern class. 
    5059         */ 
     
    5867         */ 
    5968        private $_matched; 
    60         /** 
    61          * File extension of external configuration file 
    62          */ 
    63         const CONFIG_FILE_EXT='.xml'; 
    6469        /** 
    6570         * @var string external configuration file 
     
    7580        public function init($xml) 
    7681        { 
     82                parent::init($xml); 
    7783                if($this->getRequest()->getRequestResolved()) 
    7884                        throw new TConfigurationException('urlpath_dispatch_module_must_be_global'); 
     
    8086                        $this->loadConfigFile(); 
    8187                $this->loadUrlMappings($xml); 
    82                 $this->resolveMappings(); 
    8388        } 
    8489 
     
    143148 
    144149        /** 
    145          * Using the request URL path, find the first matching pattern. If found 
    146          * the matched pattern parameters are used in the Request object. 
    147          */ 
    148         protected function resolveMappings() 
     150         * Parses the request URL and returns an array of input parameters. 
     151         * This method overrides the parent implementation. 
     152         * The input parameters do not include GET and POST variables. 
     153         * This method uses the request URL path to find the first matching pattern. If found 
     154         * the matched pattern parameters are used to return as the input parameters. 
     155         * @return array list of input parameters 
     156         */ 
     157        public function parseUrl() 
    149158        { 
    150159                $url = $this->getRequest()->getUrl(); 
     
    154163                        if(count($matches) > 0) 
    155164                        { 
     165                                $this->_matched=$pattern; 
    156166                                $this->changeServiceParameters($pattern); 
    157                                 $this->initializeRequestParameters($matches); 
    158                                 $this->_matched=$pattern; 
    159                                 break; 
     167                                $params=array(); 
     168                                foreach($matches as $key=>$value) 
     169                                        if(is_string($key)) 
     170                                                $params[$key]=$value; 
     171                                return $params; 
    160172                        } 
    161173                } 
     174                return array(); 
    162175        } 
    163176 
     
    168181        { 
    169182                return $this->_matched; 
    170         } 
    171  
    172         /** 
    173          * @param array initialize the Request with matched parameters. 
    174          */ 
    175         protected function initializeRequestParameters($matches) 
    176         { 
    177                 $request = $this->getRequest(); 
    178                 foreach($matches as $k => $v) 
    179                 { 
    180                         if(!is_int($k)) 
    181                                 $request->add($k,$v); 
    182                 } 
    183183        } 
    184184