Beispiel #1
0
 /**
  * 分析参数
  *
  * @param AbstractWindRouter $router
  * @param string $action
  * @param array $args
  * @return array 
  */
 private function _resolveMca($router, $action, $args)
 {
     list($action, $_args) = explode('?', $action . '?');
     $args = array_merge($args, $_args ? WindUrlHelper::urlToArgs($_args, false) : array());
     $action = trim($action, '/');
     $tmp = explode('/', $action . '/');
     end($tmp);
     if (5 === count($tmp) && !strncasecmp('app/', $action, 4)) {
         list($_a, $_c, $_app_name, $_m) = array(prev($tmp), prev($tmp), prev($tmp), prev($tmp));
         $args['app'] = $_app_name;
     } else {
         list($_a, $_c, $_m) = array(prev($tmp), prev($tmp), prev($tmp));
     }
     $_m = $_m ? $_m : $router->getDefaultModule();
     $_c = $_c ? $_c : $router->getDefaultController();
     $_a = $_a ? $_a : $router->getDefaultAction();
     return array($_m, $_c, $_a, $args);
 }
 /**
  * 在此路由协议的基础上组装url
  *
  * @param AbstractWindRouter $router
  * @param string $action 格式为app/module/controller/action
  * @param array $args 附带的参数
  * @return string
  * @see AbstractWindRoute::build()
  */
 public function build($router, $action, $args = array())
 {
     list($_a, $_c, $_m, $_p, $args) = WindUrlHelper::resolveAction($action, $args);
     $flag = 0;
     foreach ($this->params as $key => $val) {
         if (!isset($val['map'])) {
             continue;
         }
         if ($key === $router->getModuleKey()) {
             $m = $_m ? $_m : $router->getModule();
             if ($m === $router->getDefaultModule() && $flag & 2) {
                 $flag = 7;
             } else {
                 $_args[$val['map']] = $m;
             }
         } elseif ($key === $router->getControllerKey()) {
             $c = $_c ? $_c : $router->getController();
             if ($c === $router->getDefaultController() && $flag & 1) {
                 $flag = 3;
             } else {
                 $_args[$val['map']] = $c;
             }
         } elseif ($key === $router->getActionKey()) {
             $a = $_a ? $_a : $router->getAction();
             if ($a === $router->getDefaultAction()) {
                 $flag = 1;
             } else {
                 $_args[$val['map']] = $a;
             }
         } else {
             if (isset($args[$key])) {
                 $_args[$val['map']] = $args[$key];
             } elseif (isset($val['value'])) {
                 $_args[$val['map']] = $val['value'];
             } else {
                 $_args[$val['map']] = '';
             }
         }
         unset($args[$key]);
     }
     $mulitipyTime = count($_args);
     $_args[0] = str_repeat($this->reverse, $mulitipyTime);
     ksort($_args);
     $url = call_user_func_array("sprintf", $_args);
     $args && ($url .= '?' . WindUrlHelper::argsToUrl($args, true, $this->separator));
     $baseUrl = Wind::getApp()->getRequest()->getBaseUrl(true);
     $_baseUrl = $_p ? $this->replaceStr($baseUrl, $_p) : $baseUrl;
     return trim($_baseUrl, '/') . '/' . trim($url, '/');
 }