Ejemplo n.º 1
0
 /**
  * Matches a user submitted path with a previously defined route.
  * Assigns and returns an array of defaults on a successful match.
  *
  * @param  string $path Path used to match against this routing map
  * @return array|false  An array of assigned values or a false on a mismatch
  */
 public function route(\Yaf\Request_Abstract $request)
 {
     $requestUri = $request->getRequestUri();
     $baseuri = $request->getBaseUri();
     if ($requestUri != '' && $baseuri != '' && stripos($requestUri, $baseuri) !== false) {
         $path = substr($requestUri, strlen($baseuri));
     } else {
         $path = $requestUri;
     }
     $path = urldecode($path);
     $res = preg_match($this->_route, $path, $values);
     if ($res === 0) {
         return false;
     }
     $values = $this->_getMappedValues($values);
     if (isset($this->_default['module'])) {
         $request->setModuleName($this->_default['module']);
     }
     if (isset($this->_default['controller'])) {
         $request->setControllerName($this->_default['controller']);
     }
     if (isset($this->_default['action'])) {
         $request->setActionName($this->_default['action']);
     }
     $request->setParam($values);
     return true;
 }
Ejemplo n.º 2
0
 /**
  * Matches a user submitted path with a previously defined route.
  * Assigns and returns an array of defaults on a successful match.
  *
  * @param  string $path Path used to match against this routing map
  *
  * @return array|false  An array of assigned values or a false on a mismatch
  */
 public function route(\Yaf\Request_Abstract $request)
 {
     $requestUri = $request->getRequestUri();
     $baseuri = $request->getBaseUri();
     if ($requestUri != '' && $baseuri != '' && stripos($requestUri, $baseuri) !== false) {
         $path = substr($requestUri, strlen($baseuri));
     } else {
         $path = $requestUri;
     }
     $path = trim(urldecode($path), \Yaf\Router::URI_DELIMITER);
     $values = $this->_match($path);
     if ($values == null) {
         return false;
     }
     if (isset($this->_default['module'])) {
         $request->setModuleName($this->_default['module']);
     }
     if (isset($this->_default['controller'])) {
         $request->setControllerName($this->_default['controller']);
     }
     if (isset($this->_default['action'])) {
         $request->setActionName($this->_default['action']);
     }
     $request->setParam($values);
     return true;
 }
