protected function setUp()
 {
     // Save config
     $this->kohana_config['core.url_suffix'] = Kohana_Config::instance()->get('core.url_suffix');
     // Save Server API
     $this->kohana_server_api = Kohana::$server_api;
     // Save Router members
     $this->router_vars = array('complete_uri' => Router::$complete_uri, 'controller' => Router::$controller, 'current_uri' => Router::$current_uri, 'query_string' => Router::$query_string, 'rsegments' => Router::$rsegments, 'routed_uri' => Router::$routed_uri, 'segments' => Router::$segments, 'url_suffix' => Router::$url_suffix);
     // Reset Router members
     Router::$complete_uri = '';
     Router::$controller = NULL;
     Router::$current_uri = '';
     Router::$query_string = '';
     Router::$rsegments = NULL;
     Router::$routed_uri = '';
     Router::$segments = NULL;
     Router::$url_suffix = '';
 }
Example #2
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])) {
             Router::$current_uri = $_SERVER['argv'][1];
             // Remove GET string from segments
             if (($query = strpos(Router::$current_uri, '?')) !== FALSE) {
                 list(Router::$current_uri, $query) = explode('?', Router::$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
         Router::$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']) {
         Router::$current_uri = $_SERVER['PATH_INFO'];
     } elseif (isset($_SERVER['ORIG_PATH_INFO']) and $_SERVER['ORIG_PATH_INFO']) {
         Router::$current_uri = $_SERVER['ORIG_PATH_INFO'];
     } elseif (isset($_SERVER['PHP_SELF']) and $_SERVER['PHP_SELF']) {
         Router::$current_uri = $_SERVER['PHP_SELF'];
     }
     // The front controller directory and filename
     $fc = substr(realpath($_SERVER['SCRIPT_FILENAME']), strlen(DOCROOT));
     if (($strpos_fc = strpos(Router::$current_uri, $fc)) !== FALSE) {
         // Remove the front controller from the current uri
         Router::$current_uri = substr(Router::$current_uri, $strpos_fc + strlen($fc));
     }
     // Remove slashes from the start and end of the URI
     Router::$current_uri = trim(Router::$current_uri, '/');
     if (Router::$current_uri !== '') {
         if ($suffix = Kohana::config('core.url_suffix') and strpos(Router::$current_uri, $suffix) !== FALSE) {
             // Remove the URL suffix
             Router::$current_uri = preg_replace('#' . preg_quote($suffix) . '$#u', '', Router::$current_uri);
             // Set the URL suffix
             Router::$url_suffix = $suffix;
         }
         // Reduce multiple slashes into single slashes
         Router::$current_uri = preg_replace('#//+#', '/', Router::$current_uri);
     }
 }
Example #3
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 (Kohana::$server_api === 'cli') {
         // Command line requires a bit of hacking
         if (isset($_SERVER['argv'][1])) {
             Router::$current_uri = $_SERVER['argv'][1];
             // Remove GET string from segments
             if (strpos(Router::$current_uri, '?') !== FALSE) {
                 list(Router::$current_uri, $query) = explode('?', Router::$current_uri, 2);
                 // Parse the query string into $_GET
                 parse_str($query, $_GET);
                 // Convert $_GET to UTF-8
                 $_GET = Input::clean($_GET);
             }
         }
     } elseif (isset($_GET['kohana_uri'])) {
         // Use the URI defined in the query string
         Router::$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']);
     } else {
         if (isset($_SERVER['PATH_INFO']) and $_SERVER['PATH_INFO']) {
             Router::$current_uri = $_SERVER['PATH_INFO'];
         } elseif (isset($_SERVER['ORIG_PATH_INFO']) and $_SERVER['ORIG_PATH_INFO']) {
             Router::$current_uri = $_SERVER['ORIG_PATH_INFO'];
         } elseif (isset($_SERVER['PHP_SELF']) and $_SERVER['PHP_SELF']) {
             // PATH_INFO is empty during requests to the front controller
             Router::$current_uri = $_SERVER['PHP_SELF'];
         }
         if (isset($_SERVER['SCRIPT_NAME']) and $_SERVER['SCRIPT_NAME']) {
             // Clean up PATH_INFO fallbacks
             // PATH_INFO may be formatted for ISAPI instead of CGI on IIS
             if (strncmp(Router::$current_uri, $_SERVER['SCRIPT_NAME'], strlen($_SERVER['SCRIPT_NAME'])) === 0) {
                 // Remove the front controller from the current uri
                 Router::$current_uri = (string) substr(Router::$current_uri, strlen($_SERVER['SCRIPT_NAME']));
             }
         }
     }
     // Remove slashes from the start and end of the URI
     Router::$current_uri = trim(Router::$current_uri, '/');
     if (Router::$current_uri !== '') {
         if ($suffix = Kohana::config('core.url_suffix') and strpos(Router::$current_uri, $suffix) !== FALSE) {
             // Remove the URL suffix
             Router::$current_uri = preg_replace('#' . preg_quote($suffix) . '$#u', '', Router::$current_uri);
             // Set the URL suffix
             Router::$url_suffix = $suffix;
         }
         // Reduce multiple slashes into single slashes
         Router::$current_uri = preg_replace('#//+#', '/', Router::$current_uri);
     }
 }
Example #4
0
 /**
  * Attempts to determine the current URI using CLI, GET, PATH_INFO, ORIG_PATH_INFO, or PHP_SELF.
  * @return bool
  * @throws Exception_Exido
  */
 public static function getUri()
 {
     // Debug log
     if (Exido::$log_debug) {
         Exido::$log->add('EXIDO_DEBUG_LOG', 'Determine current URI');
     }
     Helper::load('input');
     // Trying to detect the URI
     if (inputServer('PATH_INFO')) {
         self::$current_uri = inputServer('PATH_INFO');
     } elseif (inputServer('ORIG_PATH_INFO')) {
         self::$current_uri = inputServer('ORIG_PATH_INFO');
     } elseif (inputServer('REQUEST_URI')) {
         self::$current_uri = inputServer('REQUEST_URI');
     } else {
         throw new Exception_Exido(__("Can't detect URI"));
     }
     // Remove slashes from the start and end of the URI
     self::$current_uri = trim(self::$current_uri, '/');
     if (self::$current_uri !== '') {
         if ($suffix = Exido::config('global.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;
         }
         // Find index file name
         if ($indexfile = Exido::config('global.core.index_file') and $indexpos = strpos(self::$current_uri, $indexfile) and $indexpos !== false) {
             // Remove the index file name
             self::$current_uri = substr(self::$current_uri, 0, $indexpos);
         }
         // Reduce multiple slashes into single slashes
         self::$current_uri = preg_replace('#//+#', '/', self::$current_uri);
     }
     return true;
 }