Example #1
0
 /**
  * Attempts to determine the current URI using CLI, GET, PATH_INFO, ORIG_PATH_INFO, or PHP_SELF.
  *
  * @return  void
  */
 public static function find_uri()
 {
     if (PHP_SAPI === 'cli') {
         // Command line requires a bit of hacking
         if (isset($_SERVER['argv'][1])) {
             self::$current_uri = $_SERVER['argv'][1];
             // Remove GET string from segments
             if (($query = strpos(self::$current_uri, '?')) !== FALSE) {
                 list(self::$current_uri, $query) = explode('?', self::$current_uri, 2);
                 // Parse the query string into $_GET
                 parse_str($query, $_GET);
                 // Convert $_GET to UTF-8
                 $_GET = utf8::clean($_GET);
             }
         }
     } elseif (isset($_GET['kohana_uri'])) {
         // Use the URI defined in the query string
         self::$current_uri = $_GET['kohana_uri'];
         // Remove the URI from $_GET
         unset($_GET['kohana_uri']);
         // Remove the URI from $_SERVER['QUERY_STRING']
         $_SERVER['QUERY_STRING'] = preg_replace('~\\bkohana_uri\\b[^&]*+&?~', '', $_SERVER['QUERY_STRING']);
     } elseif (isset($_SERVER['PATH_INFO']) and $_SERVER['PATH_INFO']) {
         self::$current_uri = $_SERVER['PATH_INFO'];
     } elseif (isset($_SERVER['ORIG_PATH_INFO']) and $_SERVER['ORIG_PATH_INFO']) {
         self::$current_uri = $_SERVER['ORIG_PATH_INFO'];
     } elseif (isset($_SERVER['PHP_SELF']) and $_SERVER['PHP_SELF']) {
         self::$current_uri = $_SERVER['PHP_SELF'];
     }
     // The front controller directory and filename
     $fc = substr(realpath($_SERVER['SCRIPT_FILENAME']), strlen(DOCROOT));
     if (($strpos_fc = strpos(self::$current_uri, $fc)) !== FALSE) {
         // Remove the front controller from the current uri
         self::$current_uri = substr(self::$current_uri, $strpos_fc + strlen($fc));
     }
     // Remove slashes from the start and end of the URI
     self::$current_uri = trim(self::$current_uri, '/');
     if (self::$current_uri !== '') {
         if ($suffix = Kohana::config('core.url_suffix') and strpos(self::$current_uri, $suffix) !== FALSE) {
             // Remove the URL suffix
             self::$current_uri = preg_replace('#' . preg_quote($suffix) . '$#u', '', self::$current_uri);
             // Set the URL suffix
             self::$url_suffix = $suffix;
         }
         // Reduce multiple slashes into single slashes
         self::$current_uri = preg_replace('#//+#', '/', self::$current_uri);
     }
 }