Ejemplo n.º 3
0
 /**
  *  检查用户权限
  * @param  Request_Abstract
  * @param  Response_Abstract
  * @return [type]
  */
 public function checkMemberPermission(Request_Abstract $request, Response_Abstract $response)
 {
     $config = Application::app()->getConfig()->get("roles")->toArray();
     // 是否开启权限检查
     if ($config and $config['permission'] == false) {
         return;
     }
     $rest = RegisterRest::initRegister();
     // 获取当前路由
     $this->current_key = $this->getSystemAction($request->getControllerName(), $request->getActionName(), $rest);
     // 如果路由不存在,跳转到默认路由位置。
     // 必须在 RegisterRest 注册 route 才能获取访问权限
     if (!$this->current_key) {
         $request->setControllerName('Index');
         $request->setActionName('index');
         return;
     }
     $check = explode(',', $config['check']);
     $member = explode(',', $config['member']);
     if ($this->current_key) {
         $members = MembersManage::instance();
         $user = $members->getCurrentSession();
         $controlName = explode('_', $this->current_key);
         $userpermission = isset($user['permission']) ? explode(',', $user['permission']) : array();
         // 如果是超级管理员,不检查权限。
         if ($user && $user['role_id'] == 1) {
             return;
         }
         if ($user) {
             // 检查普通用户的权限
             if ($user and $user['role_id'] > 1 and !in_array($this->current_key, $userpermission)) {
                 $request->setControllerName('Index');
                 $request->setActionName('index');
             }
         } else {
             //获取匿名用户禁止路由权限
             if (in_array($controlName[0], $check)) {
                 $request->setControllerName('Index');
                 $request->setActionName('index');
             }
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * <p><b>\Yaf\Route_Interface::route()</b> is the only method that a custom route should implement.</p><br/>
  * <p>if this method return TRUE, then the route process will be end. otherwise,\Yaf\Router will call next route in the route stack to route request.</p><br/>
  * <p>This method would set the route result to the parameter request, by calling \Yaf\Request_Abstract::setControllerName(), \Yaf\Request_Abstract::setActionName() and \Yaf\Request_Abstract::setModuleName().</p><br/>
  * <p>This method should also call \Yaf\Request_Abstract::setRouted() to make the request routed at last.</p>
  *
  * @link http://www.php.net/manual/en/yaf-route-interface.route.php
  *
  * @param \Yaf\Request_Abstract $request
  * @desc 默认module和controller均写死为Index了
  * @return bool
  */
 public function route($request)
 {
     $uris = explode('/', str_replace('-', '', $request->getRequestUri()));
     $request->setModuleName('Index');
     if (!empty($uris[1])) {
         $request->setControllerName($uris[1]);
     } else {
         $request->setControllerName('Index');
     }
     $params = array();
     $param_pairs = array_chunk(array_slice($uris, 2), 2);
     foreach ($param_pairs as $param) {
         $params[$param[0]] = empty($param[1]) ? '' : $param[1];
     }
     $request->setParam($params);
     $request->setParam($_REQUEST);
     $request->setActionName(strtolower($request->getMethod()));
     $method = $request->getParam('_method');
     if (!empty($method)) {
         $request->setActionName(strtolower($method));
     }
     //如果不return true 会继续执行static 路由规则
     return true;
 }
Ejemplo n.º 5
0
 /**
  * Processes a request and sets its controller and action.  If
  * no route was possible, default route is set.
  *
  * @param  Yaf_Request_Abstract
  *
  * @return Yaf_Request_Abstract|boolean
  */
 public function route(\Yaf\Request_Abstract $request)
 {
     $requestUri = $request->getRequestUri();
     $baseuri = $request->getBaseUri();
     if ($requestUri != '' && $baseuri != '' && stripos($requestUri, $baseuri) === 0) {
         $path = substr($requestUri, strlen($baseuri));
     } else {
         $path = $requestUri;
     }
     $path = trim(urldecode($path), \Yaf\Router::URI_DELIMITER);
     $rest = '';
     if (is_string($this->_delimiter) && $this->_delimiter != '') {
         if (($queryStringPos = strpos($path, $this->_delimiter)) !== false) {
             $rest = substr($path, $queryStringPos + strlen($this->_delimiter), strlen($path) - 1);
             $path = substr($path, 0, $queryStringPos);
         }
     }
     $route = '';
     if ($path != '' && $path != '/') {
         $route = str_replace(\Yaf\Router::URI_DELIMITER, '_', trim($path, \Yaf\Router::URI_DELIMITER));
     }
     if ($route != '') {
         if ($this->_ctlPrefer == true) {
             $request->setControllerName($route);
         } else {
             $request->setActionName($route);
         }
     }
     $params = array();
     if ($rest != null && trim($rest) != '') {
         $path = explode(\Yaf\Router::URI_DELIMITER, trim($rest, \Yaf\Router::URI_DELIMITER));
         if (($numSegs = count($path)) != 0) {
             for ($i = 0; $i < $numSegs; $i = $i + 2) {
                 $key = urldecode($path[$i]);
                 $val = isset($path[$i + 1]) ? urldecode($path[$i + 1]) : null;
                 $params[$key] = isset($params[$key]) ? array_merge((array) $params[$key], array($val)) : $val;
             }
         }
         $request->setParam($params);
     }
     return true;
 }
Ejemplo n.º 6
0
 /**
  * Processes a request and sets its controller and action.  If
  * no route was possible, default route is set.
  *
  * @param  Yaf_Request_Abstract
  *
  * @return Yaf_Request_Abstract|boolean
  */
 public function route(\Yaf\Request_Abstract $request)
 {
     $module = isset($_GET[$this->_module]) ? $_GET[$this->_module] : null;
     $controller = isset($_GET[$this->_controller]) ? $_GET[$this->_controller] : null;
     $action = isset($_GET[$this->_action]) ? $_GET[$this->_action] : null;
     if ($module == null && $controller == null && $action == null) {
         return false;
     } else {
         if ($module != null) {
             $request->setModuleName($module);
         }
         if ($controller != null) {
             $request->setControllerName($controller);
         }
         if ($action != null) {
             $request->setActionName($action);
         }
     }
     return true;
 }
Ejemplo n.º 7
0
 /**
  * 路由调度
  * @param \Yaf\Request_Abstract $request http请求对象
  * @return boolean TRUE表示和其他路由协议共存
  */
 public function route($request)
 {
     // 解析url信息
     $uri = $request->getRequestUri();
     $uri = explode('/', trim($request->getRequestUri(), '/'));
     $module = strtolower($uri[0]);
     // 分析url信息
     if (in_array($module, $this->modules)) {
         $this->route['module'] = $module;
         array_splice($uri, 0, 1);
     }
     if (isset($uri[0])) {
         $this->route['controller'] = $uri[0];
     }
     if (isset($uri[1])) {
         $this->route['action'] = $uri[1];
     }
     // 修改调度信息
     $request->setModuleName($this->route['module']);
     $request->setControllerName($this->route['controller']);
     $request->setActionName($this->route['action']);
     return TRUE;
 }
Ejemplo n.º 8
0
 /**
  * Processes a request and sets its controller and action based on a
  * supervar value.
  *
  * @param  Yaf_Request_Abstract
  * @return Yaf_Request_Abstract|boolean
  */
 public function route(\Yaf\Request_Abstract $request)
 {
     $requestUri = $request->getQuery($this->_varName);
     if ($requestUri == null || $requestUri == '') {
         return false;
     }
     $module = null;
     $controller = null;
     $action = null;
     $rest = null;
     $path = trim($requestUri, \Yaf\Router::URI_DELIMITER);
     if ($path != '' && $path != '/') {
         $path = explode(\Yaf\Router::URI_DELIMITER, $path);
         if (\Yaf\Application::isModuleName($path[0])) {
             $module = $path[0];
             array_shift($path);
         }
         if (count($path) && !empty($path[0])) {
             $controller = $path[0];
             array_shift($path);
         }
         if (count($path) && !empty($path[0])) {
             $action = $path[0];
             array_shift($path);
         }
         $rest = implode(\Yaf\Router::URI_DELIMITER, $path);
         $actionPrefer = \Yaf\G::iniGet('yaf.action_prefer');
         if ($module == null && $controller == null && $action == null) {
             if ($actionPrefer == true) {
                 $action = $rest;
             } else {
                 $controller = $rest;
             }
             $rest = null;
         } elseif ($module == null && $action == null && $rest == null) {
             if ($actionPrefer == true) {
                 $action = $controller;
                 $controller = null;
             }
         } elseif ($controller == null && $action == null && $rest != null) {
             $controller = $module;
             $action = $rest;
             $module = null;
             $rest = null;
         } elseif ($action == null && $rest == null) {
             $action = $controller;
             $controller = $module;
             $module = null;
         } elseif ($controller == null && $action == null) {
             $controller = $module;
             $action = $rest;
             $module = null;
             $rest = null;
         } elseif ($action == null) {
             $action = $rest;
             $rest = null;
         }
         if ($module != null) {
             $request->setModuleName($module);
         }
         if ($controller != null) {
             $request->setControllerName($controller);
         }
         if ($action != null) {
             $request->setActionName($action);
         }
         $params = array();
         if ($rest != null && trim($rest) != '') {
             $path = explode(\Yaf\Router::URI_DELIMITER, $rest);
             if (($numSegs = count($path)) != 0) {
                 for ($i = 0; $i < $numSegs; $i = $i + 2) {
                     $key = urldecode($path[$i]);
                     $val = isset($path[$i + 1]) ? urldecode($path[$i + 1]) : null;
                     $params[$key] = isset($params[$key]) ? array_merge((array) $params[$key], array($val)) : $val;
                 }
             }
             $request->setParam($params);
         }
     }
     return true;
 }