private static function _VLoadHostRules($sHost, &$sUri) { $srcUri = $sUri; $confFile = Ko_Web_Config::SGetValue('rewriteconf', $sHost, $sUri); if (is_file($confFile)) { $cacheFile = Ko_Web_Config::SGetValue('rewritecache', $sHost, $srcUri); if ('' === $cacheFile) { self::$s_aRules = Ko_Web_RewriteParser::AProcess(file_get_contents($confFile)); } else { $cacheDir = dirname($cacheFile); if (!is_dir($cacheDir)) { mkdir($cacheDir, 0777, true); if (!is_dir($cacheDir)) { self::$s_aRules = Ko_Web_RewriteParser::AProcess(file_get_contents($confFile)); return; } } if (!is_file($cacheFile) || filemtime($confFile) > filemtime($cacheFile)) { self::$s_aRules = Ko_Web_RewriteParser::AProcess(file_get_contents($confFile)); $script = "<?php\nKo_Web_Rewrite::VLoadRules(" . var_export(self::$s_aRules, true) . ");\n"; file_put_contents($cacheFile, $script); } else { require_once $cacheFile; } } } }
private static function _VLoadHostRules($sHost) { $confFile = Ko_Web_Config::SGetRewriteConf($sHost); if (is_file($confFile)) { $cacheFile = Ko_Web_Config::SGetRewriteCache($sHost); if ('' === $cacheFile) { self::$s_aRules = Ko_Web_RewriteParser::AProcess(file_get_contents($confFile)); } else { $cacheDir = dirname($cacheFile); if (!is_dir($cacheDir)) { mkdir($cacheDir, 0777, true); if (!is_dir($cacheDir)) { self::$s_aRules = Ko_Web_RewriteParser::AProcess(file_get_contents($confFile)); return; } } if (!is_file($cacheFile) || filemtime($confFile) > filemtime($cacheFile)) { self::$s_aRules = Ko_Web_RewriteParser::AProcess(file_get_contents($confFile)); $script = "<?php\nKo_Web_Rewrite::VLoadRules(" . Ko_Tool_Stringify::SConvArray(self::$s_aRules) . ");\n"; file_put_contents($cacheFile, $script); } else { require_once $cacheFile; } } } }
private static function _IDispatch($scriptFilename, $requestMethod, &$phpFilename) { self::$s_sFile = $scriptFilename; self::$s_sFunc = ''; self::$s_sMethod = $requestMethod; $phpFilename = ''; if ('.php' === substr(self::$s_sFile, -4)) { if (!is_file(self::$s_sFile)) { return self::$s_iErrno = self::ERR_FILE; } $phpFilename = self::$s_sFile; } else { $pathinfo = pathinfo(self::$s_sFile); if (is_file(self::$s_sFile)) { $render = new Ko_View_Render_FILE(); $render->oSetData('filename', self::$s_sFile); Ko_Web_Response::VSetContentType($pathinfo['extension']); Ko_Web_Response::VAppendBody($render); Ko_Web_Response::VSend(); } else { if (is_dir(self::$s_sFile)) { list($rewrite, $httpcode) = Ko_Web_Rewrite::AGet(); list($path, $query) = explode('?', $rewrite, 2); if (isset($query)) { $query = '?' . $query; } Ko_Web_Response::VSetRedirect($path . '/' . $query); Ko_Web_Response::VSend(); } else { self::$s_sFunc = $pathinfo['basename']; self::$s_sFile = $pathinfo['dirname'] . '.php'; if (!is_file(self::$s_sFile)) { return self::$s_iErrno = self::ERR_FILE; } self::_VRequireFile(self::$s_sFile); if (!isset(self::$s_aRoute[self::$s_sFunc])) { return self::$s_iErrno = self::ERR_FUNC; } if (!isset(self::$s_aRoute[self::$s_sFunc][self::$s_sMethod])) { return self::$s_iErrno = self::ERR_METHOD; } call_user_func(self::$s_aRoute[self::$s_sFunc][self::$s_sMethod]); } } } return self::$s_iErrno = 0; }
private static function _IDispatch($scriptFilename, $requestMethod, &$phpFilename) { self::$s_sFile = $scriptFilename; self::$s_sFunc = ''; self::$s_sMethod = $requestMethod; $phpFilename = ''; if ('.php' === substr(self::$s_sFile, -4)) { if (!is_file(self::$s_sFile)) { return self::$s_iErrno = self::ERR_FILE; } $phpFilename = self::$s_sFile; } else { if (is_file(self::$s_sFile)) { $render = new Ko_View_Render_FILE(); $render->oSetData('filename', self::$s_sFile); Ko_Web_Response::VSend($render); } else { if (is_dir(self::$s_sFile)) { list($rewrite, $httpcode) = Ko_Web_Rewrite::AGet(); list($path, $query) = explode('?', $rewrite, 2); if (isset($query)) { $query = '?' . $query; } Ko_Web_Response::VSetRedirect($path . '/' . $query); Ko_Web_Response::VSend(); } else { $pathinfo = pathinfo(self::$s_sFile); self::$s_sFunc = $pathinfo['basename']; self::$s_sFile = $pathinfo['dirname'] . '.php'; if (self::_IWebRoute()) { self::$s_sFile = $pathinfo['dirname'] . '/index.php'; return self::_IWebRoute(); } } } } return self::$s_iErrno = 0; }
<?php /** * Bootstrap * * @package ko/Web * @author zhangchu */ if (!defined('KO_WEB_BOOTSTRAP')) { define('KO_WEB_BOOTSTRAP', 1); Ko_Tool_Xhprof::VStart(); Ko_Web_Event::Trigger('ko.bootstrap', 'before'); Ko_Web_Config::VLoad(); Ko_Web_Event::Trigger('ko.config', 'after'); Ko_Web_Error::VHandle(); Ko_Web_Rewrite::VHandle(); Ko_Web_Event::Trigger('ko.dispatch', 'before'); if (Ko_Web_Route::IDispatch($phpFilename)) { Ko_Web_Event::Trigger('ko.dispatch', '404'); } else { if ('' !== $phpFilename) { $cwd = getcwd(); chdir(dirname($phpFilename)); require_once $phpFilename; chdir($cwd); } } }
<?php Ko_Web_Rewrite::VLoadRules(array('rest' => array('(.*)' => array('*' => '/rest.php?uri=$1'))));