Beispiel #1
0
 /**
  * 测试反向解析
  */
 function testReverseParse()
 {
     $context = QContext::instance();
     $router = new QRouter();
     $router->import(Q::ini('routes'));
     foreach ($this->_tests_args as $offset => $test) {
         $copy = $test;
         $path = $test['_path'];
         unset($test['_path']);
         $result = $router->url($test);
         list($route_name) = explode(':', $offset);
         if ($route_name != $router->lastReverseMatchedRouteName()) {
             dump('-----------------------------------');
             dump($path, 'test path');
             dump($test, $result);
             dump($router->lastReverseMatchedRouteName(), 'used route');
             dump($route_name, 'expected route');
             dump($router->get($route_name));
         }
         $this->assertEquals($route_name, $router->lastReverseMatchedRouteName(), "Expected route name is [{$route_name}].");
         $this->assertEquals($path, $result, "{$path} == {$result}\n" . print_r($copy, true) . "\n" . print_r($test, true));
     }
 }
Beispiel #2
0
 /**
  * 根据服务器运行环境,重新初始化 QContext 对象
  *
  * @param boolean $full_init 是否进行完全的初始化
  */
 function reinit($full_init = false)
 {
     if ($full_init) {
         $this->_params = array();
         $this->_router = null;
     }
     self::$_request_uri = null;
     self::$_base_uri = null;
     self::$_base_dir = null;
     self::$_url_mode = null;
     // 如果有必要,初始化路由服务
     $url_mode = strtolower(Q::ini('dispatcher_url_mode'));
     if (is_null($this->_router) && ($url_mode == self::URL_MODE_PATHINFO || $url_mode == self::URL_MODE_REWRITE)) {
         $this->_router = new QRouter();
         $this->_router->import(Q::ini('routes'), 'global_default_routes');
         $result = $this->_router->match('/' . ltrim($this->pathinfo(), '/'));
         if ($result) {
             foreach ($result as $var => $value) {
                 if (strlen($value) === 0) {
                     continue;
                 }
                 if (!isset($_GET[$var]) || strlen($_GET[$var]) === 0) {
                     $_GET[$var] = $_REQUEST[$var] = $value;
                 }
             }
         }
     }
     self::$_url_mode = $url_mode;
     // 从 $_GET 中提取请求参数
     $keys = array_keys($_GET);
     if (!empty($keys)) {
         $keys = array_combine($keys, $keys);
         $keys = array_change_key_case($keys);
     }
     $udi = array();
     $udi[self::UDI_CONTROLLER] = isset($keys[self::UDI_CONTROLLER]) ? $_GET[$keys[self::UDI_CONTROLLER]] : null;
     $udi[self::UDI_ACTION] = isset($keys[self::UDI_ACTION]) ? $_GET[$keys[self::UDI_ACTION]] : null;
     $udi[self::UDI_MODULE] = isset($keys[self::UDI_MODULE]) ? $_GET[$keys[self::UDI_MODULE]] : null;
     $udi[self::UDI_NAMESPACE] = isset($keys[self::UDI_NAMESPACE]) ? $_GET[$keys[self::UDI_NAMESPACE]] : null;
     $this->changeRequestUDI($udi);
 }