function swoole_urlrouter_mvc(&$uri) { $array = array('controller' => 'page', 'view' => 'index'); if (!empty($_GET["c"])) { $array['controller'] = $_GET["c"]; } if (!empty($_GET["v"])) { $array['view'] = $_GET["v"]; } if (empty($uri) or substr($uri, -8) == 'index.php') { return $array; } $request = explode('/', $uri, 3); if (count($request) < 2) { return $array; } $array['controller'] = $request[0]; $array['view'] = $request[1]; if (isset($request[2])) { $request[2] = trim($request[2], '/'); $_id = str_replace('.html', '', $request[2]); if (is_numeric($_id)) { $_GET['id'] = $_id; } else { Swoole\Tool::$url_key_join = '-'; Swoole\Tool::$url_param_join = '-'; Swoole\Tool::$url_add_end = '.html'; Swoole\Tool::$url_prefix = WEBROOT . "/{$request[0]}/{$request['1']}/"; Swoole\Tool::url_parse_into($request[2], $_GET); } } return $array; }
function swoole_urlrouter_mvc(&$uri) { $array = Swoole::$default_controller; if (!empty($_GET["c"])) { $array['controller'] = $_GET["c"]; } if (!empty($_GET["v"])) { $array['view'] = $_GET["v"]; } $request = explode('/', $uri, 3); if (count($request) < 2) { return $array; } $array['controller'] = $request[0]; $array['view'] = $request[1]; if (isset($request[2])) { $request[2] = trim($request[2], '/'); $_id = str_replace('.html', '', $request[2]); if (is_numeric($_id)) { $_GET['id'] = $_id; } else { Swoole\Tool::$url_key_join = '-'; Swoole\Tool::$url_param_join = '-'; Swoole\Tool::$url_add_end = '.html'; Swoole\Tool::$url_prefix = WEBROOT . "/{$request[0]}/{$request['1']}/"; Swoole\Tool::url_parse_into($request[2], $_GET); } $_REQUEST = array_merge($_REQUEST, $_GET); } return $array; }
function url_process_default() { $array = array('controller' => 'page', 'view' => 'index'); if (!empty($_GET["c"])) { $array['controller'] = $_GET["c"]; } if (!empty($_GET["v"])) { $array['view'] = $_GET["v"]; } $uri = parse_url($_SERVER['REQUEST_URI']); if (empty($uri['path']) or $uri['path'] == '/' or $uri['path'] == '/index.php') { return $array; } $request = explode('/', trim($uri['path'], '/'), 3); if (count($request) < 2) { return $array; } $array['controller'] = $request[0]; $array['view'] = $request[1]; if (is_numeric($request[2])) { $_GET['id'] = $request[2]; } else { Swoole\Tool::$url_key_join = '-'; Swoole\Tool::$url_param_join = '-'; Swoole\Tool::$url_add_end = '.html'; Swoole\Tool::$url_prefix = "/{$request[0]}/{$request['1']}/"; Swoole\Tool::url_parse_into($request[2], $_GET); } return $array; }
private function __construct() { if (!defined('DEBUG')) { define('DEBUG', 'off'); } if (DEBUG == 'off') { \error_reporting(0); } #初始化App环境 //为了兼容老的APPSPATH预定义常量方式 if (defined('APPSPATH')) { self::$app_root = str_replace(WEBPATH, '', APPSPATH); } elseif (empty(self::$app_root)) { self::$app_root = "/apps"; } self::$app_path = WEBPATH . self::$app_root; $this->env['app_root'] = self::$app_root; // $this->__init(); $this->load = new Swoole\Loader($this); $this->model = new Swoole\ModelLoader($this); $this->plugin = new Swoole\PluginLoader($this); //路由钩子,URLRewrite $this->addHook(Swoole::HOOK_ROUTE, function (&$uri) { $rewrite = Swoole::$php->config['rewrite']; if (empty($rewrite) or !is_array($rewrite)) { return false; } $match = array(); foreach ($rewrite as $rule) { if (preg_match('#' . $rule['regx'] . '#', $uri['path'], $match)) { //合并到GET中 if (isset($rule['get'])) { $p = explode(',', $rule['get']); foreach ($p as $k => $v) { $_GET[$v] = $match[$k + 1]; } } return $rule['mvc']; } } return false; }); //mvc $this->addHook(Swoole::HOOK_ROUTE, function (&$uri) { $array = array('controller' => 'page', 'view' => 'index'); if (!empty($_GET["c"])) { $array['controller'] = $_GET["c"]; } if (!empty($_GET["v"])) { $array['view'] = $_GET["v"]; } if (empty($uri['path']) or $uri['path'] == '/' or $uri['path'] == '/index.php') { return $array; } $request = explode('/', trim($uri['path'], '/'), 3); if (count($request) < 2) { return $array; } $array['controller'] = $request[0]; $array['view'] = $request[1]; if (isset($request[2])) { $request[2] = trim($request[2], '/'); if (is_numeric($request[2])) { $_GET['id'] = $request[2]; } else { Swoole\Tool::$url_key_join = '-'; Swoole\Tool::$url_param_join = '-'; Swoole\Tool::$url_add_end = '.html'; Swoole\Tool::$url_prefix = WEBROOT . "/{$request[0]}/{$request['1']}/"; Swoole\Tool::url_parse_into($request[2], $_GET); } } return $array; }); }