/**
  * 在此路由协议的基础上组装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, '/');
 }
 public function build($router, $action, $args = array())
 {
     list($_a, $_c, $_m, $args) = WindUrlHelper::resolveAction($action, $args);
     if ($_m && $_m !== $router->getDefaultModule()) {
         $args[$router->getModuleKey()] = $_m;
     }
     if ($_c && $_c !== $router->getDefaultController()) {
         $args[$router->getControllerKey()] = $_c;
     }
     if ($_a && $_a !== $router->getDefaultAction()) {
         $args[$router->getActionKey()] = $_a;
     }
     $_url = 'index.php?' . WindUrlHelper::argsToUrl($args);
     return $_url;
 }
 /**
  * 重定向请求到新的action操作
  * 
  * 该种重定向类型,是中断当前的请求执行过程,开启另外的action操作处理.是在一次请求内部进行重定向,
  * 所以之前的一些处理的结果变量,在重定向后是会继续存在,并可通过forward变量进行访问的.也就是不仅仅是过程的重定向,
  * 也是状态的重定向.
  * @param WindForward $forward
  * @param WindRouter $router
  * @param boolean $display
  * @return void
  */
 protected function dispatchWithAction($forward, $router, $display)
 {
     if (!($action = $forward->getAction())) {
         throw new WindException('[web.WindDispatcher.dispatchWithAction] forward fail.', WindException::ERROR_PARAMETER_TYPE_ERROR);
     }
     $this->display = $display;
     list($_a, $_c, $_m) = WindUrlHelper::resolveAction($action);
     if ($_var = $forward->getArgs()) {
         $this->getResponse()->setData($_var, 'F');
     }
     $_a && $router->setAction($_a);
     $_c && $router->setController($_c);
     $_m && $router->setModule($_m);
     Wind::getApp()->run();
 }
Example #4
0
 /**
  * 重定向请求到新的action操作
  * 
  * 该种重定向类型,是中断当前的请求执行过程,开启另外的action操作处理.是在一次请求内部进行重定向,
  * 所以之前的一些处理的结果变量,在重定向后是会继续存在,并可通过forward变量进行访问的.也就是不仅仅是过程的重定向,
  * 也是状态的重定向.
  * @param WindForward $forward
  * @param WindRouter $router
  * @param boolean $display
  * @return void
  */
 protected function dispatchWithAction($forward, $router, $display)
 {
     if (!($action = $forward->getAction())) {
         throw new WindException('[web.WindDispatcher.dispatchWithAction] forward fail.', WindException::ERROR_PARAMETER_TYPE_ERROR);
     }
     $this->display = $display;
     list($_a, $_c, $_m, $arg) = WindUrlHelper::resolveAction($action);
     foreach ($arg as $key => $value) {
         $_GET[$key] = $value;
     }
     foreach ($forward->getArgs() as $key => $value) {
         $_POST[$key] = $value;
     }
     $_a && $router->setAction($_a);
     $_c && $router->setController($_c);
     $_m && $router->setModule($_m);
     Wind::getApp()->run();
 }
Example #5
0
 public function assemble($action, $args = array(), $route = null)
 {
     $route || ($route = $this->defaultRoute);
     if ($route && null !== ($route = $this->getRoute($route))) {
         $_url = $route->build($this, $action, $args);
     } else {
         list($_a, $_c, $_m, $args) = WindUrlHelper::resolveAction($action, $args);
         if ($_m && $_m !== $this->_module) {
             $args[$this->moduleKey] = $_m;
         }
         if ($_c && $_c !== $this->_controller) {
             $args[$this->controllerKey] = $_c;
         }
         if ($_a && $_a !== $this->_action) {
             $args[$this->actionKey] = $_a;
         }
         $_url = $this->request->getScript() . '?' . WindUrlHelper::argsToUrl($args);
     }
     return $_url;
 }
