Changeset 5990


Ignore:
Timestamp:
02/02/12 06:56:12 (4 months ago)
Author:
vain
Message:
  • moved prepareRequestURI() next to usage context
  • commented
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/router.core.php

    r5942 r5990  
    4949 * With Routing you are able to map a logical name to a specific physical name. 
    5050 * Examples: map a logical URL (a mod_rewritten one) to a Controller/Method/Parameter 
    51  * or map a FileRequest via logical URL (a mod_rewritten one) to a DownloadController/Method/Parameters 
     51 * or map a FileRequest via logical URL (a mod_rewritten one) to a DownloadController/Method/Parameters. 
     52 * Routes are a valuable concept because they separate your URLs from your data.  
    5253 * 
    5354 * There are two different URL Formatings allowed: 
     
    9596 
    9697    /** 
     98     * Get and prepare the SERVER_URL/URI 
     99     * 
     100     * Several fixes are applied to the $request_url (which is Clansuite_HttpRequest::getRequestURI()) 
     101     * It's already (1) lowercased and (2) urldecoded when incomming. 
     102     * This function (3) strips slashes from beginning and end and (4) prepends a slash. 
     103     * Then (5) strips PHP_SELF from the uri string. 
     104     * A multislash removal is not needed, because of the later usage of preg_split. 
     105     * 
     106     * @param string $request_url Clansuite_HttpRequest::getRequestURI 
     107     * 
     108     * @return string Request URL 
     109     */ 
     110    private function prepareRequestURI($request_uri) 
     111    { 
     112        #Clansuite_Debug::firebug('The unprepared Server Request URI is "' . $request_uri . '"'); 
     113 
     114        # add slash in front + remove slash at the end 
     115        $this->uri = '/' . trim($request_uri, '/'); 
     116 
     117        # subtract PHP_SELF from uri 
     118        $url_directory_prefix_length = strlen(dirname($_SERVER['PHP_SELF'])); 
     119        $this->uri = substr($this->uri, $url_directory_prefix_length); 
     120 
     121        #Clansuite_Debug::firebug('The prepared Server Request URI is "' . $this->uri . '"'); 
     122 
     123        return $this->uri; 
     124    } 
     125 
     126    /** 
    97127     * Add route 
    98128     * 
     
    105135         * 1) Preprocess the route 
    106136         */ 
     137 
    107138        # split the pattern describing the URL target into uri segments 
    108139        $url_pattern = ltrim($url_pattern, '/'); 
     140         
     141        # then transform placeholders like (:num) or (:id) 
     142        $url_pattern = self::placeholdersToRegexp($url_pattern); 
     143 
    109144        $segments = explode('/', $url_pattern); 
    110145 
    111         # the incomming route might have placeholders lile (:num) or (:id) 
    112         $url_pattern = self::placeholdersToRegexp($url_pattern); 
    113  
    114146        $regexp = $this->processSegmentsRegExp($segments, $route_options); 
    115         $options = array('regexp' => $regexp, 
    116                          'number_of_segments' => count($segments)); 
     147         
     148        $options = array( 
     149            'regexp' => $regexp, 
     150            'number_of_segments' => count($segments) 
     151        ); 
    117152 
    118153 
     
    498533    } 
    499534 
    500     /** 
    501      * Get and prepare the SERVER_URL/URI 
    502      * 
    503      * Several fixes are applied the $request_url (which is Clansuite_HttpRequest::getRequestURI()) 
    504      * It's already (1) lowercased and (2) urldecoded when incomming. 
    505      * This function (3) strips slashes from beginning and end and (4) prepends a slash. 
    506      * A multislash removal is not needed, because of the later usage of preg_split. 
    507      * 
    508      * @param string $request_url Clansuite_HttpRequest::getRequestURI 
    509      * 
    510      * @return string Request URL 
    511      */ 
    512     private function prepareRequestURI($request_uri) 
    513     { 
    514         #Clansuite_Debug::firebug('The unprepared Server Request URI is "' . $request_uri . '"'); 
    515  
    516         # add slash in front + remove slash at the end 
    517         $this->uri = '/' . trim($request_uri, '/'); 
    518  
    519         # path subtraction (get length of dirname of php_self and subtract from uri) 
    520         $url_directory_prefix_length = strlen(dirname($_SERVER['PHP_SELF'])); 
    521         $this->uri = substr($this->uri, $url_directory_prefix_length); 
    522  
    523         #Clansuite_Debug::firebug('The prepared Server Request URI is "' . $this->uri . '"'); 
    524  
    525         return $this->uri; 
    526     } 
    527535 
    528536    /** 
Note: See TracChangeset for help on using the changeset viewer.