static function route() { if (!empty(APP::$config['rewrite'])) { if (($pos = strpos($_SERVER['REQUEST_URI'], '?')) !== false) { parse_str(substr($_SERVER['REQUEST_URI'], $pos + 1), $_GET); } foreach (APP::$config['rewrite'] as $rule => $mapper) { if ('/' == $rule) { $rule = ''; } if (0 !== stripos($rule, 'http://')) { $rule = 'http://' . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER["SCRIPT_NAME"]), '/\\') . '/' . $rule; } $rule = '/' . str_ireplace(array('\\\\', 'http://', '/', '<', '>', '.'), array('', '', '\\/', '(?<', '>\\w+)', '\\.'), $rule) . '/i'; if (preg_match($rule, 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], $matchs)) { $route = explode("/", $mapper); if (isset($route[2])) { list($_GET['m'], $_GET['c'], $_GET['a']) = $route; } else { list($_GET['c'], $_GET['a']) = $route; } foreach ($matchs as $matchkey => $matchval) { if (!is_int($matchkey)) { $_GET[$matchkey] = $matchval; } } break; } } $parameter = str_replace($matchs[0], "", rtrim($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], APP::$config['url']['suffix'])); $parames = explode('/', $parameter); if ($_GET['c'] == APP::$config['api']['file'] && isset($parames[1])) { $_GET['id'] = $parames[1]; } else { for ($i = 1; $i < count($parames); $i = $i + 2) { if (!empty($parames[$i])) { $_GET[$parames[$i]] = $parames[$i + 1]; } } } } if ($_GET['c'] == APP::$config['api']['file']) { $class = $_GET['a'] . 'Rest'; $action = strtolower($_SERVER['REQUEST_METHOD']) . 'Action'; APP::$__api = $_GET['c']; APP::$__action = $_GET['a']; } else { APP::$__module = $_GET['m']; APP::$__controller = $_GET['c']; APP::$__action = $_GET['a']; $class = $_GET['c'] . 'Controller'; $action = $_GET['a'] . 'Action'; } $obj = new $class(); $obj->{$action}(); }