Example #6
0
 /**
  * 在此路由协议的基础上组装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);
     foreach ($this->params as $key => $val) {
         if ($key === $router->getModuleKey()) {
             $_m || ($_m = $router->getModule());
             $_args[$val] = $_m;
         } elseif ($key === $router->getControllerKey()) {
             $_c || ($_c = $router->getController());
             $_args[$val] = $_c;
         } elseif ($key === $router->getActionKey()) {
             $_a || ($_a = $router->getAction());
             $_args[$val] = $_a;
         }
         unset($args[$key]);
     }
     $_args[0] = $this->reverse;
     ksort($_args);
     $url = call_user_func_array("sprintf", $_args);
     $args && ($url .= '/' . WindUrlHelper::argsToUrl($args, true, $this->separator));
     return trim($url, '/');
 }
Example #7
0
 /**
  * 解析url串
  *
  * @param WindHttpRequest $request        	
  * @param string $path        	
  * @return array
  */
 private function _matchPath($path, $rawDecode = false)
 {
     $path = trim($path, '/');
     if (empty($path)) {
         return array();
     }
     if ($this->rewrite_special) {
         /* 解析特殊伪静态 */
         $rule = $this->_getRule();
         if (!empty($rule)) {
             if (false !== strpos($path, '?')) {
                 list($rewritePath, $queryPath) = explode('?', $path . '?', 2);
             } else {
                 list($rewritePath, $queryPath) = explode('&', $path . '&', 2);
             }
             foreach ($rule as $k => $v) {
                 if ($k == 'default') {
                     continue;
                 }
                 $rewritePath = rawurldecode($rewritePath);
                 if (preg_match($v['pattern'], $rewritePath, $matches)) {
                     $matches = array_diff_key($matches, range(0, intval(count($matches) / 2)));
                     $args = WindUrlHelper::urlToArgs(trim($queryPath, '?'), true);
                     if ($k == 'thread' || $k == 'cate') {
                         if (!isset($matches['fid']) && isset($matches['fname'])) {
                             $domain = $this->_getDomain('domain', 'domain_key');
                             if (isset($domain[$matches['fname']])) {
                                 list($_a, $_c, $_m, $_args) = WindUrlHelper::resolveAction($domain[$matches['fname']]);
                                 return array_merge($matches, array('m' => $_m, 'c' => $_c, 'a' => $_a), $_args + $args);
                             }
                         } elseif (isset($matches['fid'])) {
                             $forum = Wekit::load('forum.PwForum')->getForum($matches['fid']);
                             $action = array('category' => array('m' => 'bbs', 'c' => 'cate', 'a' => 'run'), 'forum' => array('m' => 'bbs', 'c' => 'thread', 'a' => 'run'), 'sub' => array('m' => 'bbs', 'c' => 'thread', 'a' => 'run'), 'sub2' => array('m' => 'bbs', 'c' => 'thread', 'a' => 'run'));
                             $forum_type = isset($forum['type']) ? $forum['type'] : 'forum';
                             return array_merge($matches, $action[$forum_type], $args);
                         }
                     }
                     $route = explode('/', $v['route']);
                     return array_merge($matches, array('m' => $route[0], 'c' => $route[1], 'a' => $route[2]), $args);
                 }
             }
         }
     }
     /* 解析普通伪静态 */
     if ($this->rewrite_common && strpos($path, '.php') === false) {
         return $this->_matchCommon($path);
     }
     $r = false !== strpos($path, '?') ? WindUrlHelper::urlToArgs($path) : array();
     if ($rawDecode) {
         return $r;
     }
     $return = array();
     if (isset($r['m']) || isset($r['c']) || isset($r['a'])) {
         $return['m'] = isset($r['m']) ? $r['m'] : $this->default_m;
         $return['c'] = isset($r['c']) ? $r['c'] : 'index';
         $return['a'] = isset($r['a']) ? $r['a'] : 'run';
     }
     return $return;
 }
Example #8
0
 /**
  * 更新某个首字母的缓存
  *
  * @param char $first
  */
 public function flushDomain()
 {
     $domain = $app = array();
     $forum_isopen = Wekit::C('domain', "forum.isopen");
     $result = $this->_domainDs()->getAll();
     foreach ($result as $v) {
         if ($v['domain_type'] == 'forum' && !$forum_isopen) {
             continue;
         }
         $k = 'http://' . $v['domain'] . '.' . $v['root'];
         $domain[$k] = $v['domain_key'];
         if ($v['domain_type'] == 'app') {
             list(, , $m) = WindUrlHelper::resolveAction($v['domain_key']);
             $app[$m] = $k;
         }
     }
     Wekit::load('config.PwConfig')->setConfig('site', 'domain', $domain);
     Wekit::load('config.PwConfig')->setConfig('site', 'domain.app', $app);
 }
 /**
  * Tests WindUrlHelper::resolveAction()
  */
 public function testResolveAction()
 {
     $this->assertEquals(array('action', 'controller', 'module', 'app', array('c' => 'c', 'b' => 'b')), WindUrlHelper::resolveAction("app/module/controller/action?b=b", array('c' => 'c')));
